~ubuntu-branches/ubuntu/utopic/strongswan/utopic

« back to all changes in this revision

Viewing changes to src/libcharon/plugins/dhcp/dhcp_socket.c

  • Committer: Package Import Robot
  • Author(s): Jonathan Davies
  • Date: 2014-01-20 19:00:59 UTC
  • mfrom: (1.2.6)
  • Revision ID: package-import@ubuntu.com-20140120190059-z8e4dl3g8cd09yi5
Tags: 5.1.2~dr3+git20130120-0ubuntu1
* Upstream Git snapshot for build fixes with regards to entropy.
* debian/rules:
  - Enforcing DEB_BUILD_OPTIONS=nostrip for library integrity checking.
  - Set TESTS_REDUCED_KEYLENGTHS to one generate smallest key-lengths in
    tests.

Show diffs side-by-side

added added

removed removed

Lines of Context:
643
643
}
644
644
 
645
645
/**
 
646
 * Bind a socket to a particular interface name
 
647
 */
 
648
static bool bind_to_device(int fd, char *iface)
 
649
{
 
650
        struct ifreq ifreq;
 
651
 
 
652
        if (strlen(iface) > sizeof(ifreq.ifr_name))
 
653
        {
 
654
                DBG1(DBG_CFG, "name for DHCP interface too long: '%s'", iface);
 
655
                return FALSE;
 
656
        }
 
657
        memcpy(ifreq.ifr_name, iface, sizeof(ifreq.ifr_name));
 
658
        if (setsockopt(fd, SOL_SOCKET, SO_BINDTODEVICE, &ifreq, sizeof(ifreq)))
 
659
        {
 
660
                DBG1(DBG_CFG, "binding DHCP socket to '%s' failed: %s",
 
661
                         iface, strerror(errno));
 
662
                return FALSE;
 
663
        }
 
664
        return TRUE;
 
665
}
 
666
 
 
667
/**
646
668
 * See header
647
669
 */
648
670
dhcp_socket_t *dhcp_socket_create()
655
677
                        .s_addr = INADDR_ANY,
656
678
                },
657
679
        };
 
680
        char *iface;
658
681
        int on = 1;
659
682
        struct sock_filter dhcp_filter_code[] = {
660
683
                BPF_STMT(BPF_LD+BPF_B+BPF_ABS,
718
741
        this->dst = host_create_from_string(lib->settings->get_str(lib->settings,
719
742
                                                                "%s.plugins.dhcp.server", "255.255.255.255",
720
743
                                                                charon->name), DHCP_SERVER_PORT);
 
744
        iface = lib->settings->get_str(lib->settings, "%s.plugins.dhcp.interface",
 
745
                        NULL, charon->name);
721
746
        if (!this->dst)
722
747
        {
723
748
                DBG1(DBG_CFG, "configured DHCP server address invalid");
766
791
                destroy(this);
767
792
                return NULL;
768
793
        }
 
794
        if (iface)
 
795
        {
 
796
                if (!bind_to_device(this->send, iface) ||
 
797
                        !bind_to_device(this->receive, iface))
 
798
                {
 
799
                        destroy(this);
 
800
                        return NULL;
 
801
                }
 
802
        }
769
803
 
770
804
        lib->watcher->add(lib->watcher, this->receive, WATCHER_READ,
771
805
                                          (watcher_cb_t)receive_dhcp, this);