2 * Distributed under the terms of the GNU GPL version 2.
3 * Copyright (c) 2007, 2008 The Board of Trustees of The Leland
4 * Stanford Junior University
7 /* Functions for managing the dp interface/device. */
9 #include <linux/init.h>
10 #include <linux/module.h>
11 #include <linux/if_arp.h>
12 #include <linux/if_bridge.h>
13 #include <linux/if_vlan.h>
15 #include <net/genetlink.h>
17 #include <linux/delay.h>
18 #include <linux/etherdevice.h>
19 #include <linux/kernel.h>
20 #include <linux/kthread.h>
21 #include <linux/mutex.h>
22 #include <linux/rtnetlink.h>
23 #include <linux/rcupdate.h>
24 #include <linux/version.h>
25 #include <linux/ethtool.h>
26 #include <linux/random.h>
27 #include <asm/system.h>
28 #include <linux/netfilter_bridge.h>
29 #include <linux/inetdevice.h>
30 #include <linux/list.h>
31 #include <linux/rculist.h>
32 #include <linux/workqueue.h>
34 #include "openflow-netlink.h"
45 /* Strings to describe the manufacturer, hardware, and software. This data
46 * is queriable through the switch description stats message. */
47 static char mfr_desc[DESC_STR_LEN] = "Nicira Networks";
48 static char hw_desc[DESC_STR_LEN] = "Reference Linux Kernel Module";
49 static char sw_desc[DESC_STR_LEN] = VERSION;
50 static char serial_num[SERIAL_NUM_LEN] = "None";
52 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
53 module_param_string(mfr_desc, mfr_desc, sizeof mfr_desc, 0444);
54 module_param_string(hw_desc, hw_desc, sizeof hw_desc, 0444);
55 module_param_string(sw_desc, sw_desc, sizeof sw_desc, 0444);
56 module_param_string(serial_num, serial_num, sizeof serial_num, 0444);
58 MODULE_PARM(mfr_desc, "s");
59 MODULE_PARM(hw_desc, "s");
60 MODULE_PARM(sw_desc, "s");
61 MODULE_PARM(serial_num, "s");
65 /* Number of milliseconds between runs of the maintenance thread. */
66 #define MAINT_SLEEP_MSECS 1000
68 #define UINT32_MAX 4294967295U
69 #define UINT16_MAX 65535
70 #define MAX(X, Y) ((X) > (Y) ? (X) : (Y))
72 static struct genl_family dp_genl_family;
73 static struct genl_multicast_group mc_group;
75 /* It's hard to imagine wanting more than one datapath, but... */
78 /* Datapaths. Protected on the read side by rcu_read_lock, on the write side
79 * by dp_mutex. dp_mutex is almost completely redundant with genl_mutex
80 * maintained by the Generic Netlink code, but the timeout path needs mutual
83 * It is safe to access the datapath and net_bridge_port structures with just
86 static struct datapath *dps[DP_MAX];
87 DEFINE_MUTEX(dp_mutex);
88 EXPORT_SYMBOL(dp_mutex);
90 static int dp_maint_func(void *data);
91 static int update_port_status(struct net_bridge_port *p);
92 static int send_port_status(struct net_bridge_port *p, uint8_t status);
93 static int dp_genl_openflow_done(struct netlink_callback *);
94 static struct net_bridge_port *new_nbp(struct datapath *,
95 struct net_device *, int port_no);
96 static int del_switch_port(struct net_bridge_port *);
98 /* nla_shrink - reduce amount of space reserved by nla_reserve
99 * @skb: socket buffer from which to recover room
100 * @nla: netlink attribute to adjust
101 * @len: new length of attribute payload
103 * Reduces amount of space reserved by a call to nla_reserve.
105 * No other attributes may be added between calling nla_reserve and this
106 * function, since it will create a hole in the message.
108 void nla_shrink(struct sk_buff *skb, struct nlattr *nla, int len)
110 int delta = nla_total_size(len) - nla_total_size(nla_len(nla));
114 nla->nla_len = nla_attr_size(len);
117 /* Puts a set of openflow headers for a message of the given 'type' into 'skb'.
118 * If 'sender' is nonnull, then it is used as the message's destination. 'dp'
119 * must specify the datapath to use.
121 * '*max_openflow_len' receives the maximum number of bytes that are available
122 * for the embedded OpenFlow message. The caller must call
123 * resize_openflow_skb() to set the actual size of the message to this number
126 * Returns the openflow header if successful, otherwise (if 'skb' is too small)
129 put_openflow_headers(struct datapath *dp, struct sk_buff *skb, uint8_t type,
130 const struct sender *sender, int *max_openflow_len)
132 struct ofp_header *oh;
136 /* Assemble the Generic Netlink wrapper. */
137 if (!genlmsg_put(skb,
138 sender ? sender->pid : 0,
139 sender ? sender->seq : 0,
140 &dp_genl_family, 0, DP_GENL_C_OPENFLOW))
141 return ERR_PTR(-ENOBUFS);
142 if (nla_put_u32(skb, DP_GENL_A_DP_IDX, dp->dp_idx) < 0)
143 return ERR_PTR(-ENOBUFS);
144 openflow_len = (skb_tailroom(skb) - NLA_HDRLEN) & ~(NLA_ALIGNTO - 1);
145 if (openflow_len < sizeof *oh)
146 return ERR_PTR(-ENOBUFS);
147 *max_openflow_len = openflow_len;
148 attr = nla_reserve(skb, DP_GENL_A_OPENFLOW, openflow_len);
151 /* Fill in the header. The caller is responsible for the length. */
153 oh->version = OFP_VERSION;
155 oh->xid = sender ? sender->xid : 0;
160 /* Resizes OpenFlow header 'oh', which must be at the tail end of 'skb', to new
161 * length 'new_length' (in bytes), adjusting pointers and size values as
164 resize_openflow_skb(struct sk_buff *skb,
165 struct ofp_header *oh, size_t new_length)
167 struct nlattr *attr = ((void *) oh) - NLA_HDRLEN;
168 nla_shrink(skb, attr, new_length);
169 oh->length = htons(new_length);
170 nlmsg_end(skb, (struct nlmsghdr *) skb->data);
173 /* Allocates a new skb to contain an OpenFlow message 'openflow_len' bytes in
174 * length. Returns a null pointer if memory is unavailable, otherwise returns
175 * the OpenFlow header and stores a pointer to the skb in '*pskb'.
177 * 'type' is the OpenFlow message type. If 'sender' is nonnull, then it is
178 * used as the message's destination. 'dp' must specify the datapath to
181 alloc_openflow_skb(struct datapath *dp, size_t openflow_len, uint8_t type,
182 const struct sender *sender, struct sk_buff **pskb)
184 struct ofp_header *oh;
187 int max_openflow_len;
189 if ((openflow_len + sizeof(struct ofp_header)) > UINT16_MAX) {
191 printk("alloc_openflow_skb: openflow message too large: %zu\n",
196 genl_len = nlmsg_total_size(GENL_HDRLEN + dp_genl_family.hdrsize);
197 genl_len += nla_total_size(sizeof(uint32_t)); /* DP_GENL_A_DP_IDX */
198 genl_len += nla_total_size(openflow_len); /* DP_GENL_A_OPENFLOW */
199 skb = *pskb = genlmsg_new(genl_len, GFP_ATOMIC);
202 printk("alloc_openflow_skb: genlmsg_new failed\n");
206 oh = put_openflow_headers(dp, skb, type, sender, &max_openflow_len);
207 BUG_ON(!oh || IS_ERR(oh));
208 resize_openflow_skb(skb, oh, openflow_len);
213 /* Sends 'skb' to 'sender' if it is nonnull, otherwise multicasts 'skb' to all
216 send_openflow_skb(struct sk_buff *skb, const struct sender *sender)
219 ? genlmsg_unicast(skb, sender->pid)
220 : genlmsg_multicast(skb, 0, mc_group.id, GFP_ATOMIC));
223 /* Generates a unique datapath id. It incorporates the datapath index
224 * and a hardware address, if available. If not, it generates a random
228 uint64_t gen_datapath_id(uint16_t dp_idx)
232 struct net_device *dev;
234 /* The top 16 bits are used to identify the datapath. The lower 48 bits
235 * use an interface address. */
236 id = (uint64_t)dp_idx << 48;
237 if ((dev = dev_get_by_name(&init_net, "ctl0"))
238 || (dev = dev_get_by_name(&init_net, "eth0"))) {
239 for (i=0; i<ETH_ALEN; i++) {
240 id |= (uint64_t)dev->dev_addr[i] << (8*(ETH_ALEN-1 - i));
244 /* Randomly choose the lower 48 bits if we cannot find an
245 * address and mark the most significant bit to indicate that
246 * this was randomly generated. */
247 uint8_t rand[ETH_ALEN];
248 get_random_bytes(rand, ETH_ALEN);
249 id |= (uint64_t)1 << 63;
250 for (i=0; i<ETH_ALEN; i++) {
251 id |= (uint64_t)rand[i] << (8*(ETH_ALEN-1 - i));
258 /* Creates a new datapath numbered 'dp_idx'. Returns 0 for success or a
259 * negative error code. */
260 static int new_dp(int dp_idx)
265 if (dp_idx < 0 || dp_idx >= DP_MAX)
268 if (!try_module_get(THIS_MODULE))
271 /* Exit early if a datapath with that number already exists. */
278 dp = kzalloc(sizeof *dp, GFP_KERNEL);
282 /* Setup our "of" device */
283 err = dp_dev_setup(dp);
288 dp->id = gen_datapath_id(dp_idx);
289 dp->chain = chain_create(dp);
290 if (dp->chain == NULL)
291 goto err_destroy_dp_dev;
292 INIT_LIST_HEAD(&dp->port_list);
294 dp->local_port = new_nbp(dp, dp->netdev, OFPP_LOCAL);
295 if (IS_ERR(dp->local_port)) {
296 err = PTR_ERR(dp->local_port);
297 goto err_destroy_local_port;
301 dp->miss_send_len = OFP_DEFAULT_MISS_SEND_LEN;
303 dp->dp_task = kthread_run(dp_maint_func, dp, "dp%d", dp_idx);
304 if (IS_ERR(dp->dp_task))
305 goto err_destroy_chain;
311 err_destroy_local_port:
312 del_switch_port(dp->local_port);
314 chain_destroy(dp->chain);
320 module_put(THIS_MODULE);
324 /* Find and return a free port number under 'dp'. */
325 static int find_portno(struct datapath *dp)
328 for (i = 0; i < OFPP_MAX; i++)
329 if (dp->ports[i] == NULL)
334 static struct net_bridge_port *new_nbp(struct datapath *dp,
335 struct net_device *dev, int port_no)
337 struct net_bridge_port *p;
339 if (dev->br_port != NULL)
340 return ERR_PTR(-EBUSY);
342 p = kzalloc(sizeof(*p), GFP_KERNEL);
344 return ERR_PTR(-ENOMEM);
347 dev_set_promiscuity(dev, 1);
352 p->port_no = port_no;
353 spin_lock_init(&p->lock);
354 INIT_WORK(&p->port_task, NULL);
355 if (port_no != OFPP_LOCAL)
356 rcu_assign_pointer(dev->br_port, p);
357 if (port_no < OFPP_MAX)
358 rcu_assign_pointer(dp->ports[port_no], p);
359 list_add_rcu(&p->node, &dp->port_list);
364 int add_switch_port(struct datapath *dp, struct net_device *dev)
366 struct net_bridge_port *p;
369 if (dev->flags & IFF_LOOPBACK || dev->type != ARPHRD_ETHER
373 port_no = find_portno(dp);
377 p = new_nbp(dp, dev, port_no);
381 update_port_status(p);
383 /* Notify the ctlpath that this port has been added */
384 send_port_status(p, OFPPR_ADD);
389 /* Delete 'p' from switch. */
390 static int del_switch_port(struct net_bridge_port *p)
392 /* First drop references to device. */
393 cancel_work_sync(&p->port_task);
395 dev_set_promiscuity(p->dev, -1);
397 list_del_rcu(&p->node);
398 if (p->port_no != OFPP_LOCAL)
399 rcu_assign_pointer(p->dp->ports[p->port_no], NULL);
400 rcu_assign_pointer(p->dev->br_port, NULL);
402 /* Then wait until no one is still using it, and destroy it. */
405 /* Notify the ctlpath that this port no longer exists */
406 send_port_status(p, OFPPR_DELETE);
414 static void del_dp(struct datapath *dp)
416 struct net_bridge_port *p, *n;
418 kthread_stop(dp->dp_task);
420 /* Drop references to DP. */
421 list_for_each_entry_safe (p, n, &dp->port_list, node)
423 rcu_assign_pointer(dps[dp->dp_idx], NULL);
425 /* Kill off local_port dev references from buffered packets that have
426 * associated dst entries. */
430 /* Destroy dp->netdev. (Must follow deleting switch ports since
431 * dp->local_port has a reference to it.) */
434 /* Wait until no longer in use, then destroy it. */
436 chain_destroy(dp->chain);
438 module_put(THIS_MODULE);
441 static int dp_maint_func(void *data)
443 struct datapath *dp = (struct datapath *) data;
445 while (!kthread_should_stop()) {
446 struct net_bridge_port *p;
448 /* Check if port status has changed */
450 list_for_each_entry_rcu (p, &dp->port_list, node)
451 if (update_port_status(p))
452 send_port_status(p, OFPPR_MOD);
455 /* Timeout old entries */
456 chain_timeout(dp->chain);
457 msleep_interruptible(MAINT_SLEEP_MSECS);
464 do_port_input(struct net_bridge_port *p, struct sk_buff *skb)
466 /* Push the Ethernet header back on. */
467 skb_push(skb, ETH_HLEN);
468 fwd_port_input(p->dp->chain, skb, p);
472 * Used as br_handle_frame_hook. (Cannot run bridge at the same time, even on
473 * different set of devices!)
475 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,22)
476 /* Called with rcu_read_lock. */
477 static struct sk_buff *dp_frame_hook(struct net_bridge_port *p,
480 do_port_input(p, skb);
483 #elif LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
484 static int dp_frame_hook(struct net_bridge_port *p, struct sk_buff **pskb)
486 do_port_input(p, *pskb);
490 /* NB: This has only been tested on 2.4.35 */
491 static void dp_frame_hook(struct sk_buff *skb)
493 struct net_bridge_port *p = skb->dev->br_port;
496 do_port_input(p, skb);
503 /* Forwarding output path.
504 * Based on net/bridge/br_forward.c. */
506 static inline unsigned packet_length(const struct sk_buff *skb)
508 int length = skb->len - ETH_HLEN;
509 if (skb->protocol == htons(ETH_P_8021Q))
514 /* Send packets out all the ports except the originating one. If the
515 * "flood" argument is set, only send along the minimum spanning tree.
518 output_all(struct datapath *dp, struct sk_buff *skb, int flood)
520 u32 disable = flood ? OFPPFL_NO_FLOOD : 0;
521 struct net_bridge_port *p;
524 list_for_each_entry_rcu (p, &dp->port_list, node) {
525 if (skb->dev == p->dev || p->flags & disable)
527 if (prev_port != -1) {
528 struct sk_buff *clone = skb_clone(skb, GFP_ATOMIC);
533 dp_output_port(dp, clone, prev_port, 0);
535 prev_port = p->port_no;
538 dp_output_port(dp, skb, prev_port, 0);
545 /* Marks 'skb' as having originated from 'in_port' in 'dp'.
546 FIXME: how are devices reference counted? */
547 int dp_set_origin(struct datapath *dp, uint16_t in_port,
550 struct net_bridge_port *p = (in_port < OFPP_MAX ? dp->ports[in_port]
551 : in_port == OFPP_LOCAL ? dp->local_port
560 static int xmit_skb(struct sk_buff *skb)
563 if (packet_length(skb) > skb->dev->mtu) {
564 printk("dropped over-mtu packet: %d > %d\n",
565 packet_length(skb), skb->dev->mtu);
575 /* Takes ownership of 'skb' and transmits it to 'out_port' on 'dp'.
577 int dp_output_port(struct datapath *dp, struct sk_buff *skb, int out_port,
583 /* Send it out the port it came in on, which is already set in
587 printk("skb device not set forwarding to in_port\n");
591 return xmit_skb(skb);
594 int retval = run_flow_through_tables(dp->chain, skb,
602 return output_all(dp, skb, 1);
605 return output_all(dp, skb, 0);
607 case OFPP_CONTROLLER:
608 return dp_output_control(dp, skb, fwd_save_skb(skb), 0,
612 struct net_device *dev = dp->netdev;
613 return dev ? dp_dev_recv(dev, skb) : -ESRCH;
616 case 0 ... OFPP_MAX-1: {
617 struct net_bridge_port *p = dp->ports[out_port];
620 if (p->dev == skb->dev) {
621 /* To send to the input port, must use OFPP_IN_PORT */
624 printk("can't directly forward to input port\n");
627 if (p->flags & OFPPFL_NO_FWD && !ignore_no_fwd) {
632 return xmit_skb(skb);
642 printk("can't forward to bad port %d\n", out_port);
646 /* Takes ownership of 'skb' and transmits it to 'dp''s control path. If
647 * 'buffer_id' != -1, then only the first 64 bytes of 'skb' are sent;
648 * otherwise, all of 'skb' is sent. 'reason' indicates why 'skb' is being
649 * sent. 'max_len' sets the maximum number of bytes that the caller
650 * wants to be sent; a value of 0 indicates the entire packet should be
653 dp_output_control(struct datapath *dp, struct sk_buff *skb,
654 uint32_t buffer_id, size_t max_len, int reason)
656 /* FIXME? Can we avoid creating a new skbuff in the case where we
657 * forward the whole packet? */
658 struct sk_buff *f_skb;
659 struct ofp_packet_in *opi;
660 struct net_bridge_port *p;
661 size_t fwd_len, opi_len;
665 if ((buffer_id != (uint32_t) -1) && max_len)
666 fwd_len = min(fwd_len, max_len);
668 opi_len = offsetof(struct ofp_packet_in, data) + fwd_len;
669 opi = alloc_openflow_skb(dp, opi_len, OFPT_PACKET_IN, NULL, &f_skb);
674 opi->buffer_id = htonl(buffer_id);
675 opi->total_len = htons(skb->len);
676 p = skb->dev->br_port;
677 opi->in_port = htons(p ? p->port_no : OFPP_LOCAL);
678 opi->reason = reason;
680 memcpy(opi->data, skb_mac_header(skb), fwd_len);
681 err = send_openflow_skb(f_skb, NULL);
688 static void fill_port_desc(struct net_bridge_port *p, struct ofp_phy_port *desc)
691 desc->port_no = htons(p->port_no);
692 strncpy(desc->name, p->dev->name, OFP_MAX_PORT_NAME_LEN);
693 desc->name[OFP_MAX_PORT_NAME_LEN-1] = '\0';
694 memcpy(desc->hw_addr, p->dev->dev_addr, ETH_ALEN);
699 if (p->port_no < 255) {
700 /* FIXME: this is a layering violation and should really be
701 * done in the secchan, as with OFPC_STP in
702 * OFP_SUPPORTED_CAPABILITIES. */
703 desc->features |= OFPPF_STP;
706 spin_lock_irqsave(&p->lock, flags);
707 desc->flags = htonl(p->flags | p->status);
708 spin_unlock_irqrestore(&p->lock, flags);
710 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,24)
711 if (p->dev->ethtool_ops && p->dev->ethtool_ops->get_settings) {
712 struct ethtool_cmd ecmd = { .cmd = ETHTOOL_GSET };
714 if (!p->dev->ethtool_ops->get_settings(p->dev, &ecmd)) {
715 if (ecmd.supported & SUPPORTED_10baseT_Half)
716 desc->features |= OFPPF_10MB_HD;
717 if (ecmd.supported & SUPPORTED_10baseT_Full)
718 desc->features |= OFPPF_10MB_FD;
719 if (ecmd.supported & SUPPORTED_100baseT_Half)
720 desc->features |= OFPPF_100MB_HD;
721 if (ecmd.supported & SUPPORTED_100baseT_Full)
722 desc->features |= OFPPF_100MB_FD;
723 if (ecmd.supported & SUPPORTED_1000baseT_Half)
724 desc->features |= OFPPF_1GB_HD;
725 if (ecmd.supported & SUPPORTED_1000baseT_Full)
726 desc->features |= OFPPF_1GB_FD;
727 /* 10Gbps half-duplex doesn't exist... */
728 if (ecmd.supported & SUPPORTED_10000baseT_Full)
729 desc->features |= OFPPF_10GB_FD;
731 desc->speed = htonl(ecmd.speed);
735 desc->features = htonl(desc->features);
739 fill_features_reply(struct datapath *dp, struct ofp_switch_features *ofr)
741 struct net_bridge_port *p;
744 ofr->datapath_id = cpu_to_be64(dp->id);
746 ofr->n_buffers = htonl(N_PKT_BUFFERS);
747 ofr->n_tables = dp->chain->n_tables;
748 ofr->capabilities = htonl(OFP_SUPPORTED_CAPABILITIES);
749 ofr->actions = htonl(OFP_SUPPORTED_ACTIONS);
750 memset(ofr->pad, 0, sizeof ofr->pad);
752 list_for_each_entry_rcu (p, &dp->port_list, node) {
753 fill_port_desc(p, &ofr->ports[port_count]);
761 dp_send_features_reply(struct datapath *dp, const struct sender *sender)
764 struct ofp_switch_features *ofr;
765 size_t ofr_len, port_max_len;
769 port_max_len = sizeof(struct ofp_phy_port) * OFPP_MAX;
770 ofr = alloc_openflow_skb(dp, sizeof(*ofr) + port_max_len,
771 OFPT_FEATURES_REPLY, sender, &skb);
776 port_count = fill_features_reply(dp, ofr);
779 ofr_len = sizeof(*ofr) + (sizeof(struct ofp_phy_port) * port_count);
780 resize_openflow_skb(skb, &ofr->header, ofr_len);
781 return send_openflow_skb(skb, sender);
785 dp_send_config_reply(struct datapath *dp, const struct sender *sender)
788 struct ofp_switch_config *osc;
790 osc = alloc_openflow_skb(dp, sizeof *osc, OFPT_GET_CONFIG_REPLY, sender,
795 osc->flags = htons(dp->flags);
796 osc->miss_send_len = htons(dp->miss_send_len);
798 return send_openflow_skb(skb, sender);
802 dp_send_hello(struct datapath *dp, const struct sender *sender,
803 const struct ofp_header *request)
805 if (request->version < OFP_VERSION) {
807 sprintf(err, "Only version 0x%02x supported", OFP_VERSION);
808 dp_send_error_msg(dp, sender, OFPET_HELLO_FAILED,
809 OFPHFC_INCOMPATIBLE, err, strlen(err));
813 struct ofp_header *reply;
815 reply = alloc_openflow_skb(dp, sizeof *reply,
816 OFPT_HELLO, sender, &skb);
820 return send_openflow_skb(skb, sender);
824 /* Callback function for a workqueue to disable an interface */
826 down_port_cb(struct work_struct *work)
828 struct net_bridge_port *p = container_of(work, struct net_bridge_port,
832 if (dev_change_flags(p->dev, p->dev->flags & ~IFF_UP) < 0)
834 printk("problem bringing up port %s\n", p->dev->name);
836 p->status |= OFPPFL_PORT_DOWN;
839 /* Callback function for a workqueue to enable an interface */
841 up_port_cb(struct work_struct *work)
843 struct net_bridge_port *p = container_of(work, struct net_bridge_port,
847 if (dev_change_flags(p->dev, p->dev->flags | IFF_UP) < 0)
849 printk("problem bringing down port %s\n", p->dev->name);
851 p->status &= ~OFPPFL_PORT_DOWN;
855 dp_update_port_flags(struct datapath *dp, const struct ofp_port_mod *opm)
857 unsigned long int flags;
858 const struct ofp_phy_port *opp = &opm->desc;
859 int port_no = ntohs(opp->port_no);
860 struct net_bridge_port *p = (port_no < OFPP_MAX ? dp->ports[port_no]
861 : port_no == OFPP_LOCAL ? dp->local_port
865 /* Make sure the port id hasn't changed since this was sent */
866 if (!p || memcmp(opp->hw_addr, p->dev->dev_addr, ETH_ALEN))
869 spin_lock_irqsave(&p->lock, flags);
870 flag_mask = ntohl(opm->mask) & PORT_FLAG_BITS;
872 p->flags &= ~flag_mask;
873 p->flags |= ntohl(opp->flags) & flag_mask;
876 /* Modifying the status of an interface requires taking a lock
877 * that cannot be done from here. For this reason, we use a shared
878 * workqueue, which will cause it to be executed from a safer
880 if (opm->mask & htonl(OFPPFL_PORT_DOWN)) {
881 if ((opp->flags & htonl(OFPPFL_PORT_DOWN))
882 && (p->status & OFPPFL_PORT_DOWN) == 0) {
883 PREPARE_WORK(&p->port_task, down_port_cb);
884 schedule_work(&p->port_task);
885 } else if ((opp->flags & htonl(OFPPFL_PORT_DOWN)) == 0
886 && (p->status & OFPPFL_PORT_DOWN)) {
887 PREPARE_WORK(&p->port_task, up_port_cb);
888 schedule_work(&p->port_task);
891 spin_unlock_irqrestore(&p->lock, flags);
896 /* Update the port status field of the bridge port. A non-zero return
897 * value indicates some field has changed.
899 * NB: Callers of this function may hold the RCU read lock, so any
900 * additional checks must not sleep.
903 update_port_status(struct net_bridge_port *p)
905 unsigned long int flags;
906 uint32_t orig_status;
908 spin_lock_irqsave(&p->lock, flags);
909 orig_status = p->status;
911 if (p->dev->flags & IFF_UP)
912 p->status &= ~OFPPFL_PORT_DOWN;
914 p->status |= OFPPFL_PORT_DOWN;
916 if (netif_carrier_ok(p->dev))
917 p->status &= ~OFPPFL_LINK_DOWN;
919 p->status |= OFPPFL_LINK_DOWN;
921 spin_unlock_irqrestore(&p->lock, flags);
922 return (orig_status != p->status);
926 send_port_status(struct net_bridge_port *p, uint8_t status)
929 struct ofp_port_status *ops;
931 ops = alloc_openflow_skb(p->dp, sizeof *ops, OFPT_PORT_STATUS, NULL,
935 ops->reason = status;
936 memset(ops->pad, 0, sizeof ops->pad);
937 fill_port_desc(p, &ops->desc);
939 return send_openflow_skb(skb, NULL);
943 dp_send_flow_expired(struct datapath *dp, struct sw_flow *flow,
944 enum ofp_flow_expired_reason reason)
947 struct ofp_flow_expired *ofe;
949 if (!(dp->flags & OFPC_SEND_FLOW_EXP))
952 ofe = alloc_openflow_skb(dp, sizeof *ofe, OFPT_FLOW_EXPIRED, 0, &skb);
956 flow_fill_match(&ofe->match, &flow->key);
958 ofe->priority = htons(flow->priority);
959 ofe->reason = reason;
960 memset(ofe->pad, 0, sizeof ofe->pad);
962 ofe->duration = htonl((jiffies - flow->init_time) / HZ);
963 memset(ofe->pad2, 0, sizeof ofe->pad2);
964 ofe->packet_count = cpu_to_be64(flow->packet_count);
965 ofe->byte_count = cpu_to_be64(flow->byte_count);
967 return send_openflow_skb(skb, NULL);
969 EXPORT_SYMBOL(dp_send_flow_expired);
972 dp_send_error_msg(struct datapath *dp, const struct sender *sender,
973 uint16_t type, uint16_t code, const void *data, size_t len)
976 struct ofp_error_msg *oem;
979 oem = alloc_openflow_skb(dp, sizeof(*oem)+len, OFPT_ERROR,
984 oem->type = htons(type);
985 oem->code = htons(code);
986 memcpy(oem->data, data, len);
988 return send_openflow_skb(skb, sender);
992 dp_send_echo_reply(struct datapath *dp, const struct sender *sender,
993 const struct ofp_header *rq)
996 struct ofp_header *reply;
998 reply = alloc_openflow_skb(dp, ntohs(rq->length), OFPT_ECHO_REPLY,
1003 memcpy(reply + 1, rq + 1, ntohs(rq->length) - sizeof *rq);
1004 return send_openflow_skb(skb, sender);
1007 /* Generic Netlink interface.
1009 * See netlink(7) for an introduction to netlink. See
1010 * http://linux-net.osdl.org/index.php/Netlink for more information and
1011 * pointers on how to work with netlink and Generic Netlink in the kernel and
1014 static struct genl_family dp_genl_family = {
1015 .id = GENL_ID_GENERATE,
1017 .name = DP_GENL_FAMILY_NAME,
1019 .maxattr = DP_GENL_A_MAX,
1022 /* Attribute policy: what each attribute may contain. */
1023 static struct nla_policy dp_genl_policy[DP_GENL_A_MAX + 1] = {
1024 [DP_GENL_A_DP_IDX] = { .type = NLA_U32 },
1025 [DP_GENL_A_MC_GROUP] = { .type = NLA_U32 },
1026 [DP_GENL_A_PORTNAME] = { .type = NLA_STRING }
1029 static int dp_genl_add(struct sk_buff *skb, struct genl_info *info)
1031 if (!info->attrs[DP_GENL_A_DP_IDX])
1034 return new_dp(nla_get_u32(info->attrs[DP_GENL_A_DP_IDX]));
1037 static struct genl_ops dp_genl_ops_add_dp = {
1038 .cmd = DP_GENL_C_ADD_DP,
1039 .flags = GENL_ADMIN_PERM, /* Requires CAP_NET_ADMIN privilege. */
1040 .policy = dp_genl_policy,
1041 .doit = dp_genl_add,
1045 struct datapath *dp_get(int dp_idx)
1047 if (dp_idx < 0 || dp_idx > DP_MAX)
1049 return rcu_dereference(dps[dp_idx]);
1052 static int dp_genl_del(struct sk_buff *skb, struct genl_info *info)
1054 struct datapath *dp;
1057 if (!info->attrs[DP_GENL_A_DP_IDX])
1060 dp = dp_get(nla_get_u32((info->attrs[DP_GENL_A_DP_IDX])));
1070 static struct genl_ops dp_genl_ops_del_dp = {
1071 .cmd = DP_GENL_C_DEL_DP,
1072 .flags = GENL_ADMIN_PERM, /* Requires CAP_NET_ADMIN privilege. */
1073 .policy = dp_genl_policy,
1074 .doit = dp_genl_del,
1078 /* Queries a datapath for related information. Currently the only relevant
1079 * information is the datapath's multicast group ID. Really we want one
1080 * multicast group per datapath, but because of locking issues[*] we can't
1081 * easily get one. Thus, every datapath will currently return the same
1082 * global multicast group ID, but in the future it would be nice to fix that.
1084 * [*] dp_genl_add, to add a new datapath, is called under the genl_lock
1085 * mutex, and genl_register_mc_group, called to acquire a new multicast
1086 * group ID, also acquires genl_lock, thus deadlock.
1088 static int dp_genl_query(struct sk_buff *skb, struct genl_info *info)
1090 struct datapath *dp;
1091 struct sk_buff *ans_skb = NULL;
1095 if (!info->attrs[DP_GENL_A_DP_IDX])
1099 dp_idx = nla_get_u32((info->attrs[DP_GENL_A_DP_IDX]));
1100 dp = dp_get(dp_idx);
1105 ans_skb = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC);
1110 data = genlmsg_put_reply(ans_skb, info, &dp_genl_family,
1111 0, DP_GENL_C_QUERY_DP);
1116 NLA_PUT_U32(ans_skb, DP_GENL_A_DP_IDX, dp_idx);
1117 NLA_PUT_U32(ans_skb, DP_GENL_A_MC_GROUP, mc_group.id);
1119 genlmsg_end(ans_skb, data);
1120 err = genlmsg_reply(ans_skb, info);
1132 static struct genl_ops dp_genl_ops_query_dp = {
1133 .cmd = DP_GENL_C_QUERY_DP,
1134 .flags = GENL_ADMIN_PERM, /* Requires CAP_NET_ADMIN privilege. */
1135 .policy = dp_genl_policy,
1136 .doit = dp_genl_query,
1140 static int dp_genl_add_del_port(struct sk_buff *skb, struct genl_info *info)
1142 struct datapath *dp;
1143 struct net_device *port;
1146 if (!info->attrs[DP_GENL_A_DP_IDX] || !info->attrs[DP_GENL_A_PORTNAME])
1150 dp = dp_get(nla_get_u32(info->attrs[DP_GENL_A_DP_IDX]));
1156 /* Get interface to add/remove. */
1157 port = dev_get_by_name(&init_net,
1158 nla_data(info->attrs[DP_GENL_A_PORTNAME]));
1164 /* Execute operation. */
1165 if (info->genlhdr->cmd == DP_GENL_C_ADD_PORT)
1166 err = add_switch_port(dp, port);
1168 if (port->br_port == NULL || port->br_port->dp != dp) {
1172 err = del_switch_port(port->br_port);
1181 static struct genl_ops dp_genl_ops_add_port = {
1182 .cmd = DP_GENL_C_ADD_PORT,
1183 .flags = GENL_ADMIN_PERM, /* Requires CAP_NET_ADMIN privilege. */
1184 .policy = dp_genl_policy,
1185 .doit = dp_genl_add_del_port,
1189 static struct genl_ops dp_genl_ops_del_port = {
1190 .cmd = DP_GENL_C_DEL_PORT,
1191 .flags = GENL_ADMIN_PERM, /* Requires CAP_NET_ADMIN privilege. */
1192 .policy = dp_genl_policy,
1193 .doit = dp_genl_add_del_port,
1197 static int dp_genl_openflow(struct sk_buff *skb, struct genl_info *info)
1199 struct nlattr *va = info->attrs[DP_GENL_A_OPENFLOW];
1200 struct datapath *dp;
1201 struct ofp_header *oh;
1202 struct sender sender;
1205 if (!info->attrs[DP_GENL_A_DP_IDX] || !va)
1208 dp = dp_get(nla_get_u32(info->attrs[DP_GENL_A_DP_IDX]));
1212 if (nla_len(va) < sizeof(struct ofp_header))
1216 sender.xid = oh->xid;
1217 sender.pid = info->snd_pid;
1218 sender.seq = info->snd_seq;
1220 mutex_lock(&dp_mutex);
1221 err = fwd_control_input(dp->chain, &sender,
1222 nla_data(va), nla_len(va));
1223 mutex_unlock(&dp_mutex);
1227 static struct nla_policy dp_genl_openflow_policy[DP_GENL_A_MAX + 1] = {
1228 [DP_GENL_A_DP_IDX] = { .type = NLA_U32 },
1231 static int desc_stats_dump(struct datapath *dp, void *state,
1232 void *body, int *body_len)
1234 struct ofp_desc_stats *ods = body;
1235 int n_bytes = sizeof *ods;
1237 if (n_bytes > *body_len) {
1240 *body_len = n_bytes;
1242 strncpy(ods->mfr_desc, mfr_desc, sizeof ods->mfr_desc);
1243 strncpy(ods->hw_desc, hw_desc, sizeof ods->hw_desc);
1244 strncpy(ods->sw_desc, sw_desc, sizeof ods->sw_desc);
1245 strncpy(ods->serial_num, serial_num, sizeof ods->serial_num);
1250 struct flow_stats_state {
1252 struct sw_table_position position;
1253 const struct ofp_flow_stats_request *rq;
1256 int bytes_used, bytes_allocated;
1259 static int flow_stats_init(struct datapath *dp, const void *body, int body_len,
1262 const struct ofp_flow_stats_request *fsr = body;
1263 struct flow_stats_state *s = kmalloc(sizeof *s, GFP_ATOMIC);
1266 s->table_idx = fsr->table_id == 0xff ? 0 : fsr->table_id;
1267 memset(&s->position, 0, sizeof s->position);
1273 static int flow_stats_dump_callback(struct sw_flow *flow, void *private)
1275 struct flow_stats_state *s = private;
1276 struct ofp_flow_stats *ofs;
1280 actions_length = sizeof *ofs->actions * flow->n_actions;
1281 length = sizeof *ofs + sizeof *ofs->actions * flow->n_actions;
1282 if (length + s->bytes_used > s->bytes_allocated)
1285 ofs = s->body + s->bytes_used;
1286 ofs->length = htons(length);
1287 ofs->table_id = s->table_idx;
1289 ofs->match.wildcards = htonl(flow->key.wildcards);
1290 ofs->match.in_port = flow->key.in_port;
1291 memcpy(ofs->match.dl_src, flow->key.dl_src, ETH_ALEN);
1292 memcpy(ofs->match.dl_dst, flow->key.dl_dst, ETH_ALEN);
1293 ofs->match.dl_vlan = flow->key.dl_vlan;
1294 ofs->match.dl_type = flow->key.dl_type;
1295 ofs->match.nw_src = flow->key.nw_src;
1296 ofs->match.nw_dst = flow->key.nw_dst;
1297 ofs->match.nw_proto = flow->key.nw_proto;
1299 ofs->match.tp_src = flow->key.tp_src;
1300 ofs->match.tp_dst = flow->key.tp_dst;
1301 ofs->duration = htonl((jiffies - flow->init_time) / HZ);
1302 ofs->priority = htons(flow->priority);
1303 ofs->idle_timeout = htons(flow->idle_timeout);
1304 ofs->hard_timeout = htons(flow->hard_timeout);
1305 memset(ofs->pad2, 0, sizeof ofs->pad2);
1306 ofs->packet_count = cpu_to_be64(flow->packet_count);
1307 ofs->byte_count = cpu_to_be64(flow->byte_count);
1308 memcpy(ofs->actions, flow->actions, actions_length);
1310 s->bytes_used += length;
1314 static int flow_stats_dump(struct datapath *dp, void *state,
1315 void *body, int *body_len)
1317 struct flow_stats_state *s = state;
1318 struct sw_flow_key match_key;
1322 s->bytes_allocated = *body_len;
1325 flow_extract_match(&match_key, &s->rq->match);
1326 while (s->table_idx < dp->chain->n_tables
1327 && (s->rq->table_id == 0xff || s->rq->table_id == s->table_idx))
1329 struct sw_table *table = dp->chain->tables[s->table_idx];
1331 error = table->iterate(table, &match_key, &s->position,
1332 flow_stats_dump_callback, s);
1337 memset(&s->position, 0, sizeof s->position);
1339 *body_len = s->bytes_used;
1341 /* If error is 0, we're done.
1342 * Otherwise, if some bytes were used, there are more flows to come.
1343 * Otherwise, we were not able to fit even a single flow in the body,
1344 * which indicates that we have a single flow with too many actions to
1345 * fit. We won't ever make any progress at that rate, so give up. */
1346 return !error ? 0 : s->bytes_used ? 1 : -ENOMEM;
1349 static void flow_stats_done(void *state)
1354 static int aggregate_stats_init(struct datapath *dp,
1355 const void *body, int body_len,
1358 *state = (void *)body;
1362 static int aggregate_stats_dump_callback(struct sw_flow *flow, void *private)
1364 struct ofp_aggregate_stats_reply *rpy = private;
1365 rpy->packet_count += flow->packet_count;
1366 rpy->byte_count += flow->byte_count;
1371 static int aggregate_stats_dump(struct datapath *dp, void *state,
1372 void *body, int *body_len)
1374 struct ofp_aggregate_stats_request *rq = state;
1375 struct ofp_aggregate_stats_reply *rpy;
1376 struct sw_table_position position;
1377 struct sw_flow_key match_key;
1380 if (*body_len < sizeof *rpy)
1383 *body_len = sizeof *rpy;
1385 memset(rpy, 0, sizeof *rpy);
1387 flow_extract_match(&match_key, &rq->match);
1388 table_idx = rq->table_id == 0xff ? 0 : rq->table_id;
1389 memset(&position, 0, sizeof position);
1390 while (table_idx < dp->chain->n_tables
1391 && (rq->table_id == 0xff || rq->table_id == table_idx))
1393 struct sw_table *table = dp->chain->tables[table_idx];
1396 error = table->iterate(table, &match_key, &position,
1397 aggregate_stats_dump_callback, rpy);
1402 memset(&position, 0, sizeof position);
1405 rpy->packet_count = cpu_to_be64(rpy->packet_count);
1406 rpy->byte_count = cpu_to_be64(rpy->byte_count);
1407 rpy->flow_count = htonl(rpy->flow_count);
1411 static int table_stats_dump(struct datapath *dp, void *state,
1412 void *body, int *body_len)
1414 struct ofp_table_stats *ots;
1415 int n_bytes = dp->chain->n_tables * sizeof *ots;
1417 if (n_bytes > *body_len)
1419 *body_len = n_bytes;
1420 for (i = 0, ots = body; i < dp->chain->n_tables; i++, ots++) {
1421 struct sw_table_stats stats;
1422 dp->chain->tables[i]->stats(dp->chain->tables[i], &stats);
1423 strncpy(ots->name, stats.name, sizeof ots->name);
1425 ots->wildcards = htonl(stats.wildcards);
1426 memset(ots->pad, 0, sizeof ots->pad);
1427 ots->max_entries = htonl(stats.max_flows);
1428 ots->active_count = htonl(stats.n_flows);
1429 ots->matched_count = cpu_to_be64(stats.n_matched);
1434 struct port_stats_state {
1438 static int port_stats_init(struct datapath *dp, const void *body, int body_len,
1441 struct port_stats_state *s = kmalloc(sizeof *s, GFP_ATOMIC);
1449 static int port_stats_dump(struct datapath *dp, void *state,
1450 void *body, int *body_len)
1452 struct port_stats_state *s = state;
1453 struct ofp_port_stats *ops;
1454 int n_ports, max_ports;
1457 max_ports = *body_len / sizeof *ops;
1463 for (i = s->port; i < OFPP_MAX && n_ports < max_ports; i++) {
1464 struct net_bridge_port *p = dp->ports[i];
1465 struct net_device_stats *stats;
1468 stats = p->dev->get_stats(p->dev);
1469 ops->port_no = htons(p->port_no);
1470 memset(ops->pad, 0, sizeof ops->pad);
1471 ops->rx_packets = cpu_to_be64(stats->rx_packets);
1472 ops->tx_packets = cpu_to_be64(stats->tx_packets);
1473 ops->rx_bytes = cpu_to_be64(stats->rx_bytes);
1474 ops->tx_bytes = cpu_to_be64(stats->tx_bytes);
1475 ops->rx_dropped = cpu_to_be64(stats->rx_dropped);
1476 ops->tx_dropped = cpu_to_be64(stats->tx_dropped);
1477 ops->rx_errors = cpu_to_be64(stats->rx_errors);
1478 ops->tx_errors = cpu_to_be64(stats->tx_errors);
1479 ops->rx_frame_err = cpu_to_be64(stats->rx_frame_errors);
1480 ops->rx_over_err = cpu_to_be64(stats->rx_over_errors);
1481 ops->rx_crc_err = cpu_to_be64(stats->rx_crc_errors);
1482 ops->collisions = cpu_to_be64(stats->collisions);
1487 *body_len = n_ports * sizeof *ops;
1488 return n_ports >= max_ports;
1491 static void port_stats_done(void *state)
1497 /* Minimum and maximum acceptable number of bytes in body member of
1498 * struct ofp_stats_request. */
1499 size_t min_body, max_body;
1501 /* Prepares to dump some kind of statistics on 'dp'. 'body' and
1502 * 'body_len' are the 'body' member of the struct ofp_stats_request.
1503 * Returns zero if successful, otherwise a negative error code.
1504 * May initialize '*state' to state information. May be null if no
1505 * initialization is required.*/
1506 int (*init)(struct datapath *dp, const void *body, int body_len,
1509 /* Dumps statistics for 'dp' into the '*body_len' bytes at 'body', and
1510 * modifies '*body_len' to reflect the number of bytes actually used.
1511 * ('body' will be transmitted as the 'body' member of struct
1512 * ofp_stats_reply.) */
1513 int (*dump)(struct datapath *dp, void *state,
1514 void *body, int *body_len);
1516 /* Cleans any state created by the init or dump functions. May be null
1517 * if no cleanup is required. */
1518 void (*done)(void *state);
1521 static const struct stats_type stats[] = {
1530 sizeof(struct ofp_flow_stats_request),
1531 sizeof(struct ofp_flow_stats_request),
1536 [OFPST_AGGREGATE] = {
1537 sizeof(struct ofp_aggregate_stats_request),
1538 sizeof(struct ofp_aggregate_stats_request),
1539 aggregate_stats_init,
1540 aggregate_stats_dump,
1560 dp_genl_openflow_dumpit(struct sk_buff *skb, struct netlink_callback *cb)
1562 struct datapath *dp;
1563 struct sender sender;
1564 const struct stats_type *s;
1565 struct ofp_stats_reply *osr;
1567 int max_openflow_len, body_len;
1571 /* Set up the cleanup function for this dump. Linux 2.6.20 and later
1572 * support setting up cleanup functions via the .doneit member of
1573 * struct genl_ops. This kluge supports earlier versions also. */
1574 cb->done = dp_genl_openflow_done;
1576 sender.pid = NETLINK_CB(cb->skb).pid;
1577 sender.seq = cb->nlh->nlmsg_seq;
1579 struct nlattr *attrs[DP_GENL_A_MAX + 1];
1580 struct ofp_stats_request *rq;
1582 size_t len, body_len;
1585 err = nlmsg_parse(cb->nlh, GENL_HDRLEN, attrs, DP_GENL_A_MAX,
1586 dp_genl_openflow_policy);
1590 if (!attrs[DP_GENL_A_DP_IDX])
1592 dp_idx = nla_get_u16(attrs[DP_GENL_A_DP_IDX]);
1593 dp = dp_get(dp_idx);
1597 va = attrs[DP_GENL_A_OPENFLOW];
1599 if (!va || len < sizeof *rq)
1603 sender.xid = rq->header.xid;
1604 type = ntohs(rq->type);
1605 if (rq->header.version != OFP_VERSION) {
1606 dp_send_error_msg(dp, &sender, OFPET_BAD_REQUEST,
1607 OFPBRC_BAD_VERSION, rq, len);
1610 if (rq->header.type != OFPT_STATS_REQUEST
1611 || ntohs(rq->header.length) != len)
1614 if (type >= ARRAY_SIZE(stats) || !stats[type].dump) {
1615 dp_send_error_msg(dp, &sender, OFPET_BAD_REQUEST,
1616 OFPBRC_BAD_STAT, rq, len);
1621 body_len = len - offsetof(struct ofp_stats_request, body);
1622 if (body_len < s->min_body || body_len > s->max_body)
1626 cb->args[1] = dp_idx;
1628 cb->args[3] = rq->header.xid;
1631 err = s->init(dp, rq->body, body_len, &state);
1634 cb->args[4] = (long) state;
1636 } else if (cb->args[0] == 1) {
1637 sender.xid = cb->args[3];
1638 dp_idx = cb->args[1];
1639 s = &stats[cb->args[2]];
1641 dp = dp_get(dp_idx);
1648 osr = put_openflow_headers(dp, skb, OFPT_STATS_REPLY, &sender,
1651 return PTR_ERR(osr);
1652 osr->type = htons(s - stats);
1654 resize_openflow_skb(skb, &osr->header, max_openflow_len);
1656 body_len = max_openflow_len - offsetof(struct ofp_stats_reply, body);
1658 err = s->dump(dp, (void *) cb->args[4], body, &body_len);
1663 osr->flags = ntohs(OFPSF_REPLY_MORE);
1664 resize_openflow_skb(skb, &osr->header,
1665 (offsetof(struct ofp_stats_reply, body)
1674 dp_genl_openflow_done(struct netlink_callback *cb)
1677 const struct stats_type *s = &stats[cb->args[2]];
1679 s->done((void *) cb->args[4]);
1684 static struct genl_ops dp_genl_ops_openflow = {
1685 .cmd = DP_GENL_C_OPENFLOW,
1686 .flags = GENL_ADMIN_PERM, /* Requires CAP_NET_ADMIN privilege. */
1687 .policy = dp_genl_openflow_policy,
1688 .doit = dp_genl_openflow,
1689 .dumpit = dp_genl_openflow_dumpit,
1692 static struct genl_ops *dp_genl_all_ops[] = {
1693 /* Keep this operation first. Generic Netlink dispatching
1694 * looks up operations with linear search, so we want it at the
1696 &dp_genl_ops_openflow,
1698 &dp_genl_ops_add_dp,
1699 &dp_genl_ops_del_dp,
1700 &dp_genl_ops_query_dp,
1701 &dp_genl_ops_add_port,
1702 &dp_genl_ops_del_port,
1705 static int dp_init_netlink(void)
1710 err = genl_register_family(&dp_genl_family);
1714 for (i = 0; i < ARRAY_SIZE(dp_genl_all_ops); i++) {
1715 err = genl_register_ops(&dp_genl_family, dp_genl_all_ops[i]);
1717 goto err_unregister;
1720 strcpy(mc_group.name, "openflow");
1721 err = genl_register_mc_group(&dp_genl_family, &mc_group);
1723 goto err_unregister;
1728 genl_unregister_family(&dp_genl_family);
1732 static void dp_uninit_netlink(void)
1734 genl_unregister_family(&dp_genl_family);
1737 static int __init dp_init(void)
1741 printk("OpenFlow "VERSION", built "__DATE__" "__TIME__", "
1742 "protocol 0x%02x\n", OFP_VERSION);
1748 err = dp_init_netlink();
1750 goto error_flow_exit;
1752 /* Hook into callback used by the bridge to intercept packets.
1753 * Parasites we are. */
1754 if (br_handle_frame_hook)
1755 printk("openflow: hijacking bridge hook\n");
1756 br_handle_frame_hook = dp_frame_hook;
1763 printk(KERN_EMERG "openflow: failed to install!");
1767 static void dp_cleanup(void)
1770 dp_uninit_netlink();
1772 br_handle_frame_hook = NULL;
1775 module_init(dp_init);
1776 module_exit(dp_cleanup);
1778 MODULE_DESCRIPTION("OpenFlow switching datapath");
1779 MODULE_AUTHOR("Copyright (c) 2007, 2008 The Board of Trustees of The Leland Stanford Junior University");
1780 MODULE_LICENSE("GPL");