Exemple #1
0
static void
discovery_local_port_cb(const struct ofp_port *port, void *d_)
{
    struct discovery *d = d_;
    if (port) {
        char name[OFP_MAX_PORT_NAME_LEN + 1];
        struct netdev *netdev;
        int retval;

        /* Check that this was really a change. */
        get_port_name(port, name, sizeof name);
        if (d->dhcp && !strcmp(netdev_get_name(dhclient_get_netdev(d->dhcp)),
                               name)) {
            return;
        }

        /* Destroy current DHCP client. */
        dhclient_destroy(d->dhcp);
        d->dhcp = NULL;

        /* Bring local network device up. */
        retval = netdev_open(name, NETDEV_ETH_TYPE_NONE, &netdev);
        if (retval) {
            VLOG_ERR(LOG_MODULE, "Could not open %s device, discovery disabled: %s",
                     name, strerror(retval));
            return;
        }
        retval = netdev_turn_flags_on(netdev, NETDEV_UP, true);
        if (retval) {
            VLOG_ERR(LOG_MODULE, "Could not bring %s device up, discovery disabled: %s",
                     name, strerror(retval));
            return;
        }
        netdev_close(netdev);

        /* Initialize DHCP client. */
        retval = dhclient_create(name, modify_dhcp_request,
                                 validate_dhcp_offer, (void *) d->s, &d->dhcp);
        if (retval) {
            VLOG_ERR(LOG_MODULE, "Failed to initialize DHCP client, "
                     "discovery disabled: %s", strerror(retval));
            return;
        }
        dhclient_set_max_timeout(d->dhcp, 3);
        dhclient_init(d->dhcp, 0);
    } else {
        dhclient_destroy(d->dhcp);
        d->dhcp = NULL;
    }
}
Exemple #2
0
static int
netdev_windows_system_construct(struct netdev *netdev_)
{
    struct netdev_windows *netdev = netdev_windows_cast(netdev_);
    struct netdev_windows_netdev_info info;
    struct ofpbuf *buf;
    int ret;

    /* Query the attributes and runtime status of the netdev. */
    ret = query_netdev(netdev_get_name(&netdev->up), &info, &buf);
    /* "Internal" netdevs do not exist in the kernel yet.  They need to be
     * transformed into a netdev object and passed to dpif_port_add(), which
     * will add them to the kernel.  */
    if (strcmp(netdev_get_type(&netdev->up), "internal") && ret) {
        return ret;
    }
    ofpbuf_delete(buf);

    netdev->change_seq = 1;
    netdev->dev_type = info.ovs_type;
    netdev->port_no = info.port_no;

    netdev->mac = info.mac_address;
    netdev->cache_valid = VALID_ETHERADDR;
    netdev->ifindex = -EOPNOTSUPP;

    netdev->mtu = info.mtu;
    netdev->cache_valid |= VALID_MTU;

    netdev->ifi_flags = dp_to_netdev_ifi_flags(info.ifi_flags);
    netdev->cache_valid |= VALID_IFFLAG;

    VLOG_DBG("construct device %s, ovs_type: %u.",
             netdev_get_name(&netdev->up), info.ovs_type);
    return 0;
}
Exemple #3
0
static int dev_ifname(struct net *net, struct ifreq *ifr)
{
	ifr->ifr_name[IFNAMSIZ-1] = 0;
	return netdev_get_name(net, ifr->ifr_name, ifr->ifr_ifindex);
}