2012-07-25 22:51:05 +02:00
|
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2011 Gaetano Catalli.
|
|
|
|
|
*
|
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
|
* You may obtain a copy of the License at:
|
|
|
|
|
*
|
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
*
|
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
|
* limitations under the License.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
2013-05-10 14:39:19 -07:00
|
|
|
|
#include "netdev-provider.h"
|
2012-07-25 22:51:05 +02:00
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <errno.h>
|
|
|
|
|
#include <fcntl.h>
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
|
#include <sys/time.h>
|
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
|
#include <sys/socket.h>
|
|
|
|
|
#include <sys/sockio.h>
|
|
|
|
|
#include <ifaddrs.h>
|
|
|
|
|
#include <pcap/pcap.h>
|
|
|
|
|
#include <net/if.h>
|
|
|
|
|
#include <net/if_dl.h>
|
|
|
|
|
#include <net/if_media.h>
|
|
|
|
|
#include <net/if_tap.h>
|
|
|
|
|
#include <netinet/in.h>
|
2013-05-21 17:49:54 +09:00
|
|
|
|
#ifdef HAVE_NET_IF_MIB_H
|
2012-07-25 22:51:05 +02:00
|
|
|
|
#include <net/if_mib.h>
|
2013-05-21 17:49:54 +09:00
|
|
|
|
#endif
|
2012-07-25 22:51:05 +02:00
|
|
|
|
#include <poll.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
#include <unistd.h>
|
|
|
|
|
#include <sys/sysctl.h>
|
|
|
|
|
|
|
|
|
|
#include "rtbsd.h"
|
|
|
|
|
#include "coverage.h"
|
|
|
|
|
#include "dynamic-string.h"
|
|
|
|
|
#include "fatal-signal.h"
|
|
|
|
|
#include "ofpbuf.h"
|
|
|
|
|
#include "openflow/openflow.h"
|
|
|
|
|
#include "packets.h"
|
|
|
|
|
#include "poll-loop.h"
|
|
|
|
|
#include "socket-util.h"
|
|
|
|
|
#include "shash.h"
|
|
|
|
|
#include "svec.h"
|
2012-11-06 13:14:55 -08:00
|
|
|
|
#include "util.h"
|
2012-07-25 22:51:05 +02:00
|
|
|
|
#include "vlog.h"
|
|
|
|
|
|
|
|
|
|
VLOG_DEFINE_THIS_MODULE(netdev_bsd);
|
|
|
|
|
|
|
|
|
|
|
2013-05-10 14:39:19 -07:00
|
|
|
|
struct netdev_rx_bsd {
|
|
|
|
|
struct netdev_rx up;
|
2012-07-25 22:51:05 +02:00
|
|
|
|
|
2013-05-10 14:39:19 -07:00
|
|
|
|
/* Packet capture descriptor for a system network device.
|
|
|
|
|
* For a tap device this is NULL. */
|
|
|
|
|
pcap_t *pcap_handle;
|
2012-07-25 22:51:05 +02:00
|
|
|
|
|
2013-05-10 14:39:19 -07:00
|
|
|
|
/* Selectable file descriptor for the network device.
|
|
|
|
|
* This descriptor will be used for polling operations. */
|
|
|
|
|
int fd;
|
2012-07-25 22:51:05 +02:00
|
|
|
|
};
|
|
|
|
|
|
2013-05-10 14:39:19 -07:00
|
|
|
|
static const struct netdev_rx_class netdev_rx_bsd_class;
|
|
|
|
|
|
2013-03-15 15:54:36 -07:00
|
|
|
|
struct netdev_bsd {
|
|
|
|
|
struct netdev up;
|
2012-07-25 22:51:05 +02:00
|
|
|
|
unsigned int cache_valid;
|
|
|
|
|
unsigned int change_seq;
|
|
|
|
|
|
|
|
|
|
int ifindex;
|
|
|
|
|
uint8_t etheraddr[ETH_ADDR_LEN];
|
|
|
|
|
struct in_addr in4;
|
|
|
|
|
struct in6_addr in6;
|
|
|
|
|
int mtu;
|
|
|
|
|
int carrier;
|
|
|
|
|
|
2013-05-10 14:39:19 -07:00
|
|
|
|
int tap_fd; /* TAP character device, if any, otherwise -1. */
|
|
|
|
|
|
|
|
|
|
/* Used for sending packets on non-tap devices. */
|
|
|
|
|
pcap_t *pcap;
|
|
|
|
|
int fd;
|
2013-05-21 17:49:55 +09:00
|
|
|
|
|
|
|
|
|
char *kernel_name;
|
2012-07-25 22:51:05 +02:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
enum {
|
|
|
|
|
VALID_IFINDEX = 1 << 0,
|
|
|
|
|
VALID_ETHERADDR = 1 << 1,
|
|
|
|
|
VALID_IN4 = 1 << 2,
|
|
|
|
|
VALID_IN6 = 1 << 3,
|
|
|
|
|
VALID_MTU = 1 << 4,
|
|
|
|
|
VALID_CARRIER = 1 << 5
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/* An AF_INET socket (used for ioctl operations). */
|
|
|
|
|
static int af_inet_sock = -1;
|
|
|
|
|
|
2013-05-21 17:49:56 +09:00
|
|
|
|
#if defined(__NetBSD__)
|
|
|
|
|
/* AF_LINK socket used for netdev_bsd_get_stats and set_etheraddr */
|
|
|
|
|
static int af_link_sock = -1;
|
|
|
|
|
#endif /* defined(__NetBSD__) */
|
|
|
|
|
|
2012-07-25 22:51:05 +02:00
|
|
|
|
#define PCAP_SNAPLEN 2048
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Notifier used to invalidate device informations in case of status change.
|
|
|
|
|
*
|
|
|
|
|
* It will be registered with a 'rtbsd_notifier_register()' when the first
|
|
|
|
|
* device will be created with the call of either 'netdev_bsd_tap_create()' or
|
|
|
|
|
* 'netdev_bsd_system_create()'.
|
|
|
|
|
*
|
|
|
|
|
* The callback associated with this notifier ('netdev_bsd_cache_cb()') will
|
|
|
|
|
* invalidate cached information about the device.
|
|
|
|
|
*/
|
|
|
|
|
static struct rtbsd_notifier netdev_bsd_cache_notifier;
|
|
|
|
|
static int cache_notifier_refcount;
|
|
|
|
|
|
|
|
|
|
static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(5, 20);
|
|
|
|
|
|
2013-05-10 08:55:25 -07:00
|
|
|
|
static int netdev_bsd_do_ioctl(const char *, struct ifreq *, unsigned long cmd,
|
|
|
|
|
const char *cmd_name);
|
2012-07-25 22:51:05 +02:00
|
|
|
|
static void destroy_tap(int fd, const char *name);
|
2013-03-15 15:54:36 -07:00
|
|
|
|
static int get_flags(const struct netdev *, int *flagsp);
|
2013-05-10 08:55:25 -07:00
|
|
|
|
static int set_flags(const char *, int flags);
|
2012-07-25 22:51:05 +02:00
|
|
|
|
static int do_set_addr(struct netdev *netdev,
|
|
|
|
|
int ioctl_nr, const char *ioctl_name,
|
|
|
|
|
struct in_addr addr);
|
|
|
|
|
static int get_etheraddr(const char *netdev_name, uint8_t ea[ETH_ADDR_LEN]);
|
|
|
|
|
static int set_etheraddr(const char *netdev_name, int hwaddr_family,
|
|
|
|
|
int hwaddr_len, const uint8_t[ETH_ADDR_LEN]);
|
|
|
|
|
static int get_ifindex(const struct netdev *, int *ifindexp);
|
|
|
|
|
|
2013-05-21 17:49:54 +09:00
|
|
|
|
static int ifr_get_flags(const struct ifreq *);
|
|
|
|
|
static void ifr_set_flags(struct ifreq *, int flags);
|
|
|
|
|
|
2012-07-25 22:51:05 +02:00
|
|
|
|
static int netdev_bsd_init(void);
|
|
|
|
|
|
|
|
|
|
static bool
|
|
|
|
|
is_netdev_bsd_class(const struct netdev_class *netdev_class)
|
|
|
|
|
{
|
|
|
|
|
return netdev_class->init == netdev_bsd_init;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static struct netdev_bsd *
|
|
|
|
|
netdev_bsd_cast(const struct netdev *netdev)
|
|
|
|
|
{
|
2013-03-15 15:54:36 -07:00
|
|
|
|
ovs_assert(is_netdev_bsd_class(netdev_get_class(netdev)));
|
2013-03-08 15:09:42 -08:00
|
|
|
|
return CONTAINER_OF(netdev, struct netdev_bsd, up);
|
2012-07-25 22:51:05 +02:00
|
|
|
|
}
|
|
|
|
|
|
2013-05-10 14:39:19 -07:00
|
|
|
|
static struct netdev_rx_bsd *
|
|
|
|
|
netdev_rx_bsd_cast(const struct netdev_rx *rx)
|
|
|
|
|
{
|
|
|
|
|
netdev_rx_assert_class(rx, &netdev_rx_bsd_class);
|
|
|
|
|
return CONTAINER_OF(rx, struct netdev_rx_bsd, up);
|
|
|
|
|
}
|
|
|
|
|
|
2013-05-21 17:49:55 +09:00
|
|
|
|
static const char *
|
|
|
|
|
netdev_get_kernel_name(const struct netdev *netdev)
|
|
|
|
|
{
|
|
|
|
|
return netdev_bsd_cast(netdev)->kernel_name;
|
|
|
|
|
}
|
|
|
|
|
|
2012-07-25 22:51:05 +02:00
|
|
|
|
/* Initialize the AF_INET socket used for ioctl operations */
|
|
|
|
|
static int
|
|
|
|
|
netdev_bsd_init(void)
|
|
|
|
|
{
|
|
|
|
|
static int status = -1;
|
|
|
|
|
|
|
|
|
|
if (status >= 0) { /* already initialized */
|
|
|
|
|
return status;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
af_inet_sock = socket(AF_INET, SOCK_DGRAM, 0);
|
|
|
|
|
status = af_inet_sock >= 0 ? 0 : errno;
|
|
|
|
|
if (status) {
|
|
|
|
|
VLOG_ERR("failed to create inet socket: %s", strerror(status));
|
2013-05-21 17:49:56 +09:00
|
|
|
|
return status;
|
|
|
|
|
}
|
|
|
|
|
|
2013-05-21 17:49:57 +09:00
|
|
|
|
#if defined(__NetBSD__)
|
2013-05-21 17:49:56 +09:00
|
|
|
|
af_link_sock = socket(AF_LINK, SOCK_DGRAM, 0);
|
|
|
|
|
status = af_link_sock >= 0 ? 0 : errno;
|
|
|
|
|
if (status) {
|
|
|
|
|
VLOG_ERR("failed to create link socket: %s", strerror(status));
|
|
|
|
|
close(af_inet_sock);
|
|
|
|
|
af_inet_sock = -1;
|
2012-07-25 22:51:05 +02:00
|
|
|
|
}
|
2013-05-21 17:49:57 +09:00
|
|
|
|
#endif /* defined(__NetBSD__) */
|
2012-07-25 22:51:05 +02:00
|
|
|
|
|
|
|
|
|
return status;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Perform periodic work needed by netdev. In BSD netdevs it checks for any
|
|
|
|
|
* interface status changes, and eventually calls all the user callbacks.
|
|
|
|
|
*/
|
|
|
|
|
static void
|
|
|
|
|
netdev_bsd_run(void)
|
|
|
|
|
{
|
|
|
|
|
rtbsd_notifier_run();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Arranges for poll_block() to wake up if the "run" member function needs to
|
|
|
|
|
* be called.
|
|
|
|
|
*/
|
|
|
|
|
static void
|
|
|
|
|
netdev_bsd_wait(void)
|
|
|
|
|
{
|
|
|
|
|
rtbsd_notifier_wait();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2013-03-15 15:54:36 -07:00
|
|
|
|
netdev_bsd_changed(struct netdev_bsd *dev)
|
2012-07-25 22:51:05 +02:00
|
|
|
|
{
|
|
|
|
|
dev->change_seq++;
|
|
|
|
|
if (!dev->change_seq) {
|
|
|
|
|
dev->change_seq++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Invalidate cache in case of interface status change. */
|
|
|
|
|
static void
|
|
|
|
|
netdev_bsd_cache_cb(const struct rtbsd_change *change,
|
2013-05-10 16:23:03 -04:00
|
|
|
|
void *aux OVS_UNUSED)
|
2012-07-25 22:51:05 +02:00
|
|
|
|
{
|
2013-03-15 15:54:36 -07:00
|
|
|
|
struct netdev_bsd *dev;
|
2012-07-25 22:51:05 +02:00
|
|
|
|
|
|
|
|
|
if (change) {
|
2013-03-15 15:54:36 -07:00
|
|
|
|
struct netdev *base_dev = netdev_from_name(change->if_name);
|
2012-07-25 22:51:05 +02:00
|
|
|
|
|
|
|
|
|
if (base_dev) {
|
|
|
|
|
const struct netdev_class *netdev_class =
|
2013-03-15 15:54:36 -07:00
|
|
|
|
netdev_get_class(base_dev);
|
2012-07-25 22:51:05 +02:00
|
|
|
|
|
|
|
|
|
if (is_netdev_bsd_class(netdev_class)) {
|
2013-03-15 15:54:36 -07:00
|
|
|
|
dev = netdev_bsd_cast(base_dev);
|
2012-07-25 22:51:05 +02:00
|
|
|
|
dev->cache_valid = 0;
|
2013-03-15 15:54:36 -07:00
|
|
|
|
netdev_bsd_changed(dev);
|
2012-07-25 22:51:05 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
/*
|
|
|
|
|
* XXX the API is lacking, we should be able to iterate on the list of
|
|
|
|
|
* netdevs without having to store the info in a temp shash.
|
|
|
|
|
*/
|
|
|
|
|
struct shash device_shash;
|
|
|
|
|
struct shash_node *node;
|
|
|
|
|
|
|
|
|
|
shash_init(&device_shash);
|
2013-03-15 15:54:36 -07:00
|
|
|
|
netdev_get_devices(&netdev_bsd_class, &device_shash);
|
2012-07-25 22:51:05 +02:00
|
|
|
|
SHASH_FOR_EACH (node, &device_shash) {
|
|
|
|
|
dev = node->data;
|
|
|
|
|
dev->cache_valid = 0;
|
2013-03-15 15:54:36 -07:00
|
|
|
|
netdev_bsd_changed(dev);
|
2012-07-25 22:51:05 +02:00
|
|
|
|
}
|
|
|
|
|
shash_destroy(&device_shash);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
|
cache_notifier_ref(void)
|
|
|
|
|
{
|
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
|
|
if (!cache_notifier_refcount) {
|
|
|
|
|
ret = rtbsd_notifier_register(&netdev_bsd_cache_notifier,
|
|
|
|
|
netdev_bsd_cache_cb, NULL);
|
|
|
|
|
if (ret) {
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
cache_notifier_refcount++;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
|
cache_notifier_unref(void)
|
|
|
|
|
{
|
|
|
|
|
cache_notifier_refcount--;
|
|
|
|
|
if (cache_notifier_refcount == 0) {
|
|
|
|
|
rtbsd_notifier_unregister(&netdev_bsd_cache_notifier);
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2013-03-15 15:54:36 -07:00
|
|
|
|
/* Allocate a netdev_bsd structure */
|
2012-07-25 22:51:05 +02:00
|
|
|
|
static int
|
|
|
|
|
netdev_bsd_create_system(const struct netdev_class *class, const char *name,
|
2013-03-15 15:54:36 -07:00
|
|
|
|
struct netdev **netdevp)
|
2012-07-25 22:51:05 +02:00
|
|
|
|
{
|
2013-03-15 15:54:36 -07:00
|
|
|
|
struct netdev_bsd *netdev;
|
|
|
|
|
enum netdev_flags flags;
|
2012-07-25 22:51:05 +02:00
|
|
|
|
int error;
|
|
|
|
|
|
|
|
|
|
error = cache_notifier_ref();
|
|
|
|
|
if (error) {
|
|
|
|
|
return error;
|
|
|
|
|
}
|
|
|
|
|
|
2013-03-15 15:54:36 -07:00
|
|
|
|
netdev = xzalloc(sizeof *netdev);
|
|
|
|
|
netdev->change_seq = 1;
|
|
|
|
|
netdev_init(&netdev->up, name, class);
|
|
|
|
|
netdev->tap_fd = -1;
|
2013-05-21 17:49:55 +09:00
|
|
|
|
netdev->kernel_name = xstrdup(name);
|
2012-07-25 22:51:05 +02:00
|
|
|
|
|
2013-03-15 15:54:36 -07:00
|
|
|
|
/* Verify that the netdev really exists by attempting to read its flags */
|
|
|
|
|
error = netdev_get_flags(&netdev->up, &flags);
|
|
|
|
|
if (error == ENXIO) {
|
|
|
|
|
netdev_uninit(&netdev->up, false);
|
|
|
|
|
free(netdev);
|
|
|
|
|
cache_notifier_unref();
|
|
|
|
|
return error;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
*netdevp = &netdev->up;
|
2012-07-25 22:51:05 +02:00
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
2013-03-15 15:54:36 -07:00
|
|
|
|
* Allocate a netdev_bsd structure with 'tap' class.
|
2012-07-25 22:51:05 +02:00
|
|
|
|
*/
|
|
|
|
|
static int
|
|
|
|
|
netdev_bsd_create_tap(const struct netdev_class *class, const char *name,
|
2013-03-15 15:54:36 -07:00
|
|
|
|
struct netdev **netdevp)
|
2012-07-25 22:51:05 +02:00
|
|
|
|
{
|
2013-03-15 15:54:36 -07:00
|
|
|
|
struct netdev_bsd *netdev = NULL;
|
2012-07-25 22:51:05 +02:00
|
|
|
|
int error = 0;
|
|
|
|
|
struct ifreq ifr;
|
2013-05-21 17:49:55 +09:00
|
|
|
|
char *kernel_name = NULL;
|
2012-07-25 22:51:05 +02:00
|
|
|
|
|
|
|
|
|
error = cache_notifier_ref();
|
|
|
|
|
if (error) {
|
|
|
|
|
goto error;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* allocate the device structure and set the internal flag */
|
2013-03-15 15:54:36 -07:00
|
|
|
|
netdev = xzalloc(sizeof *netdev);
|
2012-07-25 22:51:05 +02:00
|
|
|
|
|
|
|
|
|
memset(&ifr, 0, sizeof(ifr));
|
|
|
|
|
|
|
|
|
|
/* Create a tap device by opening /dev/tap. The TAPGIFNAME ioctl is used
|
|
|
|
|
* to retrieve the name of the tap device. */
|
2013-03-15 15:54:36 -07:00
|
|
|
|
netdev->tap_fd = open("/dev/tap", O_RDWR);
|
|
|
|
|
netdev->change_seq = 1;
|
|
|
|
|
if (netdev->tap_fd < 0) {
|
2012-07-25 22:51:05 +02:00
|
|
|
|
error = errno;
|
|
|
|
|
VLOG_WARN("opening \"/dev/tap\" failed: %s", strerror(error));
|
|
|
|
|
goto error_undef_notifier;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Retrieve tap name (e.g. tap0) */
|
2013-03-15 15:54:36 -07:00
|
|
|
|
if (ioctl(netdev->tap_fd, TAPGIFNAME, &ifr) == -1) {
|
2012-07-25 22:51:05 +02:00
|
|
|
|
/* XXX Need to destroy the device? */
|
|
|
|
|
error = errno;
|
|
|
|
|
goto error_undef_notifier;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Change the name of the tap device */
|
2013-05-21 17:49:54 +09:00
|
|
|
|
#if defined(SIOCSIFNAME)
|
2012-07-25 22:51:05 +02:00
|
|
|
|
ifr.ifr_data = (void *)name;
|
|
|
|
|
if (ioctl(af_inet_sock, SIOCSIFNAME, &ifr) == -1) {
|
|
|
|
|
error = errno;
|
2013-03-15 15:54:36 -07:00
|
|
|
|
destroy_tap(netdev->tap_fd, ifr.ifr_name);
|
2012-07-25 22:51:05 +02:00
|
|
|
|
goto error_undef_notifier;
|
|
|
|
|
}
|
2013-05-21 17:49:55 +09:00
|
|
|
|
kernel_name = xstrdup(name);
|
2013-05-21 17:49:54 +09:00
|
|
|
|
#else
|
|
|
|
|
/*
|
|
|
|
|
* NetBSD doesn't support inteface renaming.
|
|
|
|
|
*/
|
|
|
|
|
VLOG_INFO("tap %s is created for bridge %s", ifr.ifr_name, name);
|
2013-05-21 17:49:55 +09:00
|
|
|
|
kernel_name = xstrdup(ifr.ifr_name);
|
2013-05-21 17:49:54 +09:00
|
|
|
|
#endif
|
2012-07-25 22:51:05 +02:00
|
|
|
|
|
|
|
|
|
/* set non-blocking. */
|
2013-03-15 15:54:36 -07:00
|
|
|
|
error = set_nonblocking(netdev->tap_fd);
|
2012-07-25 22:51:05 +02:00
|
|
|
|
if (error) {
|
2013-05-21 17:49:55 +09:00
|
|
|
|
destroy_tap(netdev->tap_fd, kernel_name);
|
2012-07-25 22:51:05 +02:00
|
|
|
|
goto error_undef_notifier;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Turn device UP */
|
2013-05-21 17:49:54 +09:00
|
|
|
|
ifr_set_flags(&ifr, IFF_UP);
|
2013-05-21 17:49:55 +09:00
|
|
|
|
strncpy(ifr.ifr_name, kernel_name, sizeof ifr.ifr_name);
|
2012-07-25 22:51:05 +02:00
|
|
|
|
if (ioctl(af_inet_sock, SIOCSIFFLAGS, &ifr) == -1) {
|
|
|
|
|
error = errno;
|
2013-05-21 17:49:55 +09:00
|
|
|
|
destroy_tap(netdev->tap_fd, kernel_name);
|
2012-07-25 22:51:05 +02:00
|
|
|
|
goto error_undef_notifier;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* initialize the device structure and
|
|
|
|
|
* link the structure to its netdev */
|
2013-03-15 15:54:36 -07:00
|
|
|
|
netdev_init(&netdev->up, name, class);
|
2013-05-21 17:49:55 +09:00
|
|
|
|
netdev->kernel_name = kernel_name;
|
2013-03-15 15:54:36 -07:00
|
|
|
|
*netdevp = &netdev->up;
|
2012-07-25 22:51:05 +02:00
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
error_undef_notifier:
|
|
|
|
|
cache_notifier_unref();
|
|
|
|
|
error:
|
2013-03-15 15:54:36 -07:00
|
|
|
|
free(netdev);
|
2013-05-21 17:49:55 +09:00
|
|
|
|
free(kernel_name);
|
2012-07-25 22:51:05 +02:00
|
|
|
|
return error;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2013-03-15 15:54:36 -07:00
|
|
|
|
netdev_bsd_destroy(struct netdev *netdev_)
|
2012-07-25 22:51:05 +02:00
|
|
|
|
{
|
2013-03-15 15:54:36 -07:00
|
|
|
|
struct netdev_bsd *netdev = netdev_bsd_cast(netdev_);
|
2012-07-25 22:51:05 +02:00
|
|
|
|
|
|
|
|
|
cache_notifier_unref();
|
|
|
|
|
|
2013-03-15 15:54:36 -07:00
|
|
|
|
if (netdev->tap_fd >= 0) {
|
2013-05-21 17:49:55 +09:00
|
|
|
|
destroy_tap(netdev->tap_fd, netdev_get_kernel_name(netdev_));
|
2012-07-25 22:51:05 +02:00
|
|
|
|
}
|
2013-03-15 15:54:36 -07:00
|
|
|
|
if (netdev->pcap) {
|
|
|
|
|
pcap_close(netdev->pcap);
|
2013-05-10 14:39:19 -07:00
|
|
|
|
}
|
2013-05-21 17:49:55 +09:00
|
|
|
|
free(netdev->kernel_name);
|
2012-07-25 22:51:05 +02:00
|
|
|
|
free(netdev);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int
|
2013-05-10 14:39:19 -07:00
|
|
|
|
netdev_bsd_open_pcap(const char *name, pcap_t **pcapp, int *fdp)
|
2012-07-25 22:51:05 +02:00
|
|
|
|
{
|
|
|
|
|
char errbuf[PCAP_ERRBUF_SIZE];
|
2013-05-10 14:39:19 -07:00
|
|
|
|
pcap_t *pcap = NULL;
|
2012-07-25 22:51:05 +02:00
|
|
|
|
int one = 1;
|
2013-05-10 14:39:19 -07:00
|
|
|
|
int error;
|
|
|
|
|
int fd;
|
2012-07-25 22:51:05 +02:00
|
|
|
|
|
2013-05-10 14:39:19 -07:00
|
|
|
|
/* Open the pcap device. The device is opened in non-promiscuous mode
|
2012-07-25 22:51:05 +02:00
|
|
|
|
* because the interface flags are manually set by the caller. */
|
|
|
|
|
errbuf[0] = '\0';
|
2013-05-10 14:39:19 -07:00
|
|
|
|
pcap = pcap_open_live(name, PCAP_SNAPLEN, 0, 1000, errbuf);
|
|
|
|
|
if (!pcap) {
|
|
|
|
|
VLOG_ERR_RL(&rl, "%s: pcap_open_live failed: %s", name, errbuf);
|
2012-07-25 22:51:05 +02:00
|
|
|
|
error = EIO;
|
|
|
|
|
goto error;
|
2013-05-10 14:39:19 -07:00
|
|
|
|
}
|
|
|
|
|
if (errbuf[0] != '\0') {
|
|
|
|
|
VLOG_WARN_RL(&rl, "%s: pcap_open_live: %s", name, errbuf);
|
2012-07-25 22:51:05 +02:00
|
|
|
|
}
|
|
|
|
|
|
2013-05-10 14:39:19 -07:00
|
|
|
|
/* Get the underlying fd. */
|
|
|
|
|
fd = pcap_get_selectable_fd(pcap);
|
2012-07-25 22:51:05 +02:00
|
|
|
|
if (fd == -1) {
|
2013-05-10 14:39:19 -07:00
|
|
|
|
VLOG_WARN_RL(&rl, "%s: no selectable file descriptor", name);
|
2012-07-25 22:51:05 +02:00
|
|
|
|
error = errno;
|
|
|
|
|
goto error;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Set non-blocking mode. Also the BIOCIMMEDIATE ioctl must be called
|
|
|
|
|
* on the file descriptor returned by pcap_get_selectable_fd to achieve
|
|
|
|
|
* a real non-blocking behaviour.*/
|
2013-05-10 14:39:19 -07:00
|
|
|
|
error = pcap_setnonblock(pcap, 1, errbuf);
|
2012-07-25 22:51:05 +02:00
|
|
|
|
if (error == -1) {
|
|
|
|
|
error = errno;
|
|
|
|
|
goto error;
|
|
|
|
|
}
|
|
|
|
|
|
2013-05-10 14:39:19 -07:00
|
|
|
|
/* This call assure that reads return immediately upon packet
|
|
|
|
|
* reception. Otherwise, a read will block until either the kernel
|
|
|
|
|
* buffer becomes full or a timeout occurs. */
|
|
|
|
|
if (ioctl(fd, BIOCIMMEDIATE, &one) < 0 ) {
|
|
|
|
|
VLOG_ERR_RL(&rl, "ioctl(BIOCIMMEDIATE) on %s device failed: %s",
|
|
|
|
|
name, strerror(errno));
|
2012-07-25 22:51:05 +02:00
|
|
|
|
error = errno;
|
|
|
|
|
goto error;
|
|
|
|
|
}
|
|
|
|
|
|
2013-05-10 14:39:19 -07:00
|
|
|
|
/* Capture only incoming packets. */
|
|
|
|
|
error = pcap_setdirection(pcap, PCAP_D_IN);
|
2012-07-25 22:51:05 +02:00
|
|
|
|
if (error == -1) {
|
|
|
|
|
error = errno;
|
|
|
|
|
goto error;
|
|
|
|
|
}
|
|
|
|
|
|
2013-05-10 14:39:19 -07:00
|
|
|
|
*pcapp = pcap;
|
|
|
|
|
*fdp = fd;
|
2012-07-25 22:51:05 +02:00
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
error:
|
2013-05-10 14:39:19 -07:00
|
|
|
|
if (pcap) {
|
|
|
|
|
pcap_close(pcap);
|
2012-07-25 22:51:05 +02:00
|
|
|
|
}
|
2013-05-10 14:39:19 -07:00
|
|
|
|
*pcapp = NULL;
|
|
|
|
|
*fdp = -1;
|
2012-07-25 22:51:05 +02:00
|
|
|
|
return error;
|
|
|
|
|
}
|
|
|
|
|
|
2013-05-10 14:39:19 -07:00
|
|
|
|
static int
|
|
|
|
|
netdev_bsd_rx_open(struct netdev *netdev_, struct netdev_rx **rxp)
|
|
|
|
|
{
|
2013-03-15 15:54:36 -07:00
|
|
|
|
struct netdev_bsd *netdev = netdev_bsd_cast(netdev_);
|
2013-05-10 14:39:19 -07:00
|
|
|
|
|
|
|
|
|
struct netdev_rx_bsd *rx;
|
|
|
|
|
pcap_t *pcap;
|
|
|
|
|
int fd;
|
|
|
|
|
|
|
|
|
|
if (!strcmp(netdev_get_type(netdev_), "tap")) {
|
|
|
|
|
pcap = NULL;
|
2013-03-15 15:54:36 -07:00
|
|
|
|
fd = netdev->tap_fd;
|
2013-05-10 14:39:19 -07:00
|
|
|
|
} else {
|
2013-05-21 17:49:55 +09:00
|
|
|
|
int error = netdev_bsd_open_pcap(netdev_get_kernel_name(netdev_),
|
|
|
|
|
&pcap, &fd);
|
2013-05-10 14:39:19 -07:00
|
|
|
|
if (error) {
|
|
|
|
|
return error;
|
|
|
|
|
}
|
|
|
|
|
|
2013-03-15 15:54:36 -07:00
|
|
|
|
netdev_bsd_changed(netdev);
|
2013-05-10 14:39:19 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
rx = xmalloc(sizeof *rx);
|
2013-03-15 15:54:36 -07:00
|
|
|
|
netdev_rx_init(&rx->up, netdev_, &netdev_rx_bsd_class);
|
2013-05-10 14:39:19 -07:00
|
|
|
|
rx->pcap_handle = pcap;
|
|
|
|
|
rx->fd = fd;
|
|
|
|
|
|
|
|
|
|
*rxp = &rx->up;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
netdev_rx_bsd_destroy(struct netdev_rx *rx_)
|
|
|
|
|
{
|
|
|
|
|
struct netdev_rx_bsd *rx = netdev_rx_bsd_cast(rx_);
|
|
|
|
|
|
|
|
|
|
if (rx->pcap_handle) {
|
|
|
|
|
pcap_close(rx->pcap_handle);
|
|
|
|
|
}
|
|
|
|
|
free(rx);
|
|
|
|
|
}
|
2012-07-25 22:51:05 +02:00
|
|
|
|
|
|
|
|
|
/* The recv callback of the netdev class returns the number of bytes of the
|
|
|
|
|
* received packet.
|
|
|
|
|
*
|
|
|
|
|
* This can be done by the pcap_next() function. Unfortunately pcap_next() does
|
|
|
|
|
* not make difference between a missing packet on the capture interface and
|
|
|
|
|
* an error during the file capture. We can use the pcap_dispatch() function
|
|
|
|
|
* instead, which is able to distinguish between errors and null packet.
|
|
|
|
|
*
|
|
|
|
|
* To make pcap_dispatch() returns the number of bytes read from the interface
|
|
|
|
|
* we need to define the following callback and argument.
|
|
|
|
|
*/
|
|
|
|
|
struct pcap_arg {
|
|
|
|
|
void *data;
|
|
|
|
|
int size;
|
|
|
|
|
int retval;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* This callback will be executed on every captured packet.
|
|
|
|
|
*
|
|
|
|
|
* If the packet captured by pcap_dispatch() does not fit the pcap buffer,
|
|
|
|
|
* pcap returns a truncated packet and we follow this behavior.
|
|
|
|
|
*
|
|
|
|
|
* The argument args->retval is the packet size in bytes.
|
|
|
|
|
*/
|
|
|
|
|
static void
|
|
|
|
|
proc_pkt(u_char *args_, const struct pcap_pkthdr *hdr, const u_char *packet)
|
|
|
|
|
{
|
|
|
|
|
struct pcap_arg *args = (struct pcap_arg *)args_;
|
|
|
|
|
|
|
|
|
|
if (args->size < hdr->len) {
|
|
|
|
|
VLOG_WARN_RL(&rl, "packet truncated");
|
|
|
|
|
args->retval = args->size;
|
|
|
|
|
} else {
|
|
|
|
|
args->retval = hdr->len;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* copy the packet to our buffer */
|
|
|
|
|
memcpy(args->data, packet, args->retval);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* This function attempts to receive a packet from the specified network
|
|
|
|
|
* device. It is assumed that the network device is a system device or a tap
|
|
|
|
|
* device opened as a system one. In this case the read operation is performed
|
2013-05-10 14:39:19 -07:00
|
|
|
|
* from rx->pcap.
|
2012-07-25 22:51:05 +02:00
|
|
|
|
*/
|
|
|
|
|
static int
|
2013-05-10 14:39:19 -07:00
|
|
|
|
netdev_rx_bsd_recv_pcap(struct netdev_rx_bsd *rx, void *data, size_t size)
|
2012-07-25 22:51:05 +02:00
|
|
|
|
{
|
|
|
|
|
struct pcap_arg arg;
|
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
|
|
/* prepare the pcap argument to store the packet */
|
|
|
|
|
arg.size = size;
|
|
|
|
|
arg.data = data;
|
|
|
|
|
|
|
|
|
|
for (;;) {
|
2013-05-10 14:39:19 -07:00
|
|
|
|
ret = pcap_dispatch(rx->pcap_handle, 1, proc_pkt, (u_char *) &arg);
|
2012-07-25 22:51:05 +02:00
|
|
|
|
|
|
|
|
|
if (ret > 0) {
|
|
|
|
|
return arg.retval; /* arg.retval < 0 is handled in the caller */
|
|
|
|
|
}
|
|
|
|
|
if (ret == -1) {
|
|
|
|
|
if (errno == EINTR) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return -EAGAIN;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* This function attempts to receive a packet from the specified network
|
2013-05-10 14:39:19 -07:00
|
|
|
|
* device. It is assumed that the network device is a tap device and
|
|
|
|
|
* 'rx->fd' is initialized with the tap file descriptor.
|
2012-07-25 22:51:05 +02:00
|
|
|
|
*/
|
|
|
|
|
static int
|
2013-05-10 14:39:19 -07:00
|
|
|
|
netdev_rx_bsd_recv_tap(struct netdev_rx_bsd *rx, void *data, size_t size)
|
2012-07-25 22:51:05 +02:00
|
|
|
|
{
|
|
|
|
|
for (;;) {
|
2013-05-10 14:39:19 -07:00
|
|
|
|
ssize_t retval = read(rx->fd, data, size);
|
2012-07-25 22:51:05 +02:00
|
|
|
|
if (retval >= 0) {
|
|
|
|
|
return retval;
|
|
|
|
|
} else if (errno != EINTR) {
|
|
|
|
|
if (errno != EAGAIN) {
|
|
|
|
|
VLOG_WARN_RL(&rl, "error receiving Ethernet packet on %s: %s",
|
2013-05-10 14:39:19 -07:00
|
|
|
|
strerror(errno), netdev_rx_get_name(&rx->up));
|
2012-07-25 22:51:05 +02:00
|
|
|
|
}
|
|
|
|
|
return -errno;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
2013-05-10 14:39:19 -07:00
|
|
|
|
netdev_rx_bsd_recv(struct netdev_rx *rx_, void *data, size_t size)
|
2012-07-25 22:51:05 +02:00
|
|
|
|
{
|
2013-05-10 14:39:19 -07:00
|
|
|
|
struct netdev_rx_bsd *rx = netdev_rx_bsd_cast(rx_);
|
2012-07-25 22:51:05 +02:00
|
|
|
|
|
2013-05-10 14:39:19 -07:00
|
|
|
|
return (rx->pcap_handle
|
|
|
|
|
? netdev_rx_bsd_recv_pcap(rx, data, size)
|
|
|
|
|
: netdev_rx_bsd_recv_tap(rx, data, size));
|
2012-07-25 22:51:05 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Registers with the poll loop to wake up from the next call to poll_block()
|
2013-05-10 14:39:19 -07:00
|
|
|
|
* when a packet is ready to be received with netdev_rx_recv() on 'rx'.
|
2012-07-25 22:51:05 +02:00
|
|
|
|
*/
|
|
|
|
|
static void
|
2013-05-10 14:39:19 -07:00
|
|
|
|
netdev_rx_bsd_wait(struct netdev_rx *rx_)
|
2012-07-25 22:51:05 +02:00
|
|
|
|
{
|
2013-05-10 14:39:19 -07:00
|
|
|
|
struct netdev_rx_bsd *rx = netdev_rx_bsd_cast(rx_);
|
2012-07-25 22:51:05 +02:00
|
|
|
|
|
2013-05-10 14:39:19 -07:00
|
|
|
|
poll_fd_wait(rx->fd, POLLIN);
|
2012-07-25 22:51:05 +02:00
|
|
|
|
}
|
|
|
|
|
|
2013-05-10 14:39:19 -07:00
|
|
|
|
/* Discards all packets waiting to be received from 'rx'. */
|
2012-07-25 22:51:05 +02:00
|
|
|
|
static int
|
2013-05-10 14:39:19 -07:00
|
|
|
|
netdev_rx_bsd_drain(struct netdev_rx *rx_)
|
2012-07-25 22:51:05 +02:00
|
|
|
|
{
|
|
|
|
|
struct ifreq ifr;
|
2013-05-10 14:39:19 -07:00
|
|
|
|
struct netdev_rx_bsd *rx = netdev_rx_bsd_cast(rx_);
|
2012-07-25 22:51:05 +02:00
|
|
|
|
|
2013-05-21 17:49:55 +09:00
|
|
|
|
strcpy(ifr.ifr_name, netdev_get_kernel_name(netdev_rx_get_netdev(rx_)));
|
2013-05-10 14:39:19 -07:00
|
|
|
|
if (ioctl(rx->fd, BIOCFLUSH, &ifr) == -1) {
|
2012-07-25 22:51:05 +02:00
|
|
|
|
VLOG_DBG_RL(&rl, "%s: ioctl(BIOCFLUSH) failed: %s",
|
2013-05-10 14:39:19 -07:00
|
|
|
|
netdev_rx_get_name(rx_), strerror(errno));
|
2012-07-25 22:51:05 +02:00
|
|
|
|
return errno;
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Send a packet on the specified network device. The device could be either a
|
|
|
|
|
* system or a tap device.
|
|
|
|
|
*/
|
|
|
|
|
static int
|
|
|
|
|
netdev_bsd_send(struct netdev *netdev_, const void *data, size_t size)
|
|
|
|
|
{
|
2013-03-15 15:54:36 -07:00
|
|
|
|
struct netdev_bsd *dev = netdev_bsd_cast(netdev_);
|
2013-05-10 14:39:19 -07:00
|
|
|
|
const char *name = netdev_get_name(netdev_);
|
2012-07-25 22:51:05 +02:00
|
|
|
|
|
2013-05-10 14:39:19 -07:00
|
|
|
|
if (dev->tap_fd < 0 && !dev->pcap) {
|
|
|
|
|
int error = netdev_bsd_open_pcap(name, &dev->pcap, &dev->fd);
|
|
|
|
|
if (error) {
|
|
|
|
|
return error;
|
|
|
|
|
}
|
2012-07-25 22:51:05 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (;;) {
|
|
|
|
|
ssize_t retval;
|
2013-05-10 14:39:19 -07:00
|
|
|
|
if (dev->tap_fd >= 0) {
|
|
|
|
|
retval = write(dev->tap_fd, data, size);
|
2012-07-25 22:51:05 +02:00
|
|
|
|
} else {
|
2013-05-10 14:39:19 -07:00
|
|
|
|
retval = pcap_inject(dev->pcap, data, size);
|
2012-07-25 22:51:05 +02:00
|
|
|
|
}
|
|
|
|
|
if (retval < 0) {
|
|
|
|
|
if (errno == EINTR) {
|
|
|
|
|
continue;
|
|
|
|
|
} else if (errno != EAGAIN) {
|
|
|
|
|
VLOG_WARN_RL(&rl, "error sending Ethernet packet on %s: %s",
|
2013-05-10 14:39:19 -07:00
|
|
|
|
name, strerror(errno));
|
2012-07-25 22:51:05 +02:00
|
|
|
|
}
|
|
|
|
|
return errno;
|
|
|
|
|
} else if (retval != size) {
|
|
|
|
|
VLOG_WARN_RL(&rl, "sent partial Ethernet packet (%zd bytes of "
|
2013-05-10 14:39:19 -07:00
|
|
|
|
"%zu) on %s", retval, size, name);
|
2012-07-25 22:51:05 +02:00
|
|
|
|
return EMSGSIZE;
|
|
|
|
|
} else {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Registers with the poll loop to wake up from the next call to poll_block()
|
|
|
|
|
* when the packet transmission queue has sufficient room to transmit a packet
|
|
|
|
|
* with netdev_send().
|
|
|
|
|
*/
|
|
|
|
|
static void
|
|
|
|
|
netdev_bsd_send_wait(struct netdev *netdev_)
|
|
|
|
|
{
|
2013-03-15 15:54:36 -07:00
|
|
|
|
struct netdev_bsd *dev = netdev_bsd_cast(netdev_);
|
2012-07-25 22:51:05 +02:00
|
|
|
|
|
2013-05-10 14:39:19 -07:00
|
|
|
|
if (dev->tap_fd >= 0) {
|
2012-07-25 22:51:05 +02:00
|
|
|
|
/* TAP device always accepts packets. */
|
|
|
|
|
poll_immediate_wake();
|
2013-05-10 14:39:19 -07:00
|
|
|
|
} else if (dev->pcap) {
|
|
|
|
|
poll_fd_wait(dev->fd, POLLOUT);
|
|
|
|
|
} else {
|
|
|
|
|
/* We haven't even tried to send a packet yet. */
|
|
|
|
|
poll_immediate_wake();
|
2012-07-25 22:51:05 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Attempts to set 'netdev''s MAC address to 'mac'. Returns 0 if successful,
|
|
|
|
|
* otherwise a positive errno value.
|
|
|
|
|
*/
|
|
|
|
|
static int
|
|
|
|
|
netdev_bsd_set_etheraddr(struct netdev *netdev_,
|
2013-05-10 16:23:03 -04:00
|
|
|
|
const uint8_t mac[ETH_ADDR_LEN])
|
2012-07-25 22:51:05 +02:00
|
|
|
|
{
|
2013-03-15 15:54:36 -07:00
|
|
|
|
struct netdev_bsd *netdev = netdev_bsd_cast(netdev_);
|
2012-07-25 22:51:05 +02:00
|
|
|
|
int error;
|
|
|
|
|
|
2013-03-15 15:54:36 -07:00
|
|
|
|
if (!(netdev->cache_valid & VALID_ETHERADDR)
|
|
|
|
|
|| !eth_addr_equals(netdev->etheraddr, mac)) {
|
2013-05-21 17:49:55 +09:00
|
|
|
|
error = set_etheraddr(netdev_get_kernel_name(netdev_), AF_LINK,
|
|
|
|
|
ETH_ADDR_LEN, mac);
|
2012-07-25 22:51:05 +02:00
|
|
|
|
if (!error) {
|
2013-03-15 15:54:36 -07:00
|
|
|
|
netdev->cache_valid |= VALID_ETHERADDR;
|
|
|
|
|
memcpy(netdev->etheraddr, mac, ETH_ADDR_LEN);
|
|
|
|
|
netdev_bsd_changed(netdev);
|
2012-07-25 22:51:05 +02:00
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
error = 0;
|
|
|
|
|
}
|
|
|
|
|
return error;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Returns a pointer to 'netdev''s MAC address. The caller must not modify or
|
|
|
|
|
* free the returned buffer.
|
|
|
|
|
*/
|
|
|
|
|
static int
|
|
|
|
|
netdev_bsd_get_etheraddr(const struct netdev *netdev_,
|
2013-05-10 16:23:03 -04:00
|
|
|
|
uint8_t mac[ETH_ADDR_LEN])
|
2012-07-25 22:51:05 +02:00
|
|
|
|
{
|
2013-03-15 15:54:36 -07:00
|
|
|
|
struct netdev_bsd *netdev = netdev_bsd_cast(netdev_);
|
2012-07-25 22:51:05 +02:00
|
|
|
|
|
2013-03-15 15:54:36 -07:00
|
|
|
|
if (!(netdev->cache_valid & VALID_ETHERADDR)) {
|
2013-05-21 17:49:55 +09:00
|
|
|
|
int error = get_etheraddr(netdev_get_kernel_name(netdev_),
|
2013-03-15 15:54:36 -07:00
|
|
|
|
netdev->etheraddr);
|
2012-07-25 22:51:05 +02:00
|
|
|
|
if (error) {
|
|
|
|
|
return error;
|
|
|
|
|
}
|
2013-03-15 15:54:36 -07:00
|
|
|
|
netdev->cache_valid |= VALID_ETHERADDR;
|
2012-07-25 22:51:05 +02:00
|
|
|
|
}
|
2013-03-15 15:54:36 -07:00
|
|
|
|
memcpy(mac, netdev->etheraddr, ETH_ADDR_LEN);
|
2012-07-25 22:51:05 +02:00
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Returns the maximum size of transmitted (and received) packets on 'netdev',
|
|
|
|
|
* in bytes, not including the hardware header; thus, this is typically 1500
|
|
|
|
|
* bytes for Ethernet devices.
|
|
|
|
|
*/
|
|
|
|
|
static int
|
|
|
|
|
netdev_bsd_get_mtu(const struct netdev *netdev_, int *mtup)
|
|
|
|
|
{
|
2013-03-15 15:54:36 -07:00
|
|
|
|
struct netdev_bsd *netdev = netdev_bsd_cast(netdev_);
|
2012-07-25 22:51:05 +02:00
|
|
|
|
|
2013-03-15 15:54:36 -07:00
|
|
|
|
if (!(netdev->cache_valid & VALID_MTU)) {
|
2012-07-25 22:51:05 +02:00
|
|
|
|
struct ifreq ifr;
|
|
|
|
|
int error;
|
|
|
|
|
|
2013-05-21 17:49:55 +09:00
|
|
|
|
error = netdev_bsd_do_ioctl(netdev_get_kernel_name(netdev_), &ifr,
|
|
|
|
|
SIOCGIFMTU, "SIOCGIFMTU");
|
2012-07-25 22:51:05 +02:00
|
|
|
|
if (error) {
|
|
|
|
|
return error;
|
|
|
|
|
}
|
2013-03-15 15:54:36 -07:00
|
|
|
|
netdev->mtu = ifr.ifr_mtu;
|
|
|
|
|
netdev->cache_valid |= VALID_MTU;
|
2012-07-25 22:51:05 +02:00
|
|
|
|
}
|
|
|
|
|
|
2013-03-15 15:54:36 -07:00
|
|
|
|
*mtup = netdev->mtu;
|
2012-07-25 22:51:05 +02:00
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
|
netdev_bsd_get_ifindex(const struct netdev *netdev)
|
|
|
|
|
{
|
|
|
|
|
int ifindex, error;
|
|
|
|
|
|
|
|
|
|
error = get_ifindex(netdev, &ifindex);
|
|
|
|
|
return error ? -error : ifindex;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
|
netdev_bsd_get_carrier(const struct netdev *netdev_, bool *carrier)
|
|
|
|
|
{
|
2013-03-15 15:54:36 -07:00
|
|
|
|
struct netdev_bsd *netdev = netdev_bsd_cast(netdev_);
|
2012-07-25 22:51:05 +02:00
|
|
|
|
|
2013-03-15 15:54:36 -07:00
|
|
|
|
if (!(netdev->cache_valid & VALID_CARRIER)) {
|
2012-07-25 22:51:05 +02:00
|
|
|
|
struct ifmediareq ifmr;
|
|
|
|
|
|
|
|
|
|
memset(&ifmr, 0, sizeof(ifmr));
|
2013-05-21 17:49:55 +09:00
|
|
|
|
strncpy(ifmr.ifm_name, netdev_get_kernel_name(netdev_),
|
|
|
|
|
sizeof ifmr.ifm_name);
|
2012-07-25 22:51:05 +02:00
|
|
|
|
|
|
|
|
|
if (ioctl(af_inet_sock, SIOCGIFMEDIA, &ifmr) == -1) {
|
|
|
|
|
VLOG_DBG_RL(&rl, "%s: ioctl(SIOCGIFMEDIA) failed: %s",
|
|
|
|
|
netdev_get_name(netdev_), strerror(errno));
|
|
|
|
|
return errno;
|
|
|
|
|
}
|
|
|
|
|
|
2013-03-15 15:54:36 -07:00
|
|
|
|
netdev->carrier = (ifmr.ifm_status & IFM_ACTIVE) == IFM_ACTIVE;
|
|
|
|
|
netdev->cache_valid |= VALID_CARRIER;
|
2012-07-25 22:51:05 +02:00
|
|
|
|
|
|
|
|
|
/* If the interface doesn't report whether the media is active,
|
|
|
|
|
* just assume it is active. */
|
|
|
|
|
if ((ifmr.ifm_status & IFM_AVALID) == 0) {
|
2013-03-15 15:54:36 -07:00
|
|
|
|
netdev->carrier = true;
|
2012-07-25 22:51:05 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
2013-03-15 15:54:36 -07:00
|
|
|
|
*carrier = netdev->carrier;
|
2012-07-25 22:51:05 +02:00
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Retrieves current device stats for 'netdev'. */
|
|
|
|
|
static int
|
2013-05-21 17:49:54 +09:00
|
|
|
|
netdev_bsd_get_stats(const struct netdev *netdev_ OVS_UNUSED,
|
|
|
|
|
struct netdev_stats *stats)
|
2012-07-25 22:51:05 +02:00
|
|
|
|
{
|
2013-05-21 17:49:54 +09:00
|
|
|
|
#if defined(__FreeBSD__)
|
2012-07-25 22:51:05 +02:00
|
|
|
|
int if_count, i;
|
|
|
|
|
int mib[6];
|
|
|
|
|
size_t len;
|
|
|
|
|
struct ifmibdata ifmd;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mib[0] = CTL_NET;
|
|
|
|
|
mib[1] = PF_LINK;
|
|
|
|
|
mib[2] = NETLINK_GENERIC;
|
|
|
|
|
mib[3] = IFMIB_SYSTEM;
|
|
|
|
|
mib[4] = IFMIB_IFCOUNT;
|
|
|
|
|
|
|
|
|
|
len = sizeof(if_count);
|
|
|
|
|
|
|
|
|
|
if (sysctl(mib, 5, &if_count, &len, (void *)0, 0) == -1) {
|
|
|
|
|
VLOG_DBG_RL(&rl, "%s: sysctl failed: %s",
|
|
|
|
|
netdev_get_name(netdev_), strerror(errno));
|
|
|
|
|
return errno;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
mib[5] = IFDATA_GENERAL;
|
|
|
|
|
mib[3] = IFMIB_IFDATA;
|
|
|
|
|
len = sizeof(ifmd);
|
|
|
|
|
for (i = 1; i <= if_count; i++) {
|
|
|
|
|
mib[4] = i; //row
|
|
|
|
|
if (sysctl(mib, 6, &ifmd, &len, (void *)0, 0) == -1) {
|
|
|
|
|
VLOG_DBG_RL(&rl, "%s: sysctl failed: %s",
|
|
|
|
|
netdev_get_name(netdev_), strerror(errno));
|
|
|
|
|
return errno;
|
|
|
|
|
} else if (!strcmp(ifmd.ifmd_name, netdev_get_name(netdev_))) {
|
|
|
|
|
stats->rx_packets = ifmd.ifmd_data.ifi_ipackets;
|
|
|
|
|
stats->tx_packets = ifmd.ifmd_data.ifi_opackets;
|
|
|
|
|
stats->rx_bytes = ifmd.ifmd_data.ifi_ibytes;
|
|
|
|
|
stats->tx_bytes = ifmd.ifmd_data.ifi_obytes;
|
|
|
|
|
stats->rx_errors = ifmd.ifmd_data.ifi_ierrors;
|
|
|
|
|
stats->tx_errors = ifmd.ifmd_data.ifi_oerrors;
|
|
|
|
|
stats->rx_dropped = ifmd.ifmd_data.ifi_iqdrops;
|
2013-05-03 16:57:38 -04:00
|
|
|
|
stats->tx_dropped = UINT64_MAX;
|
2012-07-25 22:51:05 +02:00
|
|
|
|
stats->multicast = ifmd.ifmd_data.ifi_imcasts;
|
|
|
|
|
stats->collisions = ifmd.ifmd_data.ifi_collisions;
|
|
|
|
|
|
2013-05-03 16:57:38 -04:00
|
|
|
|
stats->rx_length_errors = UINT64_MAX;
|
|
|
|
|
stats->rx_over_errors = UINT64_MAX;
|
|
|
|
|
stats->rx_crc_errors = UINT64_MAX;
|
|
|
|
|
stats->rx_frame_errors = UINT64_MAX;
|
|
|
|
|
stats->rx_fifo_errors = UINT64_MAX;
|
|
|
|
|
stats->rx_missed_errors = UINT64_MAX;
|
|
|
|
|
|
|
|
|
|
stats->tx_aborted_errors = UINT64_MAX;
|
|
|
|
|
stats->tx_carrier_errors = UINT64_MAX;
|
|
|
|
|
stats->tx_fifo_errors = UINT64_MAX;
|
|
|
|
|
stats->tx_heartbeat_errors = UINT64_MAX;
|
|
|
|
|
stats->tx_window_errors = UINT64_MAX;
|
2012-07-25 22:51:05 +02:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
2013-05-21 17:49:54 +09:00
|
|
|
|
#else
|
|
|
|
|
/* XXXnotyet */
|
|
|
|
|
memset(stats, 0, sizeof(*stats));
|
|
|
|
|
return 0;
|
|
|
|
|
#endif
|
2012-07-25 22:51:05 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static uint32_t
|
|
|
|
|
netdev_bsd_parse_media(int media)
|
|
|
|
|
{
|
|
|
|
|
uint32_t supported = 0;
|
|
|
|
|
bool half_duplex = media & IFM_HDX ? true : false;
|
|
|
|
|
|
|
|
|
|
switch (IFM_SUBTYPE(media)) {
|
|
|
|
|
case IFM_10_2:
|
|
|
|
|
case IFM_10_5:
|
|
|
|
|
case IFM_10_STP:
|
|
|
|
|
case IFM_10_T:
|
|
|
|
|
supported |= half_duplex ? NETDEV_F_10MB_HD : NETDEV_F_10MB_FD;
|
|
|
|
|
supported |= NETDEV_F_COPPER;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case IFM_10_FL:
|
|
|
|
|
supported |= half_duplex ? NETDEV_F_10MB_HD : NETDEV_F_10MB_FD;
|
|
|
|
|
supported |= NETDEV_F_FIBER;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case IFM_100_T2:
|
|
|
|
|
case IFM_100_T4:
|
|
|
|
|
case IFM_100_TX:
|
|
|
|
|
case IFM_100_VG:
|
|
|
|
|
supported |= half_duplex ? NETDEV_F_100MB_HD : NETDEV_F_100MB_FD;
|
|
|
|
|
supported |= NETDEV_F_COPPER;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case IFM_100_FX:
|
|
|
|
|
supported |= half_duplex ? NETDEV_F_100MB_HD : NETDEV_F_100MB_FD;
|
|
|
|
|
supported |= NETDEV_F_FIBER;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case IFM_1000_CX:
|
|
|
|
|
case IFM_1000_T:
|
|
|
|
|
supported |= half_duplex ? NETDEV_F_1GB_HD : NETDEV_F_1GB_FD;
|
|
|
|
|
supported |= NETDEV_F_COPPER;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case IFM_1000_LX:
|
|
|
|
|
case IFM_1000_SX:
|
|
|
|
|
supported |= half_duplex ? NETDEV_F_1GB_HD : NETDEV_F_1GB_FD;
|
|
|
|
|
supported |= NETDEV_F_FIBER;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case IFM_10G_CX4:
|
|
|
|
|
supported |= NETDEV_F_10GB_FD;
|
|
|
|
|
supported |= NETDEV_F_COPPER;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case IFM_10G_LR:
|
|
|
|
|
case IFM_10G_SR:
|
|
|
|
|
supported |= NETDEV_F_10GB_FD;
|
|
|
|
|
supported |= NETDEV_F_FIBER;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (IFM_SUBTYPE(media) == IFM_AUTO) {
|
|
|
|
|
supported |= NETDEV_F_AUTONEG;
|
|
|
|
|
}
|
|
|
|
|
/*
|
|
|
|
|
if (media & IFM_ETH_FMASK) {
|
|
|
|
|
supported |= NETDEV_F_PAUSE;
|
|
|
|
|
}
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
return supported;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Stores the features supported by 'netdev' into each of '*current',
|
|
|
|
|
* '*advertised', '*supported', and '*peer' that are non-null. Each value is a
|
|
|
|
|
* bitmap of "enum ofp_port_features" bits, in host byte order. Returns 0 if
|
|
|
|
|
* successful, otherwise a positive errno value. On failure, all of the
|
|
|
|
|
* passed-in values are set to 0.
|
|
|
|
|
*/
|
|
|
|
|
static int
|
|
|
|
|
netdev_bsd_get_features(const struct netdev *netdev,
|
2013-05-10 16:23:03 -04:00
|
|
|
|
enum netdev_features *current, uint32_t *advertised,
|
|
|
|
|
enum netdev_features *supported, uint32_t *peer)
|
2012-07-25 22:51:05 +02:00
|
|
|
|
{
|
|
|
|
|
struct ifmediareq ifmr;
|
|
|
|
|
int *media_list;
|
|
|
|
|
int i;
|
|
|
|
|
int error;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* XXX Look into SIOCGIFCAP instead of SIOCGIFMEDIA */
|
|
|
|
|
|
|
|
|
|
memset(&ifmr, 0, sizeof(ifmr));
|
|
|
|
|
strncpy(ifmr.ifm_name, netdev_get_name(netdev), sizeof ifmr.ifm_name);
|
|
|
|
|
|
|
|
|
|
/* We make two SIOCGIFMEDIA ioctl calls. The first to determine the
|
|
|
|
|
* number of supported modes, and a second with a buffer to retrieve
|
|
|
|
|
* them. */
|
|
|
|
|
if (ioctl(af_inet_sock, SIOCGIFMEDIA, &ifmr) == -1) {
|
|
|
|
|
VLOG_DBG_RL(&rl, "%s: ioctl(SIOCGIFMEDIA) failed: %s",
|
|
|
|
|
netdev_get_name(netdev), strerror(errno));
|
|
|
|
|
return errno;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
media_list = xcalloc(ifmr.ifm_count, sizeof(int));
|
|
|
|
|
ifmr.ifm_ulist = media_list;
|
|
|
|
|
|
2013-04-22 22:19:59 +09:00
|
|
|
|
if (IFM_TYPE(ifmr.ifm_current) != IFM_ETHER) {
|
2012-07-25 22:51:05 +02:00
|
|
|
|
VLOG_DBG_RL(&rl, "%s: doesn't appear to be ethernet",
|
|
|
|
|
netdev_get_name(netdev));
|
|
|
|
|
error = EINVAL;
|
|
|
|
|
goto cleanup;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (ioctl(af_inet_sock, SIOCGIFMEDIA, &ifmr) == -1) {
|
|
|
|
|
VLOG_DBG_RL(&rl, "%s: ioctl(SIOCGIFMEDIA) failed: %s",
|
|
|
|
|
netdev_get_name(netdev), strerror(errno));
|
|
|
|
|
error = errno;
|
|
|
|
|
goto cleanup;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Current settings. */
|
|
|
|
|
*current = netdev_bsd_parse_media(ifmr.ifm_active);
|
|
|
|
|
|
|
|
|
|
/* Advertised features. */
|
|
|
|
|
*advertised = netdev_bsd_parse_media(ifmr.ifm_current);
|
|
|
|
|
|
|
|
|
|
/* Supported features. */
|
|
|
|
|
*supported = 0;
|
|
|
|
|
for (i = 0; i < ifmr.ifm_count; i++) {
|
|
|
|
|
*supported |= netdev_bsd_parse_media(ifmr.ifm_ulist[i]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Peer advertisements. */
|
|
|
|
|
*peer = 0; /* XXX */
|
|
|
|
|
|
|
|
|
|
error = 0;
|
|
|
|
|
cleanup:
|
|
|
|
|
free(media_list);
|
|
|
|
|
return error;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* If 'netdev' has an assigned IPv4 address, sets '*in4' to that address (if
|
|
|
|
|
* 'in4' is non-null) and returns true. Otherwise, returns false.
|
|
|
|
|
*/
|
|
|
|
|
static int
|
|
|
|
|
netdev_bsd_get_in4(const struct netdev *netdev_, struct in_addr *in4,
|
|
|
|
|
struct in_addr *netmask)
|
|
|
|
|
{
|
2013-03-15 15:54:36 -07:00
|
|
|
|
struct netdev_bsd *netdev = netdev_bsd_cast(netdev_);
|
2012-07-25 22:51:05 +02:00
|
|
|
|
|
2013-03-15 15:54:36 -07:00
|
|
|
|
if (!(netdev->cache_valid & VALID_IN4)) {
|
2012-07-25 22:51:05 +02:00
|
|
|
|
const struct sockaddr_in *sin;
|
|
|
|
|
struct ifreq ifr;
|
|
|
|
|
int error;
|
|
|
|
|
|
|
|
|
|
ifr.ifr_addr.sa_family = AF_INET;
|
2013-05-21 17:49:55 +09:00
|
|
|
|
error = netdev_bsd_do_ioctl(netdev_get_kernel_name(netdev_), &ifr,
|
2013-05-10 16:23:03 -04:00
|
|
|
|
SIOCGIFADDR, "SIOCGIFADDR");
|
2012-07-25 22:51:05 +02:00
|
|
|
|
if (error) {
|
|
|
|
|
return error;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sin = (struct sockaddr_in *) &ifr.ifr_addr;
|
2013-03-15 15:54:36 -07:00
|
|
|
|
netdev->in4 = sin->sin_addr;
|
|
|
|
|
netdev->cache_valid |= VALID_IN4;
|
2013-05-21 17:49:55 +09:00
|
|
|
|
error = netdev_bsd_do_ioctl(netdev_get_kernel_name(netdev_), &ifr,
|
2013-05-10 16:23:03 -04:00
|
|
|
|
SIOCGIFNETMASK, "SIOCGIFNETMASK");
|
2012-07-25 22:51:05 +02:00
|
|
|
|
if (error) {
|
|
|
|
|
return error;
|
|
|
|
|
}
|
|
|
|
|
*netmask = ((struct sockaddr_in*)&ifr.ifr_addr)->sin_addr;
|
|
|
|
|
}
|
2013-03-15 15:54:36 -07:00
|
|
|
|
*in4 = netdev->in4;
|
2012-07-25 22:51:05 +02:00
|
|
|
|
|
|
|
|
|
return in4->s_addr == INADDR_ANY ? EADDRNOTAVAIL : 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Assigns 'addr' as 'netdev''s IPv4 address and 'mask' as its netmask. If
|
|
|
|
|
* 'addr' is INADDR_ANY, 'netdev''s IPv4 address is cleared. Returns a
|
|
|
|
|
* positive errno value.
|
|
|
|
|
*/
|
|
|
|
|
static int
|
|
|
|
|
netdev_bsd_set_in4(struct netdev *netdev_, struct in_addr addr,
|
2013-05-10 16:23:03 -04:00
|
|
|
|
struct in_addr mask)
|
2012-07-25 22:51:05 +02:00
|
|
|
|
{
|
2013-03-15 15:54:36 -07:00
|
|
|
|
struct netdev_bsd *netdev = netdev_bsd_cast(netdev_);
|
2012-07-25 22:51:05 +02:00
|
|
|
|
int error;
|
|
|
|
|
|
|
|
|
|
error = do_set_addr(netdev_, SIOCSIFADDR, "SIOCSIFADDR", addr);
|
|
|
|
|
if (!error) {
|
2013-03-15 15:54:36 -07:00
|
|
|
|
netdev->cache_valid |= VALID_IN4;
|
|
|
|
|
netdev->in4 = addr;
|
2012-07-25 22:51:05 +02:00
|
|
|
|
if (addr.s_addr != INADDR_ANY) {
|
|
|
|
|
error = do_set_addr(netdev_, SIOCSIFNETMASK,
|
|
|
|
|
"SIOCSIFNETMASK", mask);
|
|
|
|
|
}
|
2013-03-15 15:54:36 -07:00
|
|
|
|
netdev_bsd_changed(netdev);
|
2012-07-25 22:51:05 +02:00
|
|
|
|
}
|
|
|
|
|
return error;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
|
netdev_bsd_get_in6(const struct netdev *netdev_, struct in6_addr *in6)
|
|
|
|
|
{
|
2013-03-15 15:54:36 -07:00
|
|
|
|
struct netdev_bsd *netdev = netdev_bsd_cast(netdev_);
|
|
|
|
|
if (!(netdev->cache_valid & VALID_IN6)) {
|
2012-07-25 22:51:05 +02:00
|
|
|
|
struct ifaddrs *ifa, *head;
|
|
|
|
|
struct sockaddr_in6 *sin6;
|
|
|
|
|
const char *netdev_name = netdev_get_name(netdev_);
|
|
|
|
|
|
|
|
|
|
if (getifaddrs(&head) != 0) {
|
|
|
|
|
VLOG_ERR("getifaddrs on %s device failed: %s", netdev_name,
|
|
|
|
|
strerror(errno));
|
|
|
|
|
return errno;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (ifa = head; ifa; ifa = ifa->ifa_next) {
|
|
|
|
|
if (ifa->ifa_addr->sa_family == AF_INET6 &&
|
|
|
|
|
!strcmp(ifa->ifa_name, netdev_name)) {
|
|
|
|
|
sin6 = (struct sockaddr_in6 *)ifa->ifa_addr;
|
|
|
|
|
if (sin6) {
|
2013-03-15 15:54:36 -07:00
|
|
|
|
memcpy(&netdev->in6, &sin6->sin6_addr, sin6->sin6_len);
|
|
|
|
|
netdev->cache_valid |= VALID_IN6;
|
|
|
|
|
*in6 = netdev->in6;
|
2012-07-25 22:51:05 +02:00
|
|
|
|
freeifaddrs(head);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return EADDRNOTAVAIL;
|
|
|
|
|
}
|
2013-03-15 15:54:36 -07:00
|
|
|
|
*in6 = netdev->in6;
|
2012-07-25 22:51:05 +02:00
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
make_in4_sockaddr(struct sockaddr *sa, struct in_addr addr)
|
|
|
|
|
{
|
|
|
|
|
struct sockaddr_in sin;
|
|
|
|
|
memset(&sin, 0, sizeof sin);
|
|
|
|
|
sin.sin_family = AF_INET;
|
|
|
|
|
sin.sin_addr = addr;
|
|
|
|
|
sin.sin_port = 0;
|
|
|
|
|
|
|
|
|
|
memset(sa, 0, sizeof *sa);
|
|
|
|
|
memcpy(sa, &sin, sizeof sin);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
|
do_set_addr(struct netdev *netdev,
|
|
|
|
|
int ioctl_nr, const char *ioctl_name, struct in_addr addr)
|
|
|
|
|
{
|
|
|
|
|
struct ifreq ifr;
|
|
|
|
|
make_in4_sockaddr(&ifr.ifr_addr, addr);
|
2013-05-21 17:49:55 +09:00
|
|
|
|
return netdev_bsd_do_ioctl(netdev_get_kernel_name(netdev), &ifr, ioctl_nr,
|
|
|
|
|
ioctl_name);
|
2012-07-25 22:51:05 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
|
nd_to_iff_flags(enum netdev_flags nd)
|
|
|
|
|
{
|
|
|
|
|
int iff = 0;
|
|
|
|
|
if (nd & NETDEV_UP) {
|
|
|
|
|
iff |= IFF_UP;
|
|
|
|
|
}
|
|
|
|
|
if (nd & NETDEV_PROMISC) {
|
|
|
|
|
iff |= IFF_PROMISC;
|
2013-05-21 17:49:54 +09:00
|
|
|
|
#if defined(IFF_PPROMISC)
|
2012-07-25 22:51:05 +02:00
|
|
|
|
iff |= IFF_PPROMISC;
|
2013-05-21 17:49:54 +09:00
|
|
|
|
#endif
|
2012-07-25 22:51:05 +02:00
|
|
|
|
}
|
|
|
|
|
return iff;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
|
iff_to_nd_flags(int iff)
|
|
|
|
|
{
|
|
|
|
|
enum netdev_flags nd = 0;
|
|
|
|
|
if (iff & IFF_UP) {
|
|
|
|
|
nd |= NETDEV_UP;
|
|
|
|
|
}
|
|
|
|
|
if (iff & IFF_PROMISC) {
|
|
|
|
|
nd |= NETDEV_PROMISC;
|
|
|
|
|
}
|
|
|
|
|
return nd;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int
|
2013-03-15 15:54:36 -07:00
|
|
|
|
netdev_bsd_update_flags(struct netdev *netdev_, enum netdev_flags off,
|
2013-05-10 16:23:03 -04:00
|
|
|
|
enum netdev_flags on, enum netdev_flags *old_flagsp)
|
2012-07-25 22:51:05 +02:00
|
|
|
|
{
|
2013-03-15 15:54:36 -07:00
|
|
|
|
struct netdev_bsd *netdev = netdev_bsd_cast(netdev_);
|
2012-07-25 22:51:05 +02:00
|
|
|
|
int old_flags, new_flags;
|
|
|
|
|
int error;
|
|
|
|
|
|
2013-03-15 15:54:36 -07:00
|
|
|
|
error = get_flags(netdev_, &old_flags);
|
2012-07-25 22:51:05 +02:00
|
|
|
|
if (!error) {
|
|
|
|
|
*old_flagsp = iff_to_nd_flags(old_flags);
|
|
|
|
|
new_flags = (old_flags & ~nd_to_iff_flags(off)) | nd_to_iff_flags(on);
|
|
|
|
|
if (new_flags != old_flags) {
|
2013-05-21 17:49:55 +09:00
|
|
|
|
error = set_flags(netdev_get_kernel_name(netdev_), new_flags);
|
2013-03-15 15:54:36 -07:00
|
|
|
|
netdev_bsd_changed(netdev);
|
2012-07-25 22:51:05 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return error;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static unsigned int
|
|
|
|
|
netdev_bsd_change_seq(const struct netdev *netdev)
|
|
|
|
|
{
|
2013-03-15 15:54:36 -07:00
|
|
|
|
return netdev_bsd_cast(netdev)->change_seq;
|
2012-07-25 22:51:05 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const struct netdev_class netdev_bsd_class = {
|
|
|
|
|
"system",
|
|
|
|
|
|
|
|
|
|
netdev_bsd_init,
|
|
|
|
|
netdev_bsd_run,
|
|
|
|
|
netdev_bsd_wait,
|
|
|
|
|
netdev_bsd_create_system,
|
|
|
|
|
netdev_bsd_destroy,
|
|
|
|
|
NULL, /* get_config */
|
|
|
|
|
NULL, /* set_config */
|
2013-01-16 09:57:52 -05:00
|
|
|
|
NULL, /* get_tunnel_config */
|
2012-07-25 22:51:05 +02:00
|
|
|
|
|
2013-05-10 14:39:19 -07:00
|
|
|
|
netdev_bsd_rx_open,
|
2012-07-25 22:51:05 +02:00
|
|
|
|
|
|
|
|
|
netdev_bsd_send,
|
|
|
|
|
netdev_bsd_send_wait,
|
|
|
|
|
|
|
|
|
|
netdev_bsd_set_etheraddr,
|
|
|
|
|
netdev_bsd_get_etheraddr,
|
|
|
|
|
netdev_bsd_get_mtu,
|
|
|
|
|
NULL, /* set_mtu */
|
|
|
|
|
netdev_bsd_get_ifindex,
|
|
|
|
|
netdev_bsd_get_carrier,
|
|
|
|
|
NULL, /* get_carrier_resets */
|
|
|
|
|
NULL, /* set_miimon_interval */
|
|
|
|
|
netdev_bsd_get_stats,
|
|
|
|
|
NULL, /* set_stats */
|
|
|
|
|
|
|
|
|
|
netdev_bsd_get_features,
|
|
|
|
|
NULL, /* set_advertisement */
|
|
|
|
|
NULL, /* set_policing */
|
|
|
|
|
NULL, /* get_qos_type */
|
|
|
|
|
NULL, /* get_qos_capabilities */
|
|
|
|
|
NULL, /* get_qos */
|
|
|
|
|
NULL, /* set_qos */
|
|
|
|
|
NULL, /* get_queue */
|
|
|
|
|
NULL, /* set_queue */
|
|
|
|
|
NULL, /* delete_queue */
|
|
|
|
|
NULL, /* get_queue_stats */
|
|
|
|
|
NULL, /* dump_queue */
|
|
|
|
|
NULL, /* dump_queue_stats */
|
|
|
|
|
|
|
|
|
|
netdev_bsd_get_in4,
|
|
|
|
|
netdev_bsd_set_in4,
|
|
|
|
|
netdev_bsd_get_in6,
|
|
|
|
|
NULL, /* add_router */
|
|
|
|
|
NULL, /* get_next_hop */
|
2012-12-16 16:42:17 -08:00
|
|
|
|
NULL, /* get_status */
|
2012-07-25 22:51:05 +02:00
|
|
|
|
NULL, /* arp_lookup */
|
|
|
|
|
|
|
|
|
|
netdev_bsd_update_flags,
|
|
|
|
|
|
|
|
|
|
netdev_bsd_change_seq
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const struct netdev_class netdev_tap_class = {
|
|
|
|
|
"tap",
|
|
|
|
|
|
|
|
|
|
netdev_bsd_init,
|
|
|
|
|
netdev_bsd_run,
|
|
|
|
|
netdev_bsd_wait,
|
|
|
|
|
netdev_bsd_create_tap,
|
|
|
|
|
netdev_bsd_destroy,
|
|
|
|
|
NULL, /* get_config */
|
|
|
|
|
NULL, /* set_config */
|
2013-01-16 09:57:52 -05:00
|
|
|
|
NULL, /* get_tunnel_config */
|
2012-07-25 22:51:05 +02:00
|
|
|
|
|
2013-05-10 14:39:19 -07:00
|
|
|
|
netdev_bsd_rx_open,
|
2012-07-25 22:51:05 +02:00
|
|
|
|
|
|
|
|
|
netdev_bsd_send,
|
|
|
|
|
netdev_bsd_send_wait,
|
|
|
|
|
|
|
|
|
|
netdev_bsd_set_etheraddr,
|
|
|
|
|
netdev_bsd_get_etheraddr,
|
|
|
|
|
netdev_bsd_get_mtu,
|
|
|
|
|
NULL, /* set_mtu */
|
|
|
|
|
netdev_bsd_get_ifindex,
|
|
|
|
|
netdev_bsd_get_carrier,
|
|
|
|
|
NULL, /* get_carrier_resets */
|
|
|
|
|
NULL, /* set_miimon_interval */
|
|
|
|
|
netdev_bsd_get_stats,
|
|
|
|
|
NULL, /* set_stats */
|
|
|
|
|
|
|
|
|
|
netdev_bsd_get_features,
|
|
|
|
|
NULL, /* set_advertisement */
|
|
|
|
|
NULL, /* set_policing */
|
|
|
|
|
NULL, /* get_qos_type */
|
|
|
|
|
NULL, /* get_qos_capabilities */
|
|
|
|
|
NULL, /* get_qos */
|
|
|
|
|
NULL, /* set_qos */
|
|
|
|
|
NULL, /* get_queue */
|
|
|
|
|
NULL, /* set_queue */
|
|
|
|
|
NULL, /* delete_queue */
|
|
|
|
|
NULL, /* get_queue_stats */
|
|
|
|
|
NULL, /* dump_queue */
|
|
|
|
|
NULL, /* dump_queue_stats */
|
|
|
|
|
|
|
|
|
|
netdev_bsd_get_in4,
|
|
|
|
|
netdev_bsd_set_in4,
|
|
|
|
|
netdev_bsd_get_in6,
|
|
|
|
|
NULL, /* add_router */
|
|
|
|
|
NULL, /* get_next_hop */
|
2012-12-16 16:42:17 -08:00
|
|
|
|
NULL, /* get_status */
|
2012-07-25 22:51:05 +02:00
|
|
|
|
NULL, /* arp_lookup */
|
|
|
|
|
|
|
|
|
|
netdev_bsd_update_flags,
|
|
|
|
|
|
|
|
|
|
netdev_bsd_change_seq
|
|
|
|
|
};
|
2013-05-10 14:39:19 -07:00
|
|
|
|
|
|
|
|
|
static const struct netdev_rx_class netdev_rx_bsd_class = {
|
|
|
|
|
netdev_rx_bsd_destroy,
|
|
|
|
|
netdev_rx_bsd_recv,
|
|
|
|
|
netdev_rx_bsd_wait,
|
|
|
|
|
netdev_rx_bsd_drain,
|
|
|
|
|
};
|
2012-07-25 22:51:05 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
destroy_tap(int fd, const char *name)
|
|
|
|
|
{
|
|
|
|
|
struct ifreq ifr;
|
|
|
|
|
|
|
|
|
|
close(fd);
|
|
|
|
|
strcpy(ifr.ifr_name, name);
|
|
|
|
|
/* XXX What to do if this call fails? */
|
|
|
|
|
ioctl(af_inet_sock, SIOCIFDESTROY, &ifr);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int
|
2013-03-15 15:54:36 -07:00
|
|
|
|
get_flags(const struct netdev *netdev, int *flags)
|
2012-07-25 22:51:05 +02:00
|
|
|
|
{
|
|
|
|
|
struct ifreq ifr;
|
|
|
|
|
int error;
|
|
|
|
|
|
2013-05-21 17:49:55 +09:00
|
|
|
|
error = netdev_bsd_do_ioctl(netdev_get_kernel_name(netdev), &ifr,
|
2013-03-15 15:54:36 -07:00
|
|
|
|
SIOCGIFFLAGS, "SIOCGIFFLAGS");
|
2012-07-25 22:51:05 +02:00
|
|
|
|
|
2013-05-21 17:49:54 +09:00
|
|
|
|
*flags = ifr_get_flags(&ifr);
|
2012-07-25 22:51:05 +02:00
|
|
|
|
|
|
|
|
|
return error;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int
|
2013-05-10 08:55:25 -07:00
|
|
|
|
set_flags(const char *name, int flags)
|
2012-07-25 22:51:05 +02:00
|
|
|
|
{
|
|
|
|
|
struct ifreq ifr;
|
|
|
|
|
|
2013-05-21 17:49:54 +09:00
|
|
|
|
ifr_set_flags(&ifr, flags);
|
2012-07-25 22:51:05 +02:00
|
|
|
|
|
2013-05-10 08:55:25 -07:00
|
|
|
|
return netdev_bsd_do_ioctl(name, &ifr, SIOCSIFFLAGS, "SIOCSIFFLAGS");
|
2012-07-25 22:51:05 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
|
get_ifindex(const struct netdev *netdev_, int *ifindexp)
|
|
|
|
|
{
|
2013-03-15 15:54:36 -07:00
|
|
|
|
struct netdev_bsd *netdev = netdev_bsd_cast(netdev_);
|
2012-07-25 22:51:05 +02:00
|
|
|
|
*ifindexp = 0;
|
2013-03-15 15:54:36 -07:00
|
|
|
|
if (!(netdev->cache_valid & VALID_IFINDEX)) {
|
2012-07-25 22:51:05 +02:00
|
|
|
|
int ifindex = if_nametoindex(netdev_get_name(netdev_));
|
|
|
|
|
if (ifindex <= 0) {
|
|
|
|
|
return errno;
|
|
|
|
|
}
|
2013-03-15 15:54:36 -07:00
|
|
|
|
netdev->cache_valid |= VALID_IFINDEX;
|
|
|
|
|
netdev->ifindex = ifindex;
|
2012-07-25 22:51:05 +02:00
|
|
|
|
}
|
2013-03-15 15:54:36 -07:00
|
|
|
|
*ifindexp = netdev->ifindex;
|
2012-07-25 22:51:05 +02:00
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
|
get_etheraddr(const char *netdev_name, uint8_t ea[ETH_ADDR_LEN])
|
|
|
|
|
{
|
|
|
|
|
struct ifaddrs *head;
|
|
|
|
|
struct ifaddrs *ifa;
|
|
|
|
|
struct sockaddr_dl *sdl;
|
|
|
|
|
|
|
|
|
|
if (getifaddrs(&head) != 0) {
|
|
|
|
|
VLOG_ERR("getifaddrs on %s device failed: %s", netdev_name,
|
|
|
|
|
strerror(errno));
|
|
|
|
|
return errno;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (ifa = head; ifa; ifa = ifa->ifa_next) {
|
|
|
|
|
if (ifa->ifa_addr->sa_family == AF_LINK) {
|
|
|
|
|
if (!strcmp(ifa->ifa_name, netdev_name)) {
|
|
|
|
|
sdl = (struct sockaddr_dl *)ifa->ifa_addr;
|
|
|
|
|
if (sdl) {
|
|
|
|
|
memcpy(ea, LLADDR(sdl), sdl->sdl_alen);
|
|
|
|
|
freeifaddrs(head);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
VLOG_ERR("could not find ethernet address for %s device", netdev_name);
|
|
|
|
|
freeifaddrs(head);
|
|
|
|
|
return ENODEV;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int
|
2013-05-21 17:49:54 +09:00
|
|
|
|
set_etheraddr(const char *netdev_name OVS_UNUSED, int hwaddr_family OVS_UNUSED,
|
|
|
|
|
int hwaddr_len OVS_UNUSED,
|
|
|
|
|
const uint8_t mac[ETH_ADDR_LEN] OVS_UNUSED)
|
2012-07-25 22:51:05 +02:00
|
|
|
|
{
|
2013-05-22 20:56:47 -07:00
|
|
|
|
#if defined(__FreeBSD__)
|
2012-07-25 22:51:05 +02:00
|
|
|
|
struct ifreq ifr;
|
|
|
|
|
|
|
|
|
|
memset(&ifr, 0, sizeof ifr);
|
|
|
|
|
strncpy(ifr.ifr_name, netdev_name, sizeof ifr.ifr_name);
|
|
|
|
|
ifr.ifr_addr.sa_family = hwaddr_family;
|
|
|
|
|
ifr.ifr_addr.sa_len = hwaddr_len;
|
|
|
|
|
memcpy(ifr.ifr_addr.sa_data, mac, hwaddr_len);
|
|
|
|
|
if (ioctl(af_inet_sock, SIOCSIFLLADDR, &ifr) < 0) {
|
|
|
|
|
VLOG_ERR("ioctl(SIOCSIFLLADDR) on %s device failed: %s",
|
|
|
|
|
netdev_name, strerror(errno));
|
|
|
|
|
return errno;
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
2013-05-22 20:56:47 -07:00
|
|
|
|
#elif defined(__NetBSD__)
|
|
|
|
|
struct if_laddrreq req;
|
|
|
|
|
struct sockaddr_dl *sdl;
|
|
|
|
|
struct sockaddr_storage oldaddr;
|
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* get the old address, add new one, and then remove old one.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
if (hwaddr_len != ETH_ADDR_LEN) {
|
|
|
|
|
/* just to be safe about sockaddr storage size */
|
|
|
|
|
return EOPNOTSUPP;
|
|
|
|
|
}
|
|
|
|
|
memset(&req, 0, sizeof(req));
|
|
|
|
|
strncpy(req.iflr_name, netdev_name, sizeof(req.iflr_name));
|
|
|
|
|
req.addr.ss_len = sizeof(req.addr);
|
|
|
|
|
req.addr.ss_family = hwaddr_family;
|
|
|
|
|
sdl = (struct sockaddr_dl *)&req.addr;
|
|
|
|
|
sdl->sdl_alen = hwaddr_len;
|
|
|
|
|
ret = ioctl(af_link_sock, SIOCGLIFADDR, &req);
|
|
|
|
|
if (ret == -1) {
|
|
|
|
|
return errno;
|
|
|
|
|
}
|
|
|
|
|
if (!memcmp(&sdl->sdl_data[sdl->sdl_nlen], mac, hwaddr_len)) {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
oldaddr = req.addr;
|
|
|
|
|
|
|
|
|
|
memset(&req, 0, sizeof(req));
|
|
|
|
|
strncpy(req.iflr_name, netdev_name, sizeof(req.iflr_name));
|
|
|
|
|
req.flags = IFLR_ACTIVE;
|
|
|
|
|
sdl = (struct sockaddr_dl *)&req.addr;
|
|
|
|
|
sdl->sdl_len = offsetof(struct sockaddr_dl, sdl_data) + hwaddr_len;
|
|
|
|
|
sdl->sdl_alen = hwaddr_len;
|
|
|
|
|
sdl->sdl_family = hwaddr_family;
|
|
|
|
|
memcpy(sdl->sdl_data, mac, hwaddr_len);
|
|
|
|
|
ret = ioctl(af_link_sock, SIOCALIFADDR, &req);
|
|
|
|
|
if (ret == -1) {
|
|
|
|
|
return errno;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
memset(&req, 0, sizeof(req));
|
|
|
|
|
strncpy(req.iflr_name, netdev_name, sizeof(req.iflr_name));
|
|
|
|
|
req.addr = oldaddr;
|
|
|
|
|
ret = ioctl(af_link_sock, SIOCDLIFADDR, &req);
|
|
|
|
|
if (ret == -1) {
|
|
|
|
|
return errno;
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
#else
|
|
|
|
|
#error not implemented
|
2013-05-21 17:49:54 +09:00
|
|
|
|
#endif
|
2012-07-25 22:51:05 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int
|
2013-05-10 08:55:25 -07:00
|
|
|
|
netdev_bsd_do_ioctl(const char *name, struct ifreq *ifr, unsigned long cmd,
|
|
|
|
|
const char *cmd_name)
|
2012-07-25 22:51:05 +02:00
|
|
|
|
{
|
2013-05-10 08:55:25 -07:00
|
|
|
|
strncpy(ifr->ifr_name, name, sizeof ifr->ifr_name);
|
2012-07-25 22:51:05 +02:00
|
|
|
|
if (ioctl(af_inet_sock, cmd, ifr) == -1) {
|
2013-05-10 08:55:25 -07:00
|
|
|
|
VLOG_DBG_RL(&rl, "%s: ioctl(%s) failed: %s", name, cmd_name,
|
|
|
|
|
strerror(errno));
|
2012-07-25 22:51:05 +02:00
|
|
|
|
return errno;
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2013-05-21 17:49:54 +09:00
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
|
ifr_get_flags(const struct ifreq *ifr)
|
|
|
|
|
{
|
|
|
|
|
#ifdef HAVE_STRUCT_IFREQ_IFR_FLAGSHIGH
|
|
|
|
|
return (ifr.ifr_flagshigh << 16) | ifr.ifr_flags;
|
|
|
|
|
#else
|
|
|
|
|
return ifr.ifr_flags;
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
ifr_set_flags(struct ifreq *ifr, int flags)
|
|
|
|
|
{
|
|
|
|
|
ifr->ifr_flags = flags;
|
|
|
|
|
#ifdef HAVE_STRUCT_IFREQ_IFR_FLAGSHIGH
|
|
|
|
|
ifr->ifr_flagshigh = flags >> 16;
|
|
|
|
|
#endif
|
|
|
|
|
}
|