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 version stats message. */
47 static char mfr_desc[VERSION_STR_LEN] = "Nicira Networks";
48 static char hw_desc[VERSION_STR_LEN] = "Reference Linux Kernel Module";
49 static char sw_desc[VERSION_STR_LEN] = VERSION;
51 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
52 module_param_string(mfr_desc, mfr_desc, sizeof mfr_desc, 0444);
53 module_param_string(hw_desc, hw_desc, sizeof hw_desc, 0444);
54 module_param_string(sw_desc, sw_desc, sizeof sw_desc, 0444);
56 MODULE_PARM(mfr_desc, "s");
57 MODULE_PARM(hw_desc, "s");
58 MODULE_PARM(sw_desc, "s");
62 /* Number of milliseconds between runs of the maintenance thread. */
63 #define MAINT_SLEEP_MSECS 1000
66 BRPF_NO_FLOOD = 1 << 0,
70 BRPS_PORT_DOWN = 1 << 0,
71 BRPS_LINK_DOWN = 1 << 1,
74 #define UINT32_MAX 4294967295U
75 #define UINT16_MAX 65535
76 #define MAX(X, Y) ((X) > (Y) ? (X) : (Y))
78 struct net_bridge_port {
80 u32 flags; /* BRPF_* flags */
81 u32 status; /* BRPS_* flags */
83 struct work_struct port_task;
85 struct net_device *dev;
86 struct list_head node; /* Element in datapath.ports. */
89 static struct genl_family dp_genl_family;
90 static struct genl_multicast_group mc_group;
92 /* It's hard to imagine wanting more than one datapath, but... */
95 /* Datapaths. Protected on the read side by rcu_read_lock, on the write side
96 * by dp_mutex. dp_mutex is almost completely redundant with genl_mutex
97 * maintained by the Generic Netlink code, but the timeout path needs mutual
100 * It is safe to access the datapath and net_bridge_port structures with just
103 static struct datapath *dps[DP_MAX];
104 DEFINE_MUTEX(dp_mutex);
105 EXPORT_SYMBOL(dp_mutex);
107 static int dp_maint_func(void *data);
108 static int update_port_status(struct net_bridge_port *p);
109 static int send_port_status(struct net_bridge_port *p, uint8_t status);
110 static int dp_genl_openflow_done(struct netlink_callback *);
111 static struct net_bridge_port *new_nbp(struct datapath *,
112 struct net_device *, int port_no);
113 static int del_switch_port(struct net_bridge_port *);
115 /* nla_shrink - reduce amount of space reserved by nla_reserve
116 * @skb: socket buffer from which to recover room
117 * @nla: netlink attribute to adjust
118 * @len: new length of attribute payload
120 * Reduces amount of space reserved by a call to nla_reserve.
122 * No other attributes may be added between calling nla_reserve and this
123 * function, since it will create a hole in the message.
125 void nla_shrink(struct sk_buff *skb, struct nlattr *nla, int len)
127 int delta = nla_total_size(len) - nla_total_size(nla_len(nla));
131 nla->nla_len = nla_attr_size(len);
134 /* Puts a set of openflow headers for a message of the given 'type' into 'skb'.
135 * If 'sender' is nonnull, then it is used as the message's destination. 'dp'
136 * must specify the datapath to use.
138 * '*max_openflow_len' receives the maximum number of bytes that are available
139 * for the embedded OpenFlow message. The caller must call
140 * resize_openflow_skb() to set the actual size of the message to this number
143 * Returns the openflow header if successful, otherwise (if 'skb' is too small)
146 put_openflow_headers(struct datapath *dp, struct sk_buff *skb, uint8_t type,
147 const struct sender *sender, int *max_openflow_len)
149 struct ofp_header *oh;
153 /* Assemble the Generic Netlink wrapper. */
154 if (!genlmsg_put(skb,
155 sender ? sender->pid : 0,
156 sender ? sender->seq : 0,
157 &dp_genl_family, 0, DP_GENL_C_OPENFLOW))
158 return ERR_PTR(-ENOBUFS);
159 if (nla_put_u32(skb, DP_GENL_A_DP_IDX, dp->dp_idx) < 0)
160 return ERR_PTR(-ENOBUFS);
161 openflow_len = (skb_tailroom(skb) - NLA_HDRLEN) & ~(NLA_ALIGNTO - 1);
162 if (openflow_len < sizeof *oh)
163 return ERR_PTR(-ENOBUFS);
164 *max_openflow_len = openflow_len;
165 attr = nla_reserve(skb, DP_GENL_A_OPENFLOW, openflow_len);
168 /* Fill in the header. The caller is responsible for the length. */
170 oh->version = OFP_VERSION;
172 oh->xid = sender ? sender->xid : 0;
177 /* Resizes OpenFlow header 'oh', which must be at the tail end of 'skb', to new
178 * length 'new_length' (in bytes), adjusting pointers and size values as
181 resize_openflow_skb(struct sk_buff *skb,
182 struct ofp_header *oh, size_t new_length)
184 struct nlattr *attr = ((void *) oh) - NLA_HDRLEN;
185 nla_shrink(skb, attr, new_length);
186 oh->length = htons(new_length);
187 nlmsg_end(skb, (struct nlmsghdr *) skb->data);
190 /* Allocates a new skb to contain an OpenFlow message 'openflow_len' bytes in
191 * length. Returns a null pointer if memory is unavailable, otherwise returns
192 * the OpenFlow header and stores a pointer to the skb in '*pskb'.
194 * 'type' is the OpenFlow message type. If 'sender' is nonnull, then it is
195 * used as the message's destination. 'dp' must specify the datapath to
198 alloc_openflow_skb(struct datapath *dp, size_t openflow_len, uint8_t type,
199 const struct sender *sender, struct sk_buff **pskb)
201 struct ofp_header *oh;
204 int max_openflow_len;
206 if ((openflow_len + sizeof(struct ofp_header)) > UINT16_MAX) {
208 printk("alloc_openflow_skb: openflow message too large: %zu\n",
213 genl_len = nlmsg_total_size(GENL_HDRLEN + dp_genl_family.hdrsize);
214 genl_len += nla_total_size(sizeof(uint32_t)); /* DP_GENL_A_DP_IDX */
215 genl_len += nla_total_size(openflow_len); /* DP_GENL_A_OPENFLOW */
216 skb = *pskb = genlmsg_new(genl_len, GFP_ATOMIC);
219 printk("alloc_openflow_skb: genlmsg_new failed\n");
223 oh = put_openflow_headers(dp, skb, type, sender, &max_openflow_len);
224 BUG_ON(!oh || IS_ERR(oh));
225 resize_openflow_skb(skb, oh, openflow_len);
230 /* Sends 'skb' to 'sender' if it is nonnull, otherwise multicasts 'skb' to all
233 send_openflow_skb(struct sk_buff *skb, const struct sender *sender)
236 ? genlmsg_unicast(skb, sender->pid)
237 : genlmsg_multicast(skb, 0, mc_group.id, GFP_ATOMIC));
240 /* Generates a unique datapath id. It incorporates the datapath index
241 * and a hardware address, if available. If not, it generates a random
245 uint64_t gen_datapath_id(uint16_t dp_idx)
249 struct net_device *dev;
251 /* The top 16 bits are used to identify the datapath. The lower 48 bits
252 * use an interface address. */
253 id = (uint64_t)dp_idx << 48;
254 if ((dev = dev_get_by_name(&init_net, "ctl0"))
255 || (dev = dev_get_by_name(&init_net, "eth0"))) {
256 for (i=0; i<ETH_ALEN; i++) {
257 id |= (uint64_t)dev->dev_addr[i] << (8*(ETH_ALEN-1 - i));
261 /* Randomly choose the lower 48 bits if we cannot find an
262 * address and mark the most significant bit to indicate that
263 * this was randomly generated. */
264 uint8_t rand[ETH_ALEN];
265 get_random_bytes(rand, ETH_ALEN);
266 id |= (uint64_t)1 << 63;
267 for (i=0; i<ETH_ALEN; i++) {
268 id |= (uint64_t)rand[i] << (8*(ETH_ALEN-1 - i));
275 /* Creates a new datapath numbered 'dp_idx'. Returns 0 for success or a
276 * negative error code. */
277 static int new_dp(int dp_idx)
282 if (dp_idx < 0 || dp_idx >= DP_MAX)
285 if (!try_module_get(THIS_MODULE))
288 /* Exit early if a datapath with that number already exists. */
295 dp = kzalloc(sizeof *dp, GFP_KERNEL);
299 /* Setup our "of" device */
300 err = dp_dev_setup(dp);
305 dp->id = gen_datapath_id(dp_idx);
306 dp->chain = chain_create(dp);
307 if (dp->chain == NULL)
308 goto err_destroy_dp_dev;
309 INIT_LIST_HEAD(&dp->port_list);
311 dp->local_port = new_nbp(dp, dp->netdev, OFPP_LOCAL);
312 if (IS_ERR(dp->local_port)) {
313 err = PTR_ERR(dp->local_port);
314 goto err_destroy_local_port;
318 dp->miss_send_len = OFP_DEFAULT_MISS_SEND_LEN;
320 dp->dp_task = kthread_run(dp_maint_func, dp, "dp%d", dp_idx);
321 if (IS_ERR(dp->dp_task))
322 goto err_destroy_chain;
328 err_destroy_local_port:
329 del_switch_port(dp->local_port);
331 chain_destroy(dp->chain);
337 module_put(THIS_MODULE);
341 /* Find and return a free port number under 'dp'. */
342 static int find_portno(struct datapath *dp)
345 for (i = 0; i < OFPP_MAX; i++)
346 if (dp->ports[i] == NULL)
351 static struct net_bridge_port *new_nbp(struct datapath *dp,
352 struct net_device *dev, int port_no)
354 struct net_bridge_port *p;
356 if (dev->br_port != NULL)
357 return ERR_PTR(-EBUSY);
359 p = kzalloc(sizeof(*p), GFP_KERNEL);
361 return ERR_PTR(-ENOMEM);
364 dev_set_promiscuity(dev, 1);
369 p->port_no = port_no;
370 spin_lock_init(&p->lock);
371 INIT_WORK(&p->port_task, NULL);
372 if (port_no != OFPP_LOCAL)
373 rcu_assign_pointer(dev->br_port, p);
374 if (port_no < OFPP_MAX)
375 rcu_assign_pointer(dp->ports[port_no], p);
376 list_add_rcu(&p->node, &dp->port_list);
381 int add_switch_port(struct datapath *dp, struct net_device *dev)
383 struct net_bridge_port *p;
386 if (dev->flags & IFF_LOOPBACK || dev->type != ARPHRD_ETHER
390 port_no = find_portno(dp);
394 p = new_nbp(dp, dev, port_no);
398 update_port_status(p);
400 /* Notify the ctlpath that this port has been added */
401 send_port_status(p, OFPPR_ADD);
406 /* Delete 'p' from switch. */
407 static int del_switch_port(struct net_bridge_port *p)
409 /* First drop references to device. */
410 cancel_work_sync(&p->port_task);
412 dev_set_promiscuity(p->dev, -1);
414 list_del_rcu(&p->node);
415 if (p->port_no != OFPP_LOCAL)
416 rcu_assign_pointer(p->dp->ports[p->port_no], NULL);
417 rcu_assign_pointer(p->dev->br_port, NULL);
419 /* Then wait until no one is still using it, and destroy it. */
422 /* Notify the ctlpath that this port no longer exists */
423 send_port_status(p, OFPPR_DELETE);
431 static void del_dp(struct datapath *dp)
433 struct net_bridge_port *p, *n;
435 kthread_stop(dp->dp_task);
437 /* Drop references to DP. */
438 list_for_each_entry_safe (p, n, &dp->port_list, node)
440 rcu_assign_pointer(dps[dp->dp_idx], NULL);
442 /* Kill off local_port dev references from buffered packets that have
443 * associated dst entries. */
447 /* Destroy dp->netdev. (Must follow deleting switch ports since
448 * dp->local_port has a reference to it.) */
451 /* Wait until no longer in use, then destroy it. */
453 chain_destroy(dp->chain);
455 module_put(THIS_MODULE);
458 static int dp_maint_func(void *data)
460 struct datapath *dp = (struct datapath *) data;
462 while (!kthread_should_stop()) {
463 struct net_bridge_port *p;
465 /* Check if port status has changed */
467 list_for_each_entry_rcu (p, &dp->port_list, node)
468 if (update_port_status(p))
469 send_port_status(p, OFPPR_MOD);
472 /* Timeout old entries */
473 chain_timeout(dp->chain);
474 msleep_interruptible(MAINT_SLEEP_MSECS);
481 do_port_input(struct net_bridge_port *p, struct sk_buff *skb)
483 /* Push the Ethernet header back on. */
484 skb_push(skb, ETH_HLEN);
485 fwd_port_input(p->dp->chain, skb, p->port_no);
489 * Used as br_handle_frame_hook. (Cannot run bridge at the same time, even on
490 * different set of devices!)
492 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,22)
493 /* Called with rcu_read_lock. */
494 static struct sk_buff *dp_frame_hook(struct net_bridge_port *p,
497 do_port_input(p, skb);
500 #elif LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
501 static int dp_frame_hook(struct net_bridge_port *p, struct sk_buff **pskb)
503 do_port_input(p, *pskb);
507 /* NB: This has only been tested on 2.4.35 */
508 static void dp_frame_hook(struct sk_buff *skb)
510 struct net_bridge_port *p = skb->dev->br_port;
513 do_port_input(p, skb);
520 /* Forwarding output path.
521 * Based on net/bridge/br_forward.c. */
523 static inline unsigned packet_length(const struct sk_buff *skb)
525 int length = skb->len - ETH_HLEN;
526 if (skb->protocol == htons(ETH_P_8021Q))
531 /* Send packets out all the ports except the originating one. If the
532 * "flood" argument is set, only send along the minimum spanning tree.
535 output_all(struct datapath *dp, struct sk_buff *skb, int flood)
537 u32 disable = flood ? BRPF_NO_FLOOD : 0;
538 struct net_bridge_port *p;
541 list_for_each_entry_rcu (p, &dp->port_list, node) {
542 if (skb->dev == p->dev || p->flags & disable)
544 if (prev_port != -1) {
545 struct sk_buff *clone = skb_clone(skb, GFP_ATOMIC);
550 dp_output_port(dp, clone, prev_port);
552 prev_port = p->port_no;
555 dp_output_port(dp, skb, prev_port);
562 /* Marks 'skb' as having originated from 'in_port' in 'dp'.
563 FIXME: how are devices reference counted? */
564 int dp_set_origin(struct datapath *dp, uint16_t in_port,
567 struct net_bridge_port *p = (in_port < OFPP_MAX ? dp->ports[in_port]
568 : in_port == OFPP_LOCAL ? dp->local_port
577 static int xmit_skb(struct sk_buff *skb)
580 if (packet_length(skb) > skb->dev->mtu) {
581 printk("dropped over-mtu packet: %d > %d\n",
582 packet_length(skb), skb->dev->mtu);
592 /* Takes ownership of 'skb' and transmits it to 'out_port' on 'dp'.
594 int dp_output_port(struct datapath *dp, struct sk_buff *skb, int out_port)
599 /* Send it out the port it came in on, which is already set in
603 printk("skb device not set forwarding to in_port\n");
607 return xmit_skb(skb);
610 struct net_bridge_port *p = skb->dev->br_port;
612 retval = run_flow_through_tables(dp->chain, skb,
613 p ? p->port_no : OFPP_LOCAL);
620 return output_all(dp, skb, 1);
623 return output_all(dp, skb, 0);
625 case OFPP_CONTROLLER:
626 return dp_output_control(dp, skb, fwd_save_skb(skb), 0,
630 struct net_device *dev = dp->netdev;
631 return dev ? dp_dev_recv(dev, skb) : -ESRCH;
634 case 0 ... OFPP_MAX-1: {
635 struct net_bridge_port *p = dp->ports[out_port];
638 if (p->dev == skb->dev) {
639 /* To send to the input port, must use OFPP_IN_PORT */
642 printk("can't directly forward to input port\n");
646 return xmit_skb(skb);
656 printk("can't forward to bad port %d\n", out_port);
660 /* Takes ownership of 'skb' and transmits it to 'dp''s control path. If
661 * 'buffer_id' != -1, then only the first 64 bytes of 'skb' are sent;
662 * otherwise, all of 'skb' is sent. 'reason' indicates why 'skb' is being
663 * sent. 'max_len' sets the maximum number of bytes that the caller
664 * wants to be sent; a value of 0 indicates the entire packet should be
667 dp_output_control(struct datapath *dp, struct sk_buff *skb,
668 uint32_t buffer_id, size_t max_len, int reason)
670 /* FIXME? Can we avoid creating a new skbuff in the case where we
671 * forward the whole packet? */
672 struct sk_buff *f_skb;
673 struct ofp_packet_in *opi;
674 struct net_bridge_port *p;
675 size_t fwd_len, opi_len;
679 if ((buffer_id != (uint32_t) -1) && max_len)
680 fwd_len = min(fwd_len, max_len);
682 opi_len = offsetof(struct ofp_packet_in, data) + fwd_len;
683 opi = alloc_openflow_skb(dp, opi_len, OFPT_PACKET_IN, NULL, &f_skb);
688 opi->buffer_id = htonl(buffer_id);
689 opi->total_len = htons(skb->len);
690 p = skb->dev->br_port;
691 opi->in_port = htons(p ? p->port_no : OFPP_LOCAL);
692 opi->reason = reason;
694 memcpy(opi->data, skb_mac_header(skb), fwd_len);
695 err = send_openflow_skb(f_skb, NULL);
702 static void fill_port_desc(struct net_bridge_port *p, struct ofp_phy_port *desc)
705 desc->port_no = htons(p->port_no);
706 strncpy(desc->name, p->dev->name, OFP_MAX_PORT_NAME_LEN);
707 desc->name[OFP_MAX_PORT_NAME_LEN-1] = '\0';
708 memcpy(desc->hw_addr, p->dev->dev_addr, ETH_ALEN);
713 spin_lock_irqsave(&p->lock, flags);
714 if (p->flags & BRPF_NO_FLOOD)
715 desc->flags |= htonl(OFPPFL_NO_FLOOD);
716 else if (p->status & BRPS_PORT_DOWN)
717 desc->flags |= htonl(OFPPFL_PORT_DOWN);
718 else if (p->status & BRPS_LINK_DOWN)
719 desc->flags |= htonl(OFPPFL_LINK_DOWN);
720 spin_unlock_irqrestore(&p->lock, flags);
722 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,24)
723 if (p->dev->ethtool_ops && p->dev->ethtool_ops->get_settings) {
724 struct ethtool_cmd ecmd = { .cmd = ETHTOOL_GSET };
726 if (!p->dev->ethtool_ops->get_settings(p->dev, &ecmd)) {
727 if (ecmd.supported & SUPPORTED_10baseT_Half)
728 desc->features |= OFPPF_10MB_HD;
729 if (ecmd.supported & SUPPORTED_10baseT_Full)
730 desc->features |= OFPPF_10MB_FD;
731 if (ecmd.supported & SUPPORTED_100baseT_Half)
732 desc->features |= OFPPF_100MB_HD;
733 if (ecmd.supported & SUPPORTED_100baseT_Full)
734 desc->features |= OFPPF_100MB_FD;
735 if (ecmd.supported & SUPPORTED_1000baseT_Half)
736 desc->features |= OFPPF_1GB_HD;
737 if (ecmd.supported & SUPPORTED_1000baseT_Full)
738 desc->features |= OFPPF_1GB_FD;
739 /* 10Gbps half-duplex doesn't exist... */
740 if (ecmd.supported & SUPPORTED_10000baseT_Full)
741 desc->features |= OFPPF_10GB_FD;
743 desc->features = htonl(desc->features);
744 desc->speed = htonl(ecmd.speed);
751 fill_features_reply(struct datapath *dp, struct ofp_switch_features *ofr)
753 struct net_bridge_port *p;
756 ofr->datapath_id = cpu_to_be64(dp->id);
758 ofr->n_exact = htonl(2 * TABLE_HASH_MAX_FLOWS);
759 ofr->n_compression = 0; /* Not supported */
760 ofr->n_general = htonl(TABLE_LINEAR_MAX_FLOWS);
761 ofr->buffer_mb = htonl(UINT32_MAX);
762 ofr->n_buffers = htonl(N_PKT_BUFFERS);
763 ofr->capabilities = htonl(OFP_SUPPORTED_CAPABILITIES);
764 ofr->actions = htonl(OFP_SUPPORTED_ACTIONS);
766 list_for_each_entry_rcu (p, &dp->port_list, node) {
767 fill_port_desc(p, &ofr->ports[port_count]);
775 dp_send_features_reply(struct datapath *dp, const struct sender *sender)
778 struct ofp_switch_features *ofr;
779 size_t ofr_len, port_max_len;
783 port_max_len = sizeof(struct ofp_phy_port) * OFPP_MAX;
784 ofr = alloc_openflow_skb(dp, sizeof(*ofr) + port_max_len,
785 OFPT_FEATURES_REPLY, sender, &skb);
790 port_count = fill_features_reply(dp, ofr);
793 ofr_len = sizeof(*ofr) + (sizeof(struct ofp_phy_port) * port_count);
794 resize_openflow_skb(skb, &ofr->header, ofr_len);
795 return send_openflow_skb(skb, sender);
799 dp_send_config_reply(struct datapath *dp, const struct sender *sender)
802 struct ofp_switch_config *osc;
804 osc = alloc_openflow_skb(dp, sizeof *osc, OFPT_GET_CONFIG_REPLY, sender,
809 osc->flags = htons(dp->flags);
810 osc->miss_send_len = htons(dp->miss_send_len);
812 return send_openflow_skb(skb, sender);
815 /* Callback function for a workqueue to disable an interface */
817 down_port_cb(struct work_struct *work)
819 struct net_bridge_port *p = container_of(work, struct net_bridge_port,
823 if (dev_change_flags(p->dev, p->dev->flags & ~IFF_UP) < 0)
825 printk("problem bringing up port %s\n", p->dev->name);
827 p->status |= BRPS_PORT_DOWN;
830 /* Callback function for a workqueue to enable an interface */
832 up_port_cb(struct work_struct *work)
834 struct net_bridge_port *p = container_of(work, struct net_bridge_port,
838 if (dev_change_flags(p->dev, p->dev->flags | IFF_UP) < 0)
840 printk("problem bringing down port %s\n", p->dev->name);
842 p->status &= ~BRPS_PORT_DOWN;
846 dp_update_port_flags(struct datapath *dp, const struct ofp_port_mod *opm)
848 unsigned long int flags;
849 const struct ofp_phy_port *opp = &opm->desc;
850 int port_no = ntohs(opp->port_no);
851 struct net_bridge_port *p = (port_no < OFPP_MAX ? dp->ports[port_no]
852 : port_no == OFPP_LOCAL ? dp->local_port
854 /* Make sure the port id hasn't changed since this was sent */
855 if (!p || memcmp(opp->hw_addr, p->dev->dev_addr, ETH_ALEN))
858 spin_lock_irqsave(&p->lock, flags);
859 if (opm->mask & htonl(OFPPFL_NO_FLOOD)) {
860 if (opp->flags & htonl(OFPPFL_NO_FLOOD))
861 p->flags |= BRPF_NO_FLOOD;
863 p->flags &= ~BRPF_NO_FLOOD;
866 /* Modifying the status of an interface requires taking a lock
867 * that cannot be done from here. For this reason, we use a shared
868 * workqueue, which will cause it to be executed from a safer
870 if (opm->mask & htonl(OFPPFL_PORT_DOWN)) {
871 if ((opp->flags & htonl(OFPPFL_PORT_DOWN))
872 && (p->status & BRPS_PORT_DOWN) == 0) {
873 PREPARE_WORK(&p->port_task, down_port_cb);
874 schedule_work(&p->port_task);
875 } else if ((opp->flags & htonl(OFPPFL_PORT_DOWN)) == 0
876 && (p->status & BRPS_PORT_DOWN)) {
877 PREPARE_WORK(&p->port_task, up_port_cb);
878 schedule_work(&p->port_task);
881 spin_unlock_irqrestore(&p->lock, flags);
886 /* Update the port status field of the bridge port. A non-zero return
887 * value indicates some field has changed.
889 * NB: Callers of this function may hold the RCU read lock, so any
890 * additional checks must not sleep.
893 update_port_status(struct net_bridge_port *p)
895 unsigned long int flags;
896 uint32_t orig_status;
898 spin_lock_irqsave(&p->lock, flags);
899 orig_status = p->status;
901 if (p->dev->flags & IFF_UP)
902 p->status &= ~BRPS_PORT_DOWN;
904 p->status |= BRPS_PORT_DOWN;
906 if (netif_carrier_ok(p->dev))
907 p->status &= ~BRPS_LINK_DOWN;
909 p->status |= BRPS_LINK_DOWN;
911 spin_unlock_irqrestore(&p->lock, flags);
912 return (orig_status != p->status);
916 send_port_status(struct net_bridge_port *p, uint8_t status)
919 struct ofp_port_status *ops;
921 ops = alloc_openflow_skb(p->dp, sizeof *ops, OFPT_PORT_STATUS, NULL,
925 ops->reason = status;
926 memset(ops->pad, 0, sizeof ops->pad);
927 fill_port_desc(p, &ops->desc);
929 return send_openflow_skb(skb, NULL);
933 dp_send_flow_expired(struct datapath *dp, struct sw_flow *flow,
934 enum ofp_flow_expired_reason reason)
937 struct ofp_flow_expired *ofe;
939 if (!(dp->flags & OFPC_SEND_FLOW_EXP))
942 ofe = alloc_openflow_skb(dp, sizeof *ofe, OFPT_FLOW_EXPIRED, 0, &skb);
946 flow_fill_match(&ofe->match, &flow->key);
948 ofe->priority = htons(flow->priority);
949 ofe->reason = reason;
950 memset(ofe->pad, 0, sizeof ofe->pad);
952 ofe->duration = htonl((jiffies - flow->init_time) / HZ);
953 memset(ofe->pad2, 0, sizeof ofe->pad2);
954 ofe->packet_count = cpu_to_be64(flow->packet_count);
955 ofe->byte_count = cpu_to_be64(flow->byte_count);
957 return send_openflow_skb(skb, NULL);
959 EXPORT_SYMBOL(dp_send_flow_expired);
962 dp_send_error_msg(struct datapath *dp, const struct sender *sender,
963 uint16_t type, uint16_t code, const uint8_t *data, size_t len)
966 struct ofp_error_msg *oem;
969 oem = alloc_openflow_skb(dp, sizeof(*oem)+len, OFPT_ERROR_MSG,
974 oem->type = htons(type);
975 oem->code = htons(code);
976 memcpy(oem->data, data, len);
978 return send_openflow_skb(skb, sender);
982 dp_send_echo_reply(struct datapath *dp, const struct sender *sender,
983 const struct ofp_header *rq)
986 struct ofp_header *reply;
988 reply = alloc_openflow_skb(dp, ntohs(rq->length), OFPT_ECHO_REPLY,
993 memcpy(reply + 1, rq + 1, ntohs(rq->length) - sizeof *rq);
994 return send_openflow_skb(skb, sender);
997 /* Generic Netlink interface.
999 * See netlink(7) for an introduction to netlink. See
1000 * http://linux-net.osdl.org/index.php/Netlink for more information and
1001 * pointers on how to work with netlink and Generic Netlink in the kernel and
1004 static struct genl_family dp_genl_family = {
1005 .id = GENL_ID_GENERATE,
1007 .name = DP_GENL_FAMILY_NAME,
1009 .maxattr = DP_GENL_A_MAX,
1012 /* Attribute policy: what each attribute may contain. */
1013 static struct nla_policy dp_genl_policy[DP_GENL_A_MAX + 1] = {
1014 [DP_GENL_A_DP_IDX] = { .type = NLA_U32 },
1015 [DP_GENL_A_MC_GROUP] = { .type = NLA_U32 },
1016 [DP_GENL_A_PORTNAME] = { .type = NLA_STRING }
1019 static int dp_genl_add(struct sk_buff *skb, struct genl_info *info)
1021 if (!info->attrs[DP_GENL_A_DP_IDX])
1024 return new_dp(nla_get_u32(info->attrs[DP_GENL_A_DP_IDX]));
1027 static struct genl_ops dp_genl_ops_add_dp = {
1028 .cmd = DP_GENL_C_ADD_DP,
1029 .flags = GENL_ADMIN_PERM, /* Requires CAP_NET_ADMIN privilege. */
1030 .policy = dp_genl_policy,
1031 .doit = dp_genl_add,
1035 struct datapath *dp_get(int dp_idx)
1037 if (dp_idx < 0 || dp_idx > DP_MAX)
1039 return rcu_dereference(dps[dp_idx]);
1042 static int dp_genl_del(struct sk_buff *skb, struct genl_info *info)
1044 struct datapath *dp;
1047 if (!info->attrs[DP_GENL_A_DP_IDX])
1050 dp = dp_get(nla_get_u32((info->attrs[DP_GENL_A_DP_IDX])));
1060 static struct genl_ops dp_genl_ops_del_dp = {
1061 .cmd = DP_GENL_C_DEL_DP,
1062 .flags = GENL_ADMIN_PERM, /* Requires CAP_NET_ADMIN privilege. */
1063 .policy = dp_genl_policy,
1064 .doit = dp_genl_del,
1068 /* Queries a datapath for related information. Currently the only relevant
1069 * information is the datapath's multicast group ID. Really we want one
1070 * multicast group per datapath, but because of locking issues[*] we can't
1071 * easily get one. Thus, every datapath will currently return the same
1072 * global multicast group ID, but in the future it would be nice to fix that.
1074 * [*] dp_genl_add, to add a new datapath, is called under the genl_lock
1075 * mutex, and genl_register_mc_group, called to acquire a new multicast
1076 * group ID, also acquires genl_lock, thus deadlock.
1078 static int dp_genl_query(struct sk_buff *skb, struct genl_info *info)
1080 struct datapath *dp;
1081 struct sk_buff *ans_skb = NULL;
1085 if (!info->attrs[DP_GENL_A_DP_IDX])
1089 dp_idx = nla_get_u32((info->attrs[DP_GENL_A_DP_IDX]));
1090 dp = dp_get(dp_idx);
1095 ans_skb = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC);
1100 data = genlmsg_put_reply(ans_skb, info, &dp_genl_family,
1101 0, DP_GENL_C_QUERY_DP);
1106 NLA_PUT_U32(ans_skb, DP_GENL_A_DP_IDX, dp_idx);
1107 NLA_PUT_U32(ans_skb, DP_GENL_A_MC_GROUP, mc_group.id);
1109 genlmsg_end(ans_skb, data);
1110 err = genlmsg_reply(ans_skb, info);
1122 static struct genl_ops dp_genl_ops_query_dp = {
1123 .cmd = DP_GENL_C_QUERY_DP,
1124 .flags = GENL_ADMIN_PERM, /* Requires CAP_NET_ADMIN privilege. */
1125 .policy = dp_genl_policy,
1126 .doit = dp_genl_query,
1130 static int dp_genl_add_del_port(struct sk_buff *skb, struct genl_info *info)
1132 struct datapath *dp;
1133 struct net_device *port;
1136 if (!info->attrs[DP_GENL_A_DP_IDX] || !info->attrs[DP_GENL_A_PORTNAME])
1140 dp = dp_get(nla_get_u32(info->attrs[DP_GENL_A_DP_IDX]));
1146 /* Get interface to add/remove. */
1147 port = dev_get_by_name(&init_net,
1148 nla_data(info->attrs[DP_GENL_A_PORTNAME]));
1154 /* Execute operation. */
1155 if (info->genlhdr->cmd == DP_GENL_C_ADD_PORT)
1156 err = add_switch_port(dp, port);
1158 if (port->br_port == NULL || port->br_port->dp != dp) {
1162 err = del_switch_port(port->br_port);
1171 static struct genl_ops dp_genl_ops_add_port = {
1172 .cmd = DP_GENL_C_ADD_PORT,
1173 .flags = GENL_ADMIN_PERM, /* Requires CAP_NET_ADMIN privilege. */
1174 .policy = dp_genl_policy,
1175 .doit = dp_genl_add_del_port,
1179 static struct genl_ops dp_genl_ops_del_port = {
1180 .cmd = DP_GENL_C_DEL_PORT,
1181 .flags = GENL_ADMIN_PERM, /* Requires CAP_NET_ADMIN privilege. */
1182 .policy = dp_genl_policy,
1183 .doit = dp_genl_add_del_port,
1187 static int dp_genl_openflow(struct sk_buff *skb, struct genl_info *info)
1189 struct nlattr *va = info->attrs[DP_GENL_A_OPENFLOW];
1190 struct datapath *dp;
1191 struct ofp_header *oh;
1192 struct sender sender;
1195 if (!info->attrs[DP_GENL_A_DP_IDX] || !va)
1198 dp = dp_get(nla_get_u32(info->attrs[DP_GENL_A_DP_IDX]));
1202 if (nla_len(va) < sizeof(struct ofp_header))
1206 sender.xid = oh->xid;
1207 sender.pid = info->snd_pid;
1208 sender.seq = info->snd_seq;
1210 mutex_lock(&dp_mutex);
1211 err = fwd_control_input(dp->chain, &sender,
1212 nla_data(va), nla_len(va));
1213 mutex_unlock(&dp_mutex);
1217 static struct nla_policy dp_genl_openflow_policy[DP_GENL_A_MAX + 1] = {
1218 [DP_GENL_A_DP_IDX] = { .type = NLA_U32 },
1221 static int version_stats_dump(struct datapath *dp, void *state,
1222 void *body, int *body_len)
1224 struct ofp_version_stats *ovs = body;
1225 int n_bytes = sizeof *ovs;
1227 if (n_bytes > *body_len) {
1230 *body_len = n_bytes;
1232 strncpy(ovs->mfr_desc, mfr_desc, sizeof ovs->mfr_desc);
1233 strncpy(ovs->hw_desc, hw_desc, sizeof ovs->hw_desc);
1234 strncpy(ovs->sw_desc, sw_desc, sizeof ovs->sw_desc);
1239 struct flow_stats_state {
1241 struct sw_table_position position;
1242 const struct ofp_flow_stats_request *rq;
1245 int bytes_used, bytes_allocated;
1248 static int flow_stats_init(struct datapath *dp, const void *body, int body_len,
1251 const struct ofp_flow_stats_request *fsr = body;
1252 struct flow_stats_state *s = kmalloc(sizeof *s, GFP_ATOMIC);
1255 s->table_idx = fsr->table_id == 0xff ? 0 : fsr->table_id;
1256 memset(&s->position, 0, sizeof s->position);
1262 static int flow_stats_dump_callback(struct sw_flow *flow, void *private)
1264 struct flow_stats_state *s = private;
1265 struct ofp_flow_stats *ofs;
1269 actions_length = sizeof *ofs->actions * flow->n_actions;
1270 length = sizeof *ofs + sizeof *ofs->actions * flow->n_actions;
1271 if (length + s->bytes_used > s->bytes_allocated)
1274 ofs = s->body + s->bytes_used;
1275 ofs->length = htons(length);
1276 ofs->table_id = s->table_idx;
1278 ofs->match.wildcards = htonl(flow->key.wildcards);
1279 ofs->match.in_port = flow->key.in_port;
1280 memcpy(ofs->match.dl_src, flow->key.dl_src, ETH_ALEN);
1281 memcpy(ofs->match.dl_dst, flow->key.dl_dst, ETH_ALEN);
1282 ofs->match.dl_vlan = flow->key.dl_vlan;
1283 ofs->match.dl_type = flow->key.dl_type;
1284 ofs->match.nw_src = flow->key.nw_src;
1285 ofs->match.nw_dst = flow->key.nw_dst;
1286 ofs->match.nw_proto = flow->key.nw_proto;
1288 ofs->match.tp_src = flow->key.tp_src;
1289 ofs->match.tp_dst = flow->key.tp_dst;
1290 ofs->duration = htonl((jiffies - flow->init_time) / HZ);
1291 ofs->priority = htons(flow->priority);
1292 ofs->idle_timeout = htons(flow->idle_timeout);
1293 ofs->hard_timeout = htons(flow->hard_timeout);
1294 memset(ofs->pad2, 0, sizeof ofs->pad2);
1295 ofs->packet_count = cpu_to_be64(flow->packet_count);
1296 ofs->byte_count = cpu_to_be64(flow->byte_count);
1297 memcpy(ofs->actions, flow->actions, actions_length);
1299 s->bytes_used += length;
1303 static int flow_stats_dump(struct datapath *dp, void *state,
1304 void *body, int *body_len)
1306 struct flow_stats_state *s = state;
1307 struct sw_flow_key match_key;
1311 s->bytes_allocated = *body_len;
1314 flow_extract_match(&match_key, &s->rq->match);
1315 while (s->table_idx < dp->chain->n_tables
1316 && (s->rq->table_id == 0xff || s->rq->table_id == s->table_idx))
1318 struct sw_table *table = dp->chain->tables[s->table_idx];
1320 error = table->iterate(table, &match_key, &s->position,
1321 flow_stats_dump_callback, s);
1326 memset(&s->position, 0, sizeof s->position);
1328 *body_len = s->bytes_used;
1330 /* If error is 0, we're done.
1331 * Otherwise, if some bytes were used, there are more flows to come.
1332 * Otherwise, we were not able to fit even a single flow in the body,
1333 * which indicates that we have a single flow with too many actions to
1334 * fit. We won't ever make any progress at that rate, so give up. */
1335 return !error ? 0 : s->bytes_used ? 1 : -ENOMEM;
1338 static void flow_stats_done(void *state)
1343 static int aggregate_stats_init(struct datapath *dp,
1344 const void *body, int body_len,
1347 *state = (void *)body;
1351 static int aggregate_stats_dump_callback(struct sw_flow *flow, void *private)
1353 struct ofp_aggregate_stats_reply *rpy = private;
1354 rpy->packet_count += flow->packet_count;
1355 rpy->byte_count += flow->byte_count;
1360 static int aggregate_stats_dump(struct datapath *dp, void *state,
1361 void *body, int *body_len)
1363 struct ofp_aggregate_stats_request *rq = state;
1364 struct ofp_aggregate_stats_reply *rpy;
1365 struct sw_table_position position;
1366 struct sw_flow_key match_key;
1369 if (*body_len < sizeof *rpy)
1372 *body_len = sizeof *rpy;
1374 memset(rpy, 0, sizeof *rpy);
1376 flow_extract_match(&match_key, &rq->match);
1377 table_idx = rq->table_id == 0xff ? 0 : rq->table_id;
1378 memset(&position, 0, sizeof position);
1379 while (table_idx < dp->chain->n_tables
1380 && (rq->table_id == 0xff || rq->table_id == table_idx))
1382 struct sw_table *table = dp->chain->tables[table_idx];
1385 error = table->iterate(table, &match_key, &position,
1386 aggregate_stats_dump_callback, rpy);
1391 memset(&position, 0, sizeof position);
1394 rpy->packet_count = cpu_to_be64(rpy->packet_count);
1395 rpy->byte_count = cpu_to_be64(rpy->byte_count);
1396 rpy->flow_count = htonl(rpy->flow_count);
1400 static int table_stats_dump(struct datapath *dp, void *state,
1401 void *body, int *body_len)
1403 struct ofp_table_stats *ots;
1404 int n_bytes = dp->chain->n_tables * sizeof *ots;
1406 if (n_bytes > *body_len)
1408 *body_len = n_bytes;
1409 for (i = 0, ots = body; i < dp->chain->n_tables; i++, ots++) {
1410 struct sw_table_stats stats;
1411 dp->chain->tables[i]->stats(dp->chain->tables[i], &stats);
1412 strncpy(ots->name, stats.name, sizeof ots->name);
1414 memset(ots->pad, 0, sizeof ots->pad);
1415 ots->max_entries = htonl(stats.max_flows);
1416 ots->active_count = htonl(stats.n_flows);
1417 ots->matched_count = cpu_to_be64(stats.n_matched);
1422 struct port_stats_state {
1426 static int port_stats_init(struct datapath *dp, const void *body, int body_len,
1429 struct port_stats_state *s = kmalloc(sizeof *s, GFP_ATOMIC);
1437 static int port_stats_dump(struct datapath *dp, void *state,
1438 void *body, int *body_len)
1440 struct port_stats_state *s = state;
1441 struct ofp_port_stats *ops;
1442 int n_ports, max_ports;
1445 max_ports = *body_len / sizeof *ops;
1451 for (i = s->port; i < OFPP_MAX && n_ports < max_ports; i++) {
1452 struct net_bridge_port *p = dp->ports[i];
1453 struct net_device_stats *stats;
1456 stats = p->dev->get_stats(p->dev);
1457 ops->port_no = htons(p->port_no);
1458 memset(ops->pad, 0, sizeof ops->pad);
1459 ops->rx_packets = cpu_to_be64(stats->rx_packets);
1460 ops->tx_packets = cpu_to_be64(stats->tx_packets);
1461 ops->rx_bytes = cpu_to_be64(stats->rx_bytes);
1462 ops->tx_bytes = cpu_to_be64(stats->tx_bytes);
1463 ops->rx_dropped = cpu_to_be64(stats->rx_dropped);
1464 ops->tx_dropped = cpu_to_be64(stats->tx_dropped);
1465 ops->rx_errors = cpu_to_be64(stats->rx_errors);
1466 ops->tx_errors = cpu_to_be64(stats->tx_errors);
1467 ops->rx_frame_err = cpu_to_be64(stats->rx_frame_errors);
1468 ops->rx_over_err = cpu_to_be64(stats->rx_over_errors);
1469 ops->rx_crc_err = cpu_to_be64(stats->rx_crc_errors);
1470 ops->collisions = cpu_to_be64(stats->collisions);
1475 *body_len = n_ports * sizeof *ops;
1476 return n_ports >= max_ports;
1479 static void port_stats_done(void *state)
1485 /* Minimum and maximum acceptable number of bytes in body member of
1486 * struct ofp_stats_request. */
1487 size_t min_body, max_body;
1489 /* Prepares to dump some kind of statistics on 'dp'. 'body' and
1490 * 'body_len' are the 'body' member of the struct ofp_stats_request.
1491 * Returns zero if successful, otherwise a negative error code.
1492 * May initialize '*state' to state information. May be null if no
1493 * initialization is required.*/
1494 int (*init)(struct datapath *dp, const void *body, int body_len,
1497 /* Dumps statistics for 'dp' into the '*body_len' bytes at 'body', and
1498 * modifies '*body_len' to reflect the number of bytes actually used.
1499 * ('body' will be transmitted as the 'body' member of struct
1500 * ofp_stats_reply.) */
1501 int (*dump)(struct datapath *dp, void *state,
1502 void *body, int *body_len);
1504 /* Cleans any state created by the init or dump functions. May be null
1505 * if no cleanup is required. */
1506 void (*done)(void *state);
1509 static const struct stats_type stats[] = {
1518 sizeof(struct ofp_flow_stats_request),
1519 sizeof(struct ofp_flow_stats_request),
1524 [OFPST_AGGREGATE] = {
1525 sizeof(struct ofp_aggregate_stats_request),
1526 sizeof(struct ofp_aggregate_stats_request),
1527 aggregate_stats_init,
1528 aggregate_stats_dump,
1548 dp_genl_openflow_dumpit(struct sk_buff *skb, struct netlink_callback *cb)
1550 struct datapath *dp;
1551 struct sender sender;
1552 const struct stats_type *s;
1553 struct ofp_stats_reply *osr;
1555 int max_openflow_len, body_len;
1559 /* Set up the cleanup function for this dump. Linux 2.6.20 and later
1560 * support setting up cleanup functions via the .doneit member of
1561 * struct genl_ops. This kluge supports earlier versions also. */
1562 cb->done = dp_genl_openflow_done;
1565 struct nlattr *attrs[DP_GENL_A_MAX + 1];
1566 struct ofp_stats_request *rq;
1568 size_t len, body_len;
1571 err = nlmsg_parse(cb->nlh, GENL_HDRLEN, attrs, DP_GENL_A_MAX,
1572 dp_genl_openflow_policy);
1576 if (!attrs[DP_GENL_A_DP_IDX])
1578 dp_idx = nla_get_u16(attrs[DP_GENL_A_DP_IDX]);
1579 dp = dp_get(dp_idx);
1583 va = attrs[DP_GENL_A_OPENFLOW];
1585 if (!va || len < sizeof *rq)
1589 type = ntohs(rq->type);
1590 if (rq->header.version != OFP_VERSION
1591 || rq->header.type != OFPT_STATS_REQUEST
1592 || ntohs(rq->header.length) != len
1593 || type >= ARRAY_SIZE(stats)
1594 || !stats[type].dump)
1598 body_len = len - offsetof(struct ofp_stats_request, body);
1599 if (body_len < s->min_body || body_len > s->max_body)
1603 cb->args[1] = dp_idx;
1605 cb->args[3] = rq->header.xid;
1608 err = s->init(dp, rq->body, body_len, &state);
1611 cb->args[4] = (long) state;
1613 } else if (cb->args[0] == 1) {
1614 dp_idx = cb->args[1];
1615 s = &stats[cb->args[2]];
1617 dp = dp_get(dp_idx);
1624 sender.xid = cb->args[3];
1625 sender.pid = NETLINK_CB(cb->skb).pid;
1626 sender.seq = cb->nlh->nlmsg_seq;
1628 osr = put_openflow_headers(dp, skb, OFPT_STATS_REPLY, &sender,
1631 return PTR_ERR(osr);
1632 osr->type = htons(s - stats);
1634 resize_openflow_skb(skb, &osr->header, max_openflow_len);
1636 body_len = max_openflow_len - offsetof(struct ofp_stats_reply, body);
1638 err = s->dump(dp, (void *) cb->args[4], body, &body_len);
1643 osr->flags = ntohs(OFPSF_REPLY_MORE);
1644 resize_openflow_skb(skb, &osr->header,
1645 (offsetof(struct ofp_stats_reply, body)
1654 dp_genl_openflow_done(struct netlink_callback *cb)
1657 const struct stats_type *s = &stats[cb->args[2]];
1659 s->done((void *) cb->args[4]);
1664 static struct genl_ops dp_genl_ops_openflow = {
1665 .cmd = DP_GENL_C_OPENFLOW,
1666 .flags = GENL_ADMIN_PERM, /* Requires CAP_NET_ADMIN privilege. */
1667 .policy = dp_genl_openflow_policy,
1668 .doit = dp_genl_openflow,
1669 .dumpit = dp_genl_openflow_dumpit,
1672 static struct genl_ops *dp_genl_all_ops[] = {
1673 /* Keep this operation first. Generic Netlink dispatching
1674 * looks up operations with linear search, so we want it at the
1676 &dp_genl_ops_openflow,
1678 &dp_genl_ops_add_dp,
1679 &dp_genl_ops_del_dp,
1680 &dp_genl_ops_query_dp,
1681 &dp_genl_ops_add_port,
1682 &dp_genl_ops_del_port,
1685 static int dp_init_netlink(void)
1690 err = genl_register_family(&dp_genl_family);
1694 for (i = 0; i < ARRAY_SIZE(dp_genl_all_ops); i++) {
1695 err = genl_register_ops(&dp_genl_family, dp_genl_all_ops[i]);
1697 goto err_unregister;
1700 strcpy(mc_group.name, "openflow");
1701 err = genl_register_mc_group(&dp_genl_family, &mc_group);
1703 goto err_unregister;
1708 genl_unregister_family(&dp_genl_family);
1712 static void dp_uninit_netlink(void)
1714 genl_unregister_family(&dp_genl_family);
1717 static int __init dp_init(void)
1721 printk("OpenFlow "VERSION", built "__DATE__" "__TIME__", "
1722 "protocol 0x%02x\n", OFP_VERSION);
1728 err = dp_init_netlink();
1730 goto error_flow_exit;
1732 /* Hook into callback used by the bridge to intercept packets.
1733 * Parasites we are. */
1734 if (br_handle_frame_hook)
1735 printk("openflow: hijacking bridge hook\n");
1736 br_handle_frame_hook = dp_frame_hook;
1743 printk(KERN_EMERG "openflow: failed to install!");
1747 static void dp_cleanup(void)
1750 dp_uninit_netlink();
1752 br_handle_frame_hook = NULL;
1755 module_init(dp_init);
1756 module_exit(dp_cleanup);
1758 MODULE_DESCRIPTION("OpenFlow switching datapath");
1759 MODULE_AUTHOR("Copyright (c) 2007, 2008 The Board of Trustees of The Leland Stanford Junior University");
1760 MODULE_LICENSE("GPL");