2 * Copyright (c) 2007, 2008, 2009, 2010 Nicira Networks.
3 * Distributed under the terms of the GNU GPL version 2.
5 * Significant portions of this file may be copied from parts of the Linux
6 * kernel, by Linus Torvalds and others.
9 /* Functions for managing the dp interface/device. */
11 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
13 #include <linux/init.h>
14 #include <linux/module.h>
16 #include <linux/if_arp.h>
17 #include <linux/if_vlan.h>
20 #include <linux/delay.h>
21 #include <linux/time.h>
22 #include <linux/etherdevice.h>
23 #include <linux/kernel.h>
24 #include <linux/kthread.h>
25 #include <linux/mutex.h>
26 #include <linux/percpu.h>
27 #include <linux/rcupdate.h>
28 #include <linux/tcp.h>
29 #include <linux/udp.h>
30 #include <linux/version.h>
31 #include <linux/ethtool.h>
32 #include <linux/wait.h>
33 #include <asm/system.h>
34 #include <asm/div64.h>
36 #include <linux/highmem.h>
37 #include <linux/netfilter_bridge.h>
38 #include <linux/netfilter_ipv4.h>
39 #include <linux/inetdevice.h>
40 #include <linux/list.h>
41 #include <linux/rculist.h>
42 #include <linux/dmi.h>
43 #include <net/inet_ecn.h>
44 #include <linux/compat.h>
46 #include "openvswitch/datapath-protocol.h"
51 #include "loop_counter.h"
52 #include "odp-compat.h"
54 #include "vport-internal_dev.h"
58 int (*dp_ioctl_hook)(struct net_device *dev, struct ifreq *rq, int cmd);
59 EXPORT_SYMBOL(dp_ioctl_hook);
61 /* Datapaths. Protected on the read side by rcu_read_lock, on the write side
64 * dp_mutex nests inside the RTNL lock: if you need both you must take the RTNL
67 * It is safe to access the datapath and vport structures with just
70 static struct datapath __rcu *dps[ODP_MAX];
71 static DEFINE_MUTEX(dp_mutex);
73 static int new_vport(struct datapath *, struct odp_port *, int port_no);
75 /* Must be called with rcu_read_lock or dp_mutex. */
76 struct datapath *get_dp(int dp_idx)
78 if (dp_idx < 0 || dp_idx >= ODP_MAX)
80 return rcu_dereference_check(dps[dp_idx], rcu_read_lock_held() ||
81 lockdep_is_held(&dp_mutex));
83 EXPORT_SYMBOL_GPL(get_dp);
85 static struct datapath *get_dp_locked(int dp_idx)
89 mutex_lock(&dp_mutex);
92 mutex_lock(&dp->mutex);
93 mutex_unlock(&dp_mutex);
97 static struct tbl *get_table_protected(struct datapath *dp)
99 return rcu_dereference_protected(dp->table,
100 lockdep_is_held(&dp->mutex));
103 static struct vport *get_vport_protected(struct datapath *dp, u16 port_no)
105 return rcu_dereference_protected(dp->ports[port_no],
106 lockdep_is_held(&dp->mutex));
109 /* Must be called with rcu_read_lock or RTNL lock. */
110 const char *dp_name(const struct datapath *dp)
112 return vport_get_name(rcu_dereference_rtnl(dp->ports[ODPP_LOCAL]));
115 static inline size_t br_nlmsg_size(void)
117 return NLMSG_ALIGN(sizeof(struct ifinfomsg))
118 + nla_total_size(IFNAMSIZ) /* IFLA_IFNAME */
119 + nla_total_size(MAX_ADDR_LEN) /* IFLA_ADDRESS */
120 + nla_total_size(4) /* IFLA_MASTER */
121 + nla_total_size(4) /* IFLA_MTU */
122 + nla_total_size(4) /* IFLA_LINK */
123 + nla_total_size(1); /* IFLA_OPERSTATE */
126 static int dp_fill_ifinfo(struct sk_buff *skb,
127 const struct vport *port,
128 int event, unsigned int flags)
130 struct datapath *dp = port->dp;
131 int ifindex = vport_get_ifindex(port);
132 int iflink = vport_get_iflink(port);
133 struct ifinfomsg *hdr;
134 struct nlmsghdr *nlh;
142 nlh = nlmsg_put(skb, 0, 0, event, sizeof(*hdr), flags);
146 hdr = nlmsg_data(nlh);
147 hdr->ifi_family = AF_BRIDGE;
149 hdr->ifi_type = ARPHRD_ETHER;
150 hdr->ifi_index = ifindex;
151 hdr->ifi_flags = vport_get_flags(port);
154 NLA_PUT_STRING(skb, IFLA_IFNAME, vport_get_name(port));
155 NLA_PUT_U32(skb, IFLA_MASTER,
156 vport_get_ifindex(get_vport_protected(dp, ODPP_LOCAL)));
157 NLA_PUT_U32(skb, IFLA_MTU, vport_get_mtu(port));
158 #ifdef IFLA_OPERSTATE
159 NLA_PUT_U8(skb, IFLA_OPERSTATE,
160 vport_is_running(port)
161 ? vport_get_operstate(port)
165 NLA_PUT(skb, IFLA_ADDRESS, ETH_ALEN, vport_get_addr(port));
167 if (ifindex != iflink)
168 NLA_PUT_U32(skb, IFLA_LINK,iflink);
170 return nlmsg_end(skb, nlh);
173 nlmsg_cancel(skb, nlh);
177 static void dp_ifinfo_notify(int event, struct vport *port)
182 skb = nlmsg_new(br_nlmsg_size(), GFP_KERNEL);
186 err = dp_fill_ifinfo(skb, port, event, 0);
188 /* -EMSGSIZE implies BUG in br_nlmsg_size() */
189 WARN_ON(err == -EMSGSIZE);
193 rtnl_notify(skb, &init_net, 0, RTNLGRP_LINK, NULL, GFP_KERNEL);
197 rtnl_set_sk_err(&init_net, RTNLGRP_LINK, err);
200 static void release_dp(struct kobject *kobj)
202 struct datapath *dp = container_of(kobj, struct datapath, ifobj);
206 static struct kobj_type dp_ktype = {
207 .release = release_dp
210 static int create_dp(int dp_idx, const char __user *devnamep)
212 struct odp_port internal_dev_port;
213 char devname[IFNAMSIZ];
219 int retval = strncpy_from_user(devname, devnamep, IFNAMSIZ);
223 } else if (retval >= IFNAMSIZ) {
228 snprintf(devname, sizeof devname, "of%d", dp_idx);
232 mutex_lock(&dp_mutex);
234 if (!try_module_get(THIS_MODULE))
237 /* Exit early if a datapath with that number already exists.
238 * (We don't use -EEXIST because that's ambiguous with 'devname'
239 * conflicting with an existing network device name.) */
245 dp = kzalloc(sizeof *dp, GFP_KERNEL);
248 INIT_LIST_HEAD(&dp->port_list);
249 mutex_init(&dp->mutex);
250 mutex_lock(&dp->mutex);
252 for (i = 0; i < DP_N_QUEUES; i++)
253 skb_queue_head_init(&dp->queues[i]);
254 init_waitqueue_head(&dp->waitqueue);
256 /* Initialize kobject for bridge. This will be added as
257 * /sys/class/net/<devname>/brif later, if sysfs is enabled. */
258 dp->ifobj.kset = NULL;
259 kobject_init(&dp->ifobj, &dp_ktype);
261 /* Allocate table. */
263 rcu_assign_pointer(dp->table, tbl_create(TBL_MIN_BUCKETS));
267 /* Set up our datapath device. */
268 BUILD_BUG_ON(sizeof(internal_dev_port.devname) != sizeof(devname));
269 strcpy(internal_dev_port.devname, devname);
270 strcpy(internal_dev_port.type, "internal");
271 err = new_vport(dp, &internal_dev_port, ODPP_LOCAL);
276 goto err_destroy_table;
280 dp->stats_percpu = alloc_percpu(struct dp_stats_percpu);
281 if (!dp->stats_percpu) {
283 goto err_destroy_local_port;
286 rcu_assign_pointer(dps[dp_idx], dp);
289 mutex_unlock(&dp->mutex);
290 mutex_unlock(&dp_mutex);
295 err_destroy_local_port:
296 dp_detach_port(get_vport_protected(dp, ODPP_LOCAL));
298 tbl_destroy(get_table_protected(dp), NULL);
300 mutex_unlock(&dp->mutex);
303 module_put(THIS_MODULE);
305 mutex_unlock(&dp_mutex);
311 static void destroy_dp_rcu(struct rcu_head *rcu)
313 struct datapath *dp = container_of(rcu, struct datapath, rcu);
316 for (i = 0; i < DP_N_QUEUES; i++)
317 skb_queue_purge(&dp->queues[i]);
319 tbl_destroy((struct tbl __force *)dp->table, flow_free_tbl);
320 free_percpu(dp->stats_percpu);
321 kobject_put(&dp->ifobj);
324 static int destroy_dp(int dp_idx)
331 mutex_lock(&dp_mutex);
338 mutex_lock(&dp->mutex);
340 list_for_each_entry_safe (p, n, &dp->port_list, node)
341 if (p->port_no != ODPP_LOCAL)
345 rcu_assign_pointer(dps[dp->dp_idx], NULL);
346 dp_detach_port(get_vport_protected(dp, ODPP_LOCAL));
348 mutex_unlock(&dp->mutex);
349 call_rcu(&dp->rcu, destroy_dp_rcu);
350 module_put(THIS_MODULE);
353 mutex_unlock(&dp_mutex);
358 /* Called with RTNL lock and dp->mutex. */
359 static int new_vport(struct datapath *dp, struct odp_port *odp_port, int port_no)
361 struct vport_parms parms;
364 parms.name = odp_port->devname;
365 parms.type = odp_port->type;
366 parms.config = odp_port->config;
368 parms.port_no = port_no;
371 vport = vport_add(&parms);
375 return PTR_ERR(vport);
377 rcu_assign_pointer(dp->ports[port_no], vport);
378 list_add_rcu(&vport->node, &dp->port_list);
381 dp_ifinfo_notify(RTM_NEWLINK, vport);
386 static int attach_port(int dp_idx, struct odp_port __user *portp)
389 struct odp_port port;
394 if (copy_from_user(&port, portp, sizeof port))
396 port.devname[IFNAMSIZ - 1] = '\0';
397 port.type[VPORT_TYPE_SIZE - 1] = '\0';
400 dp = get_dp_locked(dp_idx);
403 goto out_unlock_rtnl;
405 for (port_no = 1; port_no < DP_MAX_PORTS; port_no++)
406 if (!dp->ports[port_no])
412 err = new_vport(dp, &port, port_no);
416 set_internal_devs_mtu(dp);
417 dp_sysfs_add_if(get_vport_protected(dp, port_no));
419 err = put_user(port_no, &portp->port);
422 mutex_unlock(&dp->mutex);
429 int dp_detach_port(struct vport *p)
435 if (p->port_no != ODPP_LOCAL)
437 dp_ifinfo_notify(RTM_DELLINK, p);
439 /* First drop references to device. */
441 list_del_rcu(&p->node);
442 rcu_assign_pointer(p->dp->ports[p->port_no], NULL);
444 /* Then destroy it. */
452 static int detach_port(int dp_idx, int port_no)
459 if (port_no < 0 || port_no >= DP_MAX_PORTS || port_no == ODPP_LOCAL)
463 dp = get_dp_locked(dp_idx);
466 goto out_unlock_rtnl;
468 p = get_vport_protected(dp, port_no);
473 err = dp_detach_port(p);
476 mutex_unlock(&dp->mutex);
483 /* Must be called with rcu_read_lock. */
484 void dp_process_received_packet(struct vport *p, struct sk_buff *skb)
486 struct datapath *dp = p->dp;
487 struct dp_stats_percpu *stats;
488 int stats_counter_off;
489 struct sw_flow_actions *acts;
490 struct loop_counter *loop;
493 OVS_CB(skb)->vport = p;
495 if (!OVS_CB(skb)->flow) {
496 struct odp_flow_key key;
497 struct tbl_node *flow_node;
500 /* Extract flow from 'skb' into 'key'. */
501 error = flow_extract(skb, p ? p->port_no : ODPP_NONE, &key, &is_frag);
502 if (unlikely(error)) {
507 if (is_frag && dp->drop_frags) {
509 stats_counter_off = offsetof(struct dp_stats_percpu, n_frags);
514 flow_node = tbl_lookup(rcu_dereference(dp->table), &key,
515 flow_hash(&key), flow_cmp);
516 if (unlikely(!flow_node)) {
517 dp_output_control(dp, skb, _ODPL_MISS_NR,
518 (__force u64)OVS_CB(skb)->tun_id);
519 stats_counter_off = offsetof(struct dp_stats_percpu, n_missed);
523 OVS_CB(skb)->flow = flow_cast(flow_node);
526 stats_counter_off = offsetof(struct dp_stats_percpu, n_hit);
527 flow_used(OVS_CB(skb)->flow, skb);
529 acts = rcu_dereference(OVS_CB(skb)->flow->sf_acts);
531 /* Check whether we've looped too much. */
532 loop = loop_get_counter();
533 if (unlikely(++loop->count > MAX_LOOPS))
534 loop->looping = true;
535 if (unlikely(loop->looping)) {
536 loop_suppress(dp, acts);
541 /* Execute actions. */
542 execute_actions(dp, skb, &OVS_CB(skb)->flow->key, acts->actions,
545 /* Check whether sub-actions looped too much. */
546 if (unlikely(loop->looping))
547 loop_suppress(dp, acts);
550 /* Decrement loop counter. */
552 loop->looping = false;
556 /* Update datapath statistics. */
558 stats = per_cpu_ptr(dp->stats_percpu, smp_processor_id());
560 write_seqcount_begin(&stats->seqlock);
561 (*(u64 *)((u8 *)stats + stats_counter_off))++;
562 write_seqcount_end(&stats->seqlock);
567 /* Append each packet in 'skb' list to 'queue'. There will be only one packet
568 * unless we broke up a GSO packet. */
569 static int queue_control_packets(struct sk_buff *skb, struct sk_buff_head *queue,
570 int queue_no, u64 arg)
572 struct sk_buff *nskb;
576 if (OVS_CB(skb)->vport)
577 port_no = OVS_CB(skb)->vport->port_no;
579 port_no = ODPP_LOCAL;
582 struct odp_msg *header;
587 err = skb_cow(skb, sizeof *header);
591 header = (struct odp_msg*)__skb_push(skb, sizeof *header);
592 header->type = queue_no;
593 header->length = skb->len;
594 header->port = port_no;
596 skb_queue_tail(queue, skb);
604 while ((skb = nskb) != NULL) {
611 int dp_output_control(struct datapath *dp, struct sk_buff *skb, int queue_no,
614 struct dp_stats_percpu *stats;
615 struct sk_buff_head *queue;
618 WARN_ON_ONCE(skb_shared(skb));
619 BUG_ON(queue_no != _ODPL_MISS_NR && queue_no != _ODPL_ACTION_NR && queue_no != _ODPL_SFLOW_NR);
620 queue = &dp->queues[queue_no];
622 if (skb_queue_len(queue) >= DP_MAX_QUEUE_LEN)
625 forward_ip_summed(skb);
627 err = vswitch_skb_checksum_setup(skb);
631 /* Break apart GSO packets into their component pieces. Otherwise
632 * userspace may try to stuff a 64kB packet into a 1500-byte MTU. */
633 if (skb_is_gso(skb)) {
634 struct sk_buff *nskb = skb_gso_segment(skb, NETIF_F_SG | NETIF_F_HW_CSUM);
644 err = queue_control_packets(skb, queue, queue_no, arg);
645 wake_up_interruptible(&dp->waitqueue);
652 stats = per_cpu_ptr(dp->stats_percpu, smp_processor_id());
654 write_seqcount_begin(&stats->seqlock);
656 write_seqcount_end(&stats->seqlock);
663 static int flush_flows(struct datapath *dp)
665 struct tbl *old_table = get_table_protected(dp);
666 struct tbl *new_table;
668 new_table = tbl_create(TBL_MIN_BUCKETS);
672 rcu_assign_pointer(dp->table, new_table);
674 tbl_deferred_destroy(old_table, flow_free_tbl);
679 static int validate_actions(const struct nlattr *actions, u32 actions_len)
681 const struct nlattr *a;
684 nla_for_each_attr(a, actions, actions_len, rem) {
685 static const u32 action_lens[ODPAT_MAX + 1] = {
687 [ODPAT_CONTROLLER] = 8,
688 [ODPAT_SET_DL_TCI] = 2,
689 [ODPAT_STRIP_VLAN] = 0,
690 [ODPAT_SET_DL_SRC] = ETH_ALEN,
691 [ODPAT_SET_DL_DST] = ETH_ALEN,
692 [ODPAT_SET_NW_SRC] = 4,
693 [ODPAT_SET_NW_DST] = 4,
694 [ODPAT_SET_NW_TOS] = 1,
695 [ODPAT_SET_TP_SRC] = 2,
696 [ODPAT_SET_TP_DST] = 2,
697 [ODPAT_SET_TUNNEL] = 8,
698 [ODPAT_SET_PRIORITY] = 4,
699 [ODPAT_POP_PRIORITY] = 0,
700 [ODPAT_DROP_SPOOFED_ARP] = 0,
702 int type = nla_type(a);
704 if (type > ODPAT_MAX || nla_len(a) != action_lens[type])
711 case ODPAT_CONTROLLER:
712 case ODPAT_STRIP_VLAN:
713 case ODPAT_SET_DL_SRC:
714 case ODPAT_SET_DL_DST:
715 case ODPAT_SET_NW_SRC:
716 case ODPAT_SET_NW_DST:
717 case ODPAT_SET_TP_SRC:
718 case ODPAT_SET_TP_DST:
719 case ODPAT_SET_TUNNEL:
720 case ODPAT_SET_PRIORITY:
721 case ODPAT_POP_PRIORITY:
722 case ODPAT_DROP_SPOOFED_ARP:
723 /* No validation needed. */
727 if (nla_get_u32(a) >= DP_MAX_PORTS)
730 case ODPAT_SET_DL_TCI:
731 if (nla_get_be16(a) & htons(VLAN_CFI_MASK))
735 case ODPAT_SET_NW_TOS:
736 if (nla_get_u8(a) & INET_ECN_MASK)
751 static struct sw_flow_actions *get_actions(const struct odp_flow *flow)
753 struct sw_flow_actions *actions;
756 actions = flow_actions_alloc(flow->actions_len);
757 error = PTR_ERR(actions);
762 if (copy_from_user(actions->actions,
763 (struct nlattr __user __force *)flow->actions,
765 goto error_free_actions;
766 error = validate_actions(actions->actions, actions->actions_len);
768 goto error_free_actions;
775 return ERR_PTR(error);
778 static void get_stats(struct sw_flow *flow, struct odp_flow_stats *stats)
781 struct timespec offset_ts, used, now_mono;
783 ktime_get_ts(&now_mono);
784 jiffies_to_timespec(jiffies - flow->used, &offset_ts);
785 set_normalized_timespec(&used, now_mono.tv_sec - offset_ts.tv_sec,
786 now_mono.tv_nsec - offset_ts.tv_nsec);
788 stats->used_sec = used.tv_sec;
789 stats->used_nsec = used.tv_nsec;
792 stats->used_nsec = 0;
795 stats->n_packets = flow->packet_count;
796 stats->n_bytes = flow->byte_count;
798 stats->tcp_flags = flow->tcp_flags;
802 static void clear_stats(struct sw_flow *flow)
806 flow->packet_count = 0;
807 flow->byte_count = 0;
810 static int expand_table(struct datapath *dp)
812 struct tbl *old_table = get_table_protected(dp);
813 struct tbl *new_table;
815 new_table = tbl_expand(old_table);
816 if (IS_ERR(new_table))
817 return PTR_ERR(new_table);
819 rcu_assign_pointer(dp->table, new_table);
820 tbl_deferred_destroy(old_table, NULL);
825 static int do_put_flow(struct datapath *dp, struct odp_flow_put *uf,
826 struct odp_flow_stats *stats)
828 struct tbl_node *flow_node;
829 struct sw_flow *flow;
831 struct sw_flow_actions *acts = NULL;
835 hash = flow_hash(&uf->flow.key);
836 table = get_table_protected(dp);
837 flow_node = tbl_lookup(table, &uf->flow.key, hash, flow_cmp);
841 if (!(uf->flags & ODPPF_CREATE))
844 /* Expand table, if necessary, to make room. */
845 if (tbl_count(table) >= tbl_n_buckets(table)) {
846 error = expand_table(dp);
849 table = get_table_protected(dp);
855 error = PTR_ERR(flow);
858 flow->key = uf->flow.key;
861 /* Obtain actions. */
862 acts = get_actions(&uf->flow);
863 error = PTR_ERR(acts);
865 goto error_free_flow;
866 rcu_assign_pointer(flow->sf_acts, acts);
868 /* Put flow in bucket. */
869 error = tbl_insert(table, &flow->tbl_node, hash);
871 goto error_free_flow_acts;
873 memset(stats, 0, sizeof(struct odp_flow_stats));
875 /* We found a matching flow. */
876 struct sw_flow_actions *old_acts, *new_acts;
878 flow = flow_cast(flow_node);
880 /* Bail out if we're not allowed to modify an existing flow. */
882 if (!(uf->flags & ODPPF_MODIFY))
886 new_acts = get_actions(&uf->flow);
887 error = PTR_ERR(new_acts);
888 if (IS_ERR(new_acts))
891 old_acts = rcu_dereference_protected(flow->sf_acts,
892 lockdep_is_held(&dp->mutex));
893 if (old_acts->actions_len != new_acts->actions_len ||
894 memcmp(old_acts->actions, new_acts->actions,
895 old_acts->actions_len)) {
896 rcu_assign_pointer(flow->sf_acts, new_acts);
897 flow_deferred_free_acts(old_acts);
902 /* Fetch stats, then clear them if necessary. */
903 spin_lock_bh(&flow->lock);
904 get_stats(flow, stats);
905 if (uf->flags & ODPPF_ZERO_STATS)
907 spin_unlock_bh(&flow->lock);
912 error_free_flow_acts:
915 flow->sf_acts = NULL;
921 static int put_flow(struct datapath *dp, struct odp_flow_put __user *ufp)
923 struct odp_flow_stats stats;
924 struct odp_flow_put uf;
927 if (copy_from_user(&uf, ufp, sizeof(struct odp_flow_put)))
930 error = do_put_flow(dp, &uf, &stats);
934 if (copy_to_user(&ufp->flow.stats, &stats,
935 sizeof(struct odp_flow_stats)))
941 static int do_answer_query(struct datapath *dp, struct sw_flow *flow,
943 struct odp_flow_stats __user *ustats,
944 struct nlattr __user *actions,
945 u32 __user *actions_lenp)
947 struct sw_flow_actions *sf_acts;
948 struct odp_flow_stats stats;
951 spin_lock_bh(&flow->lock);
952 get_stats(flow, &stats);
953 if (query_flags & ODPFF_ZERO_TCP_FLAGS)
956 spin_unlock_bh(&flow->lock);
958 if (copy_to_user(ustats, &stats, sizeof(struct odp_flow_stats)) ||
959 get_user(actions_len, actions_lenp))
965 sf_acts = rcu_dereference_protected(flow->sf_acts,
966 lockdep_is_held(&dp->mutex));
967 if (put_user(sf_acts->actions_len, actions_lenp) ||
968 (actions && copy_to_user(actions, sf_acts->actions,
969 min(sf_acts->actions_len, actions_len))))
975 static int answer_query(struct datapath *dp, struct sw_flow *flow,
976 u32 query_flags, struct odp_flow __user *ufp)
978 struct nlattr __user *actions;
980 if (get_user(actions, (struct nlattr __user * __user *)&ufp->actions))
983 return do_answer_query(dp, flow, query_flags,
984 &ufp->stats, actions, &ufp->actions_len);
987 static struct sw_flow *do_del_flow(struct datapath *dp, struct odp_flow_key *key)
989 struct tbl *table = get_table_protected(dp);
990 struct tbl_node *flow_node;
993 flow_node = tbl_lookup(table, key, flow_hash(key), flow_cmp);
995 return ERR_PTR(-ENOENT);
997 error = tbl_remove(table, flow_node);
999 return ERR_PTR(error);
1001 /* XXX Returned flow_node's statistics might lose a few packets, since
1002 * other CPUs can be using this flow. We used to synchronize_rcu() to
1003 * make sure that we get completely accurate stats, but that blows our
1004 * performance, badly. */
1005 return flow_cast(flow_node);
1008 static int del_flow(struct datapath *dp, struct odp_flow __user *ufp)
1010 struct sw_flow *flow;
1014 if (copy_from_user(&uf, ufp, sizeof uf))
1017 flow = do_del_flow(dp, &uf.key);
1019 return PTR_ERR(flow);
1021 error = answer_query(dp, flow, 0, ufp);
1022 flow_deferred_free(flow);
1026 static int do_query_flows(struct datapath *dp, const struct odp_flowvec *flowvec)
1028 struct tbl *table = get_table_protected(dp);
1031 for (i = 0; i < flowvec->n_flows; i++) {
1032 struct odp_flow __user *ufp = (struct odp_flow __user __force *)&flowvec->flows[i];
1034 struct tbl_node *flow_node;
1037 if (copy_from_user(&uf, ufp, sizeof uf))
1040 flow_node = tbl_lookup(table, &uf.key, flow_hash(&uf.key), flow_cmp);
1042 error = put_user(ENOENT, &ufp->stats.error);
1044 error = answer_query(dp, flow_cast(flow_node), uf.flags, ufp);
1048 return flowvec->n_flows;
1051 struct list_flows_cbdata {
1052 struct datapath *dp;
1053 struct odp_flow __user *uflows;
1058 static int list_flow(struct tbl_node *node, void *cbdata_)
1060 struct sw_flow *flow = flow_cast(node);
1061 struct list_flows_cbdata *cbdata = cbdata_;
1062 struct odp_flow __user *ufp = &cbdata->uflows[cbdata->listed_flows++];
1065 if (copy_to_user(&ufp->key, &flow->key, sizeof flow->key))
1067 error = answer_query(cbdata->dp, flow, 0, ufp);
1071 if (cbdata->listed_flows >= cbdata->n_flows)
1072 return cbdata->listed_flows;
1076 static int do_list_flows(struct datapath *dp, const struct odp_flowvec *flowvec)
1078 struct list_flows_cbdata cbdata;
1081 if (!flowvec->n_flows)
1085 cbdata.uflows = (struct odp_flow __user __force*)flowvec->flows;
1086 cbdata.n_flows = flowvec->n_flows;
1087 cbdata.listed_flows = 0;
1089 error = tbl_foreach(get_table_protected(dp), list_flow, &cbdata);
1090 return error ? error : cbdata.listed_flows;
1093 static int do_flowvec_ioctl(struct datapath *dp, unsigned long argp,
1094 int (*function)(struct datapath *,
1095 const struct odp_flowvec *))
1097 struct odp_flowvec __user *uflowvec;
1098 struct odp_flowvec flowvec;
1101 uflowvec = (struct odp_flowvec __user *)argp;
1102 if (copy_from_user(&flowvec, uflowvec, sizeof flowvec))
1105 if (flowvec.n_flows > INT_MAX / sizeof(struct odp_flow))
1108 retval = function(dp, &flowvec);
1109 return (retval < 0 ? retval
1110 : retval == flowvec.n_flows ? 0
1111 : put_user(retval, &uflowvec->n_flows));
1114 static int do_execute(struct datapath *dp, const struct odp_execute *execute)
1116 struct odp_flow_key key;
1117 struct sk_buff *skb;
1118 struct sw_flow_actions *actions;
1124 if (execute->length < ETH_HLEN || execute->length > 65535)
1127 actions = flow_actions_alloc(execute->actions_len);
1128 if (IS_ERR(actions)) {
1129 err = PTR_ERR(actions);
1134 if (copy_from_user(actions->actions,
1135 (struct nlattr __user __force *)execute->actions, execute->actions_len))
1136 goto error_free_actions;
1138 err = validate_actions(actions->actions, execute->actions_len);
1140 goto error_free_actions;
1143 skb = alloc_skb(execute->length, GFP_KERNEL);
1145 goto error_free_actions;
1148 if (copy_from_user(skb_put(skb, execute->length),
1149 (const void __user __force *)execute->data,
1151 goto error_free_skb;
1153 skb_reset_mac_header(skb);
1156 /* Normally, setting the skb 'protocol' field would be handled by a
1157 * call to eth_type_trans(), but it assumes there's a sending
1158 * device, which we may not have. */
1159 if (ntohs(eth->h_proto) >= 1536)
1160 skb->protocol = eth->h_proto;
1162 skb->protocol = htons(ETH_P_802_2);
1164 err = flow_extract(skb, -1, &key, &is_frag);
1166 goto error_free_skb;
1169 err = execute_actions(dp, skb, &key, actions->actions, actions->actions_len);
1183 static int execute_packet(struct datapath *dp, const struct odp_execute __user *executep)
1185 struct odp_execute execute;
1187 if (copy_from_user(&execute, executep, sizeof execute))
1190 return do_execute(dp, &execute);
1193 static int get_dp_stats(struct datapath *dp, struct odp_stats __user *statsp)
1195 struct tbl *table = get_table_protected(dp);
1196 struct odp_stats stats;
1199 stats.n_flows = tbl_count(table);
1200 stats.cur_capacity = tbl_n_buckets(table);
1201 stats.max_capacity = TBL_MAX_BUCKETS;
1202 stats.n_ports = dp->n_ports;
1203 stats.max_ports = DP_MAX_PORTS;
1204 stats.n_frags = stats.n_hit = stats.n_missed = stats.n_lost = 0;
1205 for_each_possible_cpu(i) {
1206 const struct dp_stats_percpu *percpu_stats;
1207 struct dp_stats_percpu local_stats;
1210 percpu_stats = per_cpu_ptr(dp->stats_percpu, i);
1213 seqcount = read_seqcount_begin(&percpu_stats->seqlock);
1214 local_stats = *percpu_stats;
1215 } while (read_seqcount_retry(&percpu_stats->seqlock, seqcount));
1217 stats.n_frags += local_stats.n_frags;
1218 stats.n_hit += local_stats.n_hit;
1219 stats.n_missed += local_stats.n_missed;
1220 stats.n_lost += local_stats.n_lost;
1222 stats.max_miss_queue = DP_MAX_QUEUE_LEN;
1223 stats.max_action_queue = DP_MAX_QUEUE_LEN;
1224 return copy_to_user(statsp, &stats, sizeof stats) ? -EFAULT : 0;
1227 /* MTU of the dp pseudo-device: ETH_DATA_LEN or the minimum of the ports */
1228 int dp_min_mtu(const struct datapath *dp)
1235 list_for_each_entry_rcu (p, &dp->port_list, node) {
1238 /* Skip any internal ports, since that's what we're trying to
1240 if (is_internal_vport(p))
1243 dev_mtu = vport_get_mtu(p);
1244 if (!mtu || dev_mtu < mtu)
1248 return mtu ? mtu : ETH_DATA_LEN;
1251 /* Sets the MTU of all datapath devices to the minimum of the ports. Must
1252 * be called with RTNL lock. */
1253 void set_internal_devs_mtu(const struct datapath *dp)
1260 mtu = dp_min_mtu(dp);
1262 list_for_each_entry_rcu (p, &dp->port_list, node) {
1263 if (is_internal_vport(p))
1264 vport_set_mtu(p, mtu);
1268 static int put_port(const struct vport *p, struct odp_port __user *uop)
1272 memset(&op, 0, sizeof op);
1275 strncpy(op.devname, vport_get_name(p), sizeof op.devname);
1276 strncpy(op.type, vport_get_type(p), sizeof op.type);
1277 vport_get_config(p, op.config);
1280 op.port = p->port_no;
1282 return copy_to_user(uop, &op, sizeof op) ? -EFAULT : 0;
1285 static int query_port(struct datapath *dp, struct odp_port __user *uport)
1287 struct odp_port port;
1288 struct vport *vport;
1290 if (copy_from_user(&port, uport, sizeof port))
1293 if (port.devname[0]) {
1294 port.devname[IFNAMSIZ - 1] = '\0';
1297 vport = vport_locate(port.devname);
1302 if (vport->dp != dp)
1305 if (port.port >= DP_MAX_PORTS)
1308 vport = get_vport_protected(dp, port.port);
1313 return put_port(vport, uport);
1316 static int do_list_ports(struct datapath *dp, struct odp_port __user *uports,
1323 list_for_each_entry_rcu (p, &dp->port_list, node) {
1324 if (put_port(p, &uports[idx]))
1326 if (idx++ >= n_ports)
1333 static int list_ports(struct datapath *dp, struct odp_portvec __user *upv)
1335 struct odp_portvec pv;
1338 if (copy_from_user(&pv, upv, sizeof pv))
1341 retval = do_list_ports(dp, (struct odp_port __user __force *)pv.ports,
1346 return put_user(retval, &upv->n_ports);
1349 static int get_listen_mask(const struct file *f)
1351 return (long)f->private_data;
1354 static void set_listen_mask(struct file *f, int listen_mask)
1356 f->private_data = (void*)(long)listen_mask;
1359 static long openvswitch_ioctl(struct file *f, unsigned int cmd,
1362 int dp_idx = iminor(f->f_dentry->d_inode);
1363 struct datapath *dp;
1364 int drop_frags, listeners, port_no;
1365 unsigned int sflow_probability;
1368 /* Handle commands with special locking requirements up front. */
1371 err = create_dp(dp_idx, (char __user *)argp);
1374 case ODP_DP_DESTROY:
1375 err = destroy_dp(dp_idx);
1378 case ODP_VPORT_ATTACH:
1379 err = attach_port(dp_idx, (struct odp_port __user *)argp);
1382 case ODP_VPORT_DETACH:
1383 err = get_user(port_no, (int __user *)argp);
1385 err = detach_port(dp_idx, port_no);
1389 err = vport_user_mod((struct odp_port __user *)argp);
1392 case ODP_VPORT_STATS_GET:
1393 err = vport_user_stats_get((struct odp_vport_stats_req __user *)argp);
1396 case ODP_VPORT_STATS_SET:
1397 err = vport_user_stats_set((struct odp_vport_stats_req __user *)argp);
1400 case ODP_VPORT_ETHER_GET:
1401 err = vport_user_ether_get((struct odp_vport_ether __user *)argp);
1404 case ODP_VPORT_ETHER_SET:
1405 err = vport_user_ether_set((struct odp_vport_ether __user *)argp);
1408 case ODP_VPORT_MTU_GET:
1409 err = vport_user_mtu_get((struct odp_vport_mtu __user *)argp);
1412 case ODP_VPORT_MTU_SET:
1413 err = vport_user_mtu_set((struct odp_vport_mtu __user *)argp);
1417 dp = get_dp_locked(dp_idx);
1424 err = get_dp_stats(dp, (struct odp_stats __user *)argp);
1427 case ODP_GET_DROP_FRAGS:
1428 err = put_user(dp->drop_frags, (int __user *)argp);
1431 case ODP_SET_DROP_FRAGS:
1432 err = get_user(drop_frags, (int __user *)argp);
1436 if (drop_frags != 0 && drop_frags != 1)
1438 dp->drop_frags = drop_frags;
1442 case ODP_GET_LISTEN_MASK:
1443 err = put_user(get_listen_mask(f), (int __user *)argp);
1446 case ODP_SET_LISTEN_MASK:
1447 err = get_user(listeners, (int __user *)argp);
1451 if (listeners & ~ODPL_ALL)
1454 set_listen_mask(f, listeners);
1457 case ODP_GET_SFLOW_PROBABILITY:
1458 err = put_user(dp->sflow_probability, (unsigned int __user *)argp);
1461 case ODP_SET_SFLOW_PROBABILITY:
1462 err = get_user(sflow_probability, (unsigned int __user *)argp);
1464 dp->sflow_probability = sflow_probability;
1467 case ODP_VPORT_QUERY:
1468 err = query_port(dp, (struct odp_port __user *)argp);
1471 case ODP_VPORT_LIST:
1472 err = list_ports(dp, (struct odp_portvec __user *)argp);
1475 case ODP_FLOW_FLUSH:
1476 err = flush_flows(dp);
1480 err = put_flow(dp, (struct odp_flow_put __user *)argp);
1484 err = del_flow(dp, (struct odp_flow __user *)argp);
1488 err = do_flowvec_ioctl(dp, argp, do_query_flows);
1492 err = do_flowvec_ioctl(dp, argp, do_list_flows);
1496 err = execute_packet(dp, (struct odp_execute __user *)argp);
1503 mutex_unlock(&dp->mutex);
1508 static int dp_has_packet_of_interest(struct datapath *dp, int listeners)
1511 for (i = 0; i < DP_N_QUEUES; i++) {
1512 if (listeners & (1 << i) && !skb_queue_empty(&dp->queues[i]))
1518 #ifdef CONFIG_COMPAT
1519 static int compat_list_ports(struct datapath *dp, struct compat_odp_portvec __user *upv)
1521 struct compat_odp_portvec pv;
1524 if (copy_from_user(&pv, upv, sizeof pv))
1527 retval = do_list_ports(dp, compat_ptr(pv.ports), pv.n_ports);
1531 return put_user(retval, &upv->n_ports);
1534 static int compat_get_flow(struct odp_flow *flow, const struct compat_odp_flow __user *compat)
1536 compat_uptr_t actions;
1538 if (!access_ok(VERIFY_READ, compat, sizeof(struct compat_odp_flow)) ||
1539 __copy_from_user(&flow->stats, &compat->stats, sizeof(struct odp_flow_stats)) ||
1540 __copy_from_user(&flow->key, &compat->key, sizeof(struct odp_flow_key)) ||
1541 __get_user(actions, &compat->actions) ||
1542 __get_user(flow->actions_len, &compat->actions_len) ||
1543 __get_user(flow->flags, &compat->flags))
1546 flow->actions = (struct nlattr __force *)compat_ptr(actions);
1550 static int compat_put_flow(struct datapath *dp, struct compat_odp_flow_put __user *ufp)
1552 struct odp_flow_stats stats;
1553 struct odp_flow_put fp;
1556 if (compat_get_flow(&fp.flow, &ufp->flow) ||
1557 get_user(fp.flags, &ufp->flags))
1560 error = do_put_flow(dp, &fp, &stats);
1564 if (copy_to_user(&ufp->flow.stats, &stats,
1565 sizeof(struct odp_flow_stats)))
1571 static int compat_answer_query(struct datapath *dp, struct sw_flow *flow,
1573 struct compat_odp_flow __user *ufp)
1575 compat_uptr_t actions;
1577 if (get_user(actions, &ufp->actions))
1580 return do_answer_query(dp, flow, query_flags, &ufp->stats,
1581 compat_ptr(actions), &ufp->actions_len);
1584 static int compat_del_flow(struct datapath *dp, struct compat_odp_flow __user *ufp)
1586 struct sw_flow *flow;
1590 if (compat_get_flow(&uf, ufp))
1593 flow = do_del_flow(dp, &uf.key);
1595 return PTR_ERR(flow);
1597 error = compat_answer_query(dp, flow, 0, ufp);
1598 flow_deferred_free(flow);
1602 static int compat_query_flows(struct datapath *dp,
1603 struct compat_odp_flow __user *flows,
1606 struct tbl *table = get_table_protected(dp);
1609 for (i = 0; i < n_flows; i++) {
1610 struct compat_odp_flow __user *ufp = &flows[i];
1612 struct tbl_node *flow_node;
1615 if (compat_get_flow(&uf, ufp))
1618 flow_node = tbl_lookup(table, &uf.key, flow_hash(&uf.key), flow_cmp);
1620 error = put_user(ENOENT, &ufp->stats.error);
1622 error = compat_answer_query(dp, flow_cast(flow_node),
1630 struct compat_list_flows_cbdata {
1631 struct datapath *dp;
1632 struct compat_odp_flow __user *uflows;
1637 static int compat_list_flow(struct tbl_node *node, void *cbdata_)
1639 struct sw_flow *flow = flow_cast(node);
1640 struct compat_list_flows_cbdata *cbdata = cbdata_;
1641 struct compat_odp_flow __user *ufp = &cbdata->uflows[cbdata->listed_flows++];
1644 if (copy_to_user(&ufp->key, &flow->key, sizeof flow->key))
1646 error = compat_answer_query(cbdata->dp, flow, 0, ufp);
1650 if (cbdata->listed_flows >= cbdata->n_flows)
1651 return cbdata->listed_flows;
1655 static int compat_list_flows(struct datapath *dp,
1656 struct compat_odp_flow __user *flows, u32 n_flows)
1658 struct compat_list_flows_cbdata cbdata;
1665 cbdata.uflows = flows;
1666 cbdata.n_flows = n_flows;
1667 cbdata.listed_flows = 0;
1669 error = tbl_foreach(get_table_protected(dp), compat_list_flow, &cbdata);
1670 return error ? error : cbdata.listed_flows;
1673 static int compat_flowvec_ioctl(struct datapath *dp, unsigned long argp,
1674 int (*function)(struct datapath *,
1675 struct compat_odp_flow __user *,
1678 struct compat_odp_flowvec __user *uflowvec;
1679 struct compat_odp_flow __user *flows;
1680 struct compat_odp_flowvec flowvec;
1683 uflowvec = compat_ptr(argp);
1684 if (!access_ok(VERIFY_WRITE, uflowvec, sizeof *uflowvec) ||
1685 copy_from_user(&flowvec, uflowvec, sizeof flowvec))
1688 if (flowvec.n_flows > INT_MAX / sizeof(struct compat_odp_flow))
1691 flows = compat_ptr(flowvec.flows);
1692 if (!access_ok(VERIFY_WRITE, flows,
1693 flowvec.n_flows * sizeof(struct compat_odp_flow)))
1696 retval = function(dp, flows, flowvec.n_flows);
1697 return (retval < 0 ? retval
1698 : retval == flowvec.n_flows ? 0
1699 : put_user(retval, &uflowvec->n_flows));
1702 static int compat_execute(struct datapath *dp, const struct compat_odp_execute __user *uexecute)
1704 struct odp_execute execute;
1705 compat_uptr_t actions;
1708 if (!access_ok(VERIFY_READ, uexecute, sizeof(struct compat_odp_execute)) ||
1709 __get_user(actions, &uexecute->actions) ||
1710 __get_user(execute.actions_len, &uexecute->actions_len) ||
1711 __get_user(data, &uexecute->data) ||
1712 __get_user(execute.length, &uexecute->length))
1715 execute.actions = (struct nlattr __force *)compat_ptr(actions);
1716 execute.data = (const void __force *)compat_ptr(data);
1718 return do_execute(dp, &execute);
1721 static long openvswitch_compat_ioctl(struct file *f, unsigned int cmd, unsigned long argp)
1723 int dp_idx = iminor(f->f_dentry->d_inode);
1724 struct datapath *dp;
1728 case ODP_DP_DESTROY:
1729 case ODP_FLOW_FLUSH:
1730 /* Ioctls that don't need any translation at all. */
1731 return openvswitch_ioctl(f, cmd, argp);
1734 case ODP_VPORT_ATTACH:
1735 case ODP_VPORT_DETACH:
1737 case ODP_VPORT_MTU_SET:
1738 case ODP_VPORT_MTU_GET:
1739 case ODP_VPORT_ETHER_SET:
1740 case ODP_VPORT_ETHER_GET:
1741 case ODP_VPORT_STATS_SET:
1742 case ODP_VPORT_STATS_GET:
1744 case ODP_GET_DROP_FRAGS:
1745 case ODP_SET_DROP_FRAGS:
1746 case ODP_SET_LISTEN_MASK:
1747 case ODP_GET_LISTEN_MASK:
1748 case ODP_SET_SFLOW_PROBABILITY:
1749 case ODP_GET_SFLOW_PROBABILITY:
1750 case ODP_VPORT_QUERY:
1751 /* Ioctls that just need their pointer argument extended. */
1752 return openvswitch_ioctl(f, cmd, (unsigned long)compat_ptr(argp));
1755 dp = get_dp_locked(dp_idx);
1761 case ODP_VPORT_LIST32:
1762 err = compat_list_ports(dp, compat_ptr(argp));
1765 case ODP_FLOW_PUT32:
1766 err = compat_put_flow(dp, compat_ptr(argp));
1769 case ODP_FLOW_DEL32:
1770 err = compat_del_flow(dp, compat_ptr(argp));
1773 case ODP_FLOW_GET32:
1774 err = compat_flowvec_ioctl(dp, argp, compat_query_flows);
1777 case ODP_FLOW_LIST32:
1778 err = compat_flowvec_ioctl(dp, argp, compat_list_flows);
1782 err = compat_execute(dp, compat_ptr(argp));
1789 mutex_unlock(&dp->mutex);
1795 /* Unfortunately this function is not exported so this is a verbatim copy
1796 * from net/core/datagram.c in 2.6.30. */
1797 static int skb_copy_and_csum_datagram(const struct sk_buff *skb, int offset,
1798 u8 __user *to, int len,
1801 int start = skb_headlen(skb);
1803 int i, copy = start - offset;
1810 *csump = csum_and_copy_to_user(skb->data + offset, to, copy,
1814 if ((len -= copy) == 0)
1821 for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) {
1824 WARN_ON(start > offset + len);
1826 end = start + skb_shinfo(skb)->frags[i].size;
1827 if ((copy = end - offset) > 0) {
1831 skb_frag_t *frag = &skb_shinfo(skb)->frags[i];
1832 struct page *page = frag->page;
1837 csum2 = csum_and_copy_to_user(vaddr +
1844 *csump = csum_block_add(*csump, csum2, pos);
1854 if (skb_shinfo(skb)->frag_list) {
1855 struct sk_buff *list = skb_shinfo(skb)->frag_list;
1857 for (; list; list=list->next) {
1860 WARN_ON(start > offset + len);
1862 end = start + list->len;
1863 if ((copy = end - offset) > 0) {
1867 if (skb_copy_and_csum_datagram(list,
1872 *csump = csum_block_add(*csump, csum2, pos);
1873 if ((len -= copy) == 0)
1889 static ssize_t openvswitch_read(struct file *f, char __user *buf,
1890 size_t nbytes, loff_t *ppos)
1892 int listeners = get_listen_mask(f);
1893 int dp_idx = iminor(f->f_dentry->d_inode);
1894 struct datapath *dp = get_dp_locked(dp_idx);
1895 struct sk_buff *skb;
1896 size_t copy_bytes, tot_copy_bytes;
1902 if (nbytes == 0 || !listeners)
1908 for (i = 0; i < DP_N_QUEUES; i++) {
1909 if (listeners & (1 << i)) {
1910 skb = skb_dequeue(&dp->queues[i]);
1916 if (f->f_flags & O_NONBLOCK) {
1921 wait_event_interruptible(dp->waitqueue,
1922 dp_has_packet_of_interest(dp,
1925 if (signal_pending(current)) {
1926 retval = -ERESTARTSYS;
1931 mutex_unlock(&dp->mutex);
1933 copy_bytes = tot_copy_bytes = min_t(size_t, skb->len, nbytes);
1936 if (skb->ip_summed == CHECKSUM_PARTIAL) {
1937 if (copy_bytes == skb->len) {
1939 u16 csum_start, csum_offset;
1941 get_skb_csum_pointers(skb, &csum_start, &csum_offset);
1942 csum_start -= skb_headroom(skb);
1944 BUG_ON(csum_start >= skb_headlen(skb));
1945 retval = skb_copy_and_csum_datagram(skb, csum_start, buf + csum_start,
1946 copy_bytes - csum_start, &csum);
1948 __sum16 __user *csump;
1950 copy_bytes = csum_start;
1951 csump = (__sum16 __user *)(buf + csum_start + csum_offset);
1953 BUG_ON((char __user *)csump + sizeof(__sum16) >
1955 put_user(csum_fold(csum), csump);
1958 retval = skb_checksum_help(skb);
1965 iov.iov_len = copy_bytes;
1966 retval = skb_copy_datagram_iovec(skb, 0, &iov, iov.iov_len);
1970 retval = tot_copy_bytes;
1976 mutex_unlock(&dp->mutex);
1980 static unsigned int openvswitch_poll(struct file *file, poll_table *wait)
1982 int dp_idx = iminor(file->f_dentry->d_inode);
1983 struct datapath *dp = get_dp_locked(dp_idx);
1988 poll_wait(file, &dp->waitqueue, wait);
1989 if (dp_has_packet_of_interest(dp, get_listen_mask(file)))
1990 mask |= POLLIN | POLLRDNORM;
1991 mutex_unlock(&dp->mutex);
1993 mask = POLLIN | POLLRDNORM | POLLHUP;
1998 static struct file_operations openvswitch_fops = {
1999 .owner = THIS_MODULE,
2000 .read = openvswitch_read,
2001 .poll = openvswitch_poll,
2002 .unlocked_ioctl = openvswitch_ioctl,
2003 #ifdef CONFIG_COMPAT
2004 .compat_ioctl = openvswitch_compat_ioctl,
2010 static int __init dp_init(void)
2012 struct sk_buff *dummy_skb;
2015 BUILD_BUG_ON(sizeof(struct ovs_skb_cb) > sizeof(dummy_skb->cb));
2017 printk("Open vSwitch %s, built "__DATE__" "__TIME__"\n", VERSION BUILDNR);
2025 goto error_flow_exit;
2027 err = register_netdevice_notifier(&dp_device_notifier);
2029 goto error_vport_exit;
2031 major = register_chrdev(0, "openvswitch", &openvswitch_fops);
2033 goto error_unreg_notifier;
2037 error_unreg_notifier:
2038 unregister_netdevice_notifier(&dp_device_notifier);
2047 static void dp_cleanup(void)
2050 unregister_chrdev(major, "openvswitch");
2051 unregister_netdevice_notifier(&dp_device_notifier);
2056 module_init(dp_init);
2057 module_exit(dp_cleanup);
2059 MODULE_DESCRIPTION("Open vSwitch switching datapath");
2060 MODULE_LICENSE("GPL");