X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=lib%2Fnetdev-bsd.c;h=3eb29ea6a2d35284cf3e0685fe3b95051fa1cdd7;hb=2bd135b5f88b1633042fe4dc99119bfbe14bd73e;hp=50fb5207b2bf7840491e3ac70cbe2bf704ee91b8;hpb=b72d8dc2dab67d020270ef950158ed05626f0ab3;p=sliver-openvswitch.git diff --git a/lib/netdev-bsd.c b/lib/netdev-bsd.c index 50fb5207b..3eb29ea6a 100644 --- a/lib/netdev-bsd.c +++ b/lib/netdev-bsd.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011 Gaetano Catalli. + * Copyright (c) 2011, 2013 Gaetano Catalli. * Copyright (c) 2013 YAMAMOTO Takashi. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -42,6 +42,8 @@ #include #if defined(__NetBSD__) #include +#include +#include #endif #include "rtbsd.h" @@ -291,7 +293,7 @@ netdev_bsd_construct_system(struct netdev *netdev_) return error; } - ovs_mutex_init(&netdev->mutex, PTHREAD_MUTEX_NORMAL); + ovs_mutex_init(&netdev->mutex); netdev->change_seq = 1; netdev->tap_fd = -1; netdev->kernel_name = xstrdup(netdev_->name); @@ -325,7 +327,7 @@ netdev_bsd_construct_tap(struct netdev *netdev_) /* Create a tap device by opening /dev/tap. The TAPGIFNAME ioctl is used * to retrieve the name of the tap device. */ - ovs_mutex_init(&netdev->mutex, PTHREAD_MUTEX_NORMAL); + ovs_mutex_init(&netdev->mutex); netdev->tap_fd = open("/dev/tap", O_RDWR); netdev->change_seq = 1; if (netdev->tap_fd < 0) { @@ -1332,6 +1334,63 @@ netdev_bsd_get_next_hop(const struct in_addr *host OVS_UNUSED, #endif } +static int +netdev_bsd_arp_lookup(const struct netdev *netdev OVS_UNUSED, + ovs_be32 ip OVS_UNUSED, + uint8_t mac[ETH_ADDR_LEN] OVS_UNUSED) +{ +#if defined(__NetBSD__) + const struct rt_msghdr *rtm; + size_t needed; + char *buf; + const char *cp; + const char *ep; + int mib[6]; + int error; + + buf = NULL; + mib[0] = CTL_NET; + mib[1] = PF_ROUTE; + mib[2] = 0; + mib[3] = AF_INET; + mib[4] = NET_RT_FLAGS; + mib[5] = RTF_LLINFO; + if (sysctl(mib, 6, NULL, &needed, NULL, 0) == -1) { + error = errno; + goto error; + } + buf = xmalloc(needed); + if (sysctl(mib, 6, buf, &needed, NULL, 0) == -1) { + error = errno; + goto error; + } + ep = buf + needed; + for (cp = buf; cp < ep; cp += rtm->rtm_msglen) { + const struct sockaddr_inarp *sina; + const struct sockaddr_dl *sdl; + + rtm = (const void *)cp; + sina = (const void *)(rtm + 1); + if (ip != sina->sin_addr.s_addr) { + continue; + } + sdl = (const void *) + ((const char *)(const void *)sina + RT_ROUNDUP(sina->sin_len)); + if (sdl->sdl_alen == ETH_ADDR_LEN) { + memcpy(mac, &sdl->sdl_data[sdl->sdl_nlen], ETH_ADDR_LEN); + error = 0; + goto error; + } + } + error = ENXIO; +error: + free(buf); + return error; +#else + return EOPNOTSUPP; +#endif +} + static void make_in4_sockaddr(struct sockaddr *sa, struct in_addr addr) { @@ -1369,6 +1428,9 @@ nd_to_iff_flags(enum netdev_flags nd) iff |= IFF_PPROMISC; #endif } + if (nd & NETDEV_LOOPBACK) { + iff |= IFF_LOOPBACK; + } return iff; } @@ -1382,6 +1444,9 @@ iff_to_nd_flags(int iff) if (iff & IFF_PROMISC) { nd |= NETDEV_PROMISC; } + if (iff & IFF_LOOPBACK) { + nd |= NETDEV_LOOPBACK; + } return nd; } @@ -1451,7 +1516,9 @@ const struct netdev_class netdev_bsd_class = { NULL, /* set_queue */ NULL, /* delete_queue */ NULL, /* get_queue_stats */ - NULL, /* dump_queue */ + NULL, /* queue_dump_start */ + NULL, /* queue_dump_next */ + NULL, /* queue_dump_done */ NULL, /* dump_queue_stats */ netdev_bsd_get_in4, @@ -1460,7 +1527,7 @@ const struct netdev_class netdev_bsd_class = { NULL, /* add_router */ netdev_bsd_get_next_hop, NULL, /* get_status */ - NULL, /* arp_lookup */ + netdev_bsd_arp_lookup, /* arp_lookup */ netdev_bsd_update_flags, @@ -1514,7 +1581,9 @@ const struct netdev_class netdev_tap_class = { NULL, /* set_queue */ NULL, /* delete_queue */ NULL, /* get_queue_stats */ - NULL, /* dump_queue */ + NULL, /* queue_dump_start */ + NULL, /* queue_dump_next */ + NULL, /* queue_dump_done */ NULL, /* dump_queue_stats */ netdev_bsd_get_in4, @@ -1523,7 +1592,7 @@ const struct netdev_class netdev_tap_class = { NULL, /* add_router */ netdev_bsd_get_next_hop, NULL, /* get_status */ - NULL, /* arp_lookup */ + netdev_bsd_arp_lookup, /* arp_lookup */ netdev_bsd_update_flags,