From: Ben Pfaff Date: Mon, 14 Jul 2008 20:03:19 +0000 (-0700) Subject: netdev: Add argument to netdev_open() to specify Ethernet type to capture. X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e55d52c988aa9b65c8273591ee29676b4f915313;p=openvswitch netdev: Add argument to netdev_open() to specify Ethernet type to capture. This is needed by the controller, which wants to listen only for OpenFlow discovery BPDUs on its network devices. Also, update all existing callers. --- diff --git a/include/netdev.h b/include/netdev.h index 06476e2e..57b7cbd4 100644 --- a/include/netdev.h +++ b/include/netdev.h @@ -52,8 +52,14 @@ enum netdev_flags { NETDEV_PROMISC = 0x0002 /* Promiscuous mode? */ }; +enum netdev_pseudo_ethertype { + NETDEV_ETH_TYPE_NONE = -128, /* Receive no frames. */ + NETDEV_ETH_TYPE_ANY, /* Receive all frames. */ + NETDEV_ETH_TYPE_802_2 /* Receive all IEEE 802.2 frames. */ +}; + struct netdev; -int netdev_open(const char *name, struct netdev **); +int netdev_open(const char *name, int ethertype, struct netdev **); void netdev_close(struct netdev *); int netdev_recv(struct netdev *, struct buffer *); void netdev_recv_wait(struct netdev *); diff --git a/lib/netdev.c b/lib/netdev.c index 43592393..a96f782c 100644 --- a/lib/netdev.c +++ b/lib/netdev.c @@ -209,9 +209,14 @@ do_ethtool(struct netdev *netdev) /* Opens the network device named 'name' (e.g. "eth0") and returns zero if * successful, otherwise a positive errno value. On success, sets '*netdev' - * to the new network device, otherwise to null. */ + * to the new network device, otherwise to null. + * + * 'ethertype' may be a 16-bit Ethernet protocol value in host byte order to + * capture frames of that type received on the device. It may also be one of + * the 'enum netdev_pseudo_ethertype' values to receive frames in one of those + * categories. */ int -netdev_open(const char *name, struct netdev **netdev_) +netdev_open(const char *name, int ethertype, struct netdev **netdev_) { int fd; struct sockaddr sa; @@ -234,7 +239,11 @@ netdev_open(const char *name, struct netdev **netdev_) * We have to use SOCK_PACKET, despite its deprecation, because only * SOCK_PACKET lets us set the hardware source address of outgoing * packets. */ - fd = socket(PF_PACKET, SOCK_PACKET, htons(ETH_P_ALL)); + fd = socket(PF_PACKET, SOCK_PACKET, + htons(ethertype == NETDEV_ETH_TYPE_NONE ? 0 + : ethertype == NETDEV_ETH_TYPE_ANY ? ETH_P_ALL + : ethertype == NETDEV_ETH_TYPE_802_2 ? ETH_P_802_2 + : ethertype)); if (fd < 0) { return errno; } diff --git a/secchan/secchan.c b/secchan/secchan.c index 8c59b8ae..80ba9870 100644 --- a/secchan/secchan.c +++ b/secchan/secchan.c @@ -166,7 +166,7 @@ main(int argc, char *argv[]) } snprintf(of_name, sizeof of_name, "of%s", nl_name + 3); - retval = netdev_open(of_name, &of_device); + retval = netdev_open(of_name, NETDEV_ETH_TYPE_NONE, &of_device); if (!retval) { enum netdev_flags flags; retval = netdev_get_flags(of_device, &flags); diff --git a/switch/datapath.c b/switch/datapath.c index a196bead..a7e5d938 100644 --- a/switch/datapath.c +++ b/switch/datapath.c @@ -215,7 +215,7 @@ dp_add_port(struct datapath *dp, const char *name) struct sw_port *p; int error; - error = netdev_open(name, &netdev); + error = netdev_open(name, NETDEV_ETH_TYPE_ANY, &netdev); if (error) { return error; }