1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright (c) 2007-2014 Nicira, Inc.
6 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
8 #include <linux/init.h>
9 #include <linux/module.h>
10 #include <linux/if_arp.h>
11 #include <linux/if_vlan.h>
14 #include <linux/jhash.h>
15 #include <linux/delay.h>
16 #include <linux/time.h>
17 #include <linux/etherdevice.h>
18 #include <linux/genetlink.h>
19 #include <linux/kernel.h>
20 #include <linux/kthread.h>
21 #include <linux/mutex.h>
22 #include <linux/percpu.h>
23 #include <linux/rcupdate.h>
24 #include <linux/tcp.h>
25 #include <linux/udp.h>
26 #include <linux/ethtool.h>
27 #include <linux/wait.h>
28 #include <asm/div64.h>
29 #include <linux/highmem.h>
30 #include <linux/netfilter_bridge.h>
31 #include <linux/netfilter_ipv4.h>
32 #include <linux/inetdevice.h>
33 #include <linux/list.h>
34 #include <linux/openvswitch.h>
35 #include <linux/rculist.h>
36 #include <linux/dmi.h>
37 #include <net/genetlink.h>
38 #include <net/net_namespace.h>
39 #include <net/netns/generic.h>
43 #include "flow_table.h"
44 #include "flow_netlink.h"
46 #include "vport-internal_dev.h"
47 #include "vport-netdev.h"
49 unsigned int ovs_net_id __read_mostly;
51 static struct genl_family dp_packet_genl_family;
52 static struct genl_family dp_flow_genl_family;
53 static struct genl_family dp_datapath_genl_family;
55 static const struct nla_policy flow_policy[];
57 static const struct genl_multicast_group ovs_dp_flow_multicast_group = {
58 .name = OVS_FLOW_MCGROUP,
61 static const struct genl_multicast_group ovs_dp_datapath_multicast_group = {
62 .name = OVS_DATAPATH_MCGROUP,
65 static const struct genl_multicast_group ovs_dp_vport_multicast_group = {
66 .name = OVS_VPORT_MCGROUP,
69 /* Check if need to build a reply message.
70 * OVS userspace sets the NLM_F_ECHO flag if it needs the reply. */
71 static bool ovs_must_notify(struct genl_family *family, struct genl_info *info,
74 return info->nlhdr->nlmsg_flags & NLM_F_ECHO ||
75 genl_has_listeners(family, genl_info_net(info), group);
78 static void ovs_notify(struct genl_family *family,
79 struct sk_buff *skb, struct genl_info *info)
81 genl_notify(family, skb, info, 0, GFP_KERNEL);
87 * All writes e.g. Writes to device state (add/remove datapath, port, set
88 * operations on vports, etc.), Writes to other state (flow table
89 * modifications, set miscellaneous datapath parameters, etc.) are protected
92 * Reads are protected by RCU.
94 * There are a few special cases (mostly stats) that have their own
95 * synchronization but they nest under all of above and don't interact with
98 * The RTNL lock nests inside ovs_mutex.
101 static DEFINE_MUTEX(ovs_mutex);
105 mutex_lock(&ovs_mutex);
108 void ovs_unlock(void)
110 mutex_unlock(&ovs_mutex);
113 #ifdef CONFIG_LOCKDEP
114 int lockdep_ovsl_is_held(void)
117 return lockdep_is_held(&ovs_mutex);
123 static struct vport *new_vport(const struct vport_parms *);
124 static int queue_gso_packets(struct datapath *dp, struct sk_buff *,
125 const struct sw_flow_key *,
126 const struct dp_upcall_info *,
128 static int queue_userspace_packet(struct datapath *dp, struct sk_buff *,
129 const struct sw_flow_key *,
130 const struct dp_upcall_info *,
133 /* Must be called with rcu_read_lock or ovs_mutex. */
134 const char *ovs_dp_name(const struct datapath *dp)
136 struct vport *vport = ovs_vport_ovsl_rcu(dp, OVSP_LOCAL);
137 return ovs_vport_name(vport);
140 static int get_dpifindex(const struct datapath *dp)
147 local = ovs_vport_rcu(dp, OVSP_LOCAL);
149 ifindex = local->dev->ifindex;
158 static void destroy_dp_rcu(struct rcu_head *rcu)
160 struct datapath *dp = container_of(rcu, struct datapath, rcu);
162 ovs_flow_tbl_destroy(&dp->table);
163 free_percpu(dp->stats_percpu);
169 static struct hlist_head *vport_hash_bucket(const struct datapath *dp,
172 return &dp->ports[port_no & (DP_VPORT_HASH_BUCKETS - 1)];
175 /* Called with ovs_mutex or RCU read lock. */
176 struct vport *ovs_lookup_vport(const struct datapath *dp, u16 port_no)
179 struct hlist_head *head;
181 head = vport_hash_bucket(dp, port_no);
182 hlist_for_each_entry_rcu(vport, head, dp_hash_node) {
183 if (vport->port_no == port_no)
189 /* Called with ovs_mutex. */
190 static struct vport *new_vport(const struct vport_parms *parms)
194 vport = ovs_vport_add(parms);
195 if (!IS_ERR(vport)) {
196 struct datapath *dp = parms->dp;
197 struct hlist_head *head = vport_hash_bucket(dp, vport->port_no);
199 hlist_add_head_rcu(&vport->dp_hash_node, head);
204 void ovs_dp_detach_port(struct vport *p)
208 /* First drop references to device. */
209 hlist_del_rcu(&p->dp_hash_node);
211 /* Then destroy it. */
215 /* Must be called with rcu_read_lock. */
216 void ovs_dp_process_packet(struct sk_buff *skb, struct sw_flow_key *key)
218 const struct vport *p = OVS_CB(skb)->input_vport;
219 struct datapath *dp = p->dp;
220 struct sw_flow *flow;
221 struct sw_flow_actions *sf_acts;
222 struct dp_stats_percpu *stats;
227 stats = this_cpu_ptr(dp->stats_percpu);
230 flow = ovs_flow_tbl_lookup_stats(&dp->table, key, &n_mask_hit);
231 if (unlikely(!flow)) {
232 struct dp_upcall_info upcall;
234 memset(&upcall, 0, sizeof(upcall));
235 upcall.cmd = OVS_PACKET_CMD_MISS;
236 upcall.portid = ovs_vport_find_upcall_portid(p, skb);
237 upcall.mru = OVS_CB(skb)->mru;
238 error = ovs_dp_upcall(dp, skb, key, &upcall, 0);
250 stats_counter = &stats->n_missed;
254 ovs_flow_stats_update(flow, key->tp.flags, skb);
255 sf_acts = rcu_dereference(flow->sf_acts);
256 error = ovs_execute_actions(dp, skb, sf_acts, key);
258 net_dbg_ratelimited("ovs: action execution error on datapath %s: %d\n",
259 ovs_dp_name(dp), error);
261 stats_counter = &stats->n_hit;
264 /* Update datapath statistics. */
265 u64_stats_update_begin(&stats->syncp);
267 stats->n_mask_hit += n_mask_hit;
268 u64_stats_update_end(&stats->syncp);
271 int ovs_dp_upcall(struct datapath *dp, struct sk_buff *skb,
272 const struct sw_flow_key *key,
273 const struct dp_upcall_info *upcall_info,
276 struct dp_stats_percpu *stats;
279 if (upcall_info->portid == 0) {
284 if (!skb_is_gso(skb))
285 err = queue_userspace_packet(dp, skb, key, upcall_info, cutlen);
287 err = queue_gso_packets(dp, skb, key, upcall_info, cutlen);
294 stats = this_cpu_ptr(dp->stats_percpu);
296 u64_stats_update_begin(&stats->syncp);
298 u64_stats_update_end(&stats->syncp);
303 static int queue_gso_packets(struct datapath *dp, struct sk_buff *skb,
304 const struct sw_flow_key *key,
305 const struct dp_upcall_info *upcall_info,
308 unsigned int gso_type = skb_shinfo(skb)->gso_type;
309 struct sw_flow_key later_key;
310 struct sk_buff *segs, *nskb;
313 BUILD_BUG_ON(sizeof(*OVS_CB(skb)) > SKB_SGO_CB_OFFSET);
314 segs = __skb_gso_segment(skb, NETIF_F_SG, false);
316 return PTR_ERR(segs);
320 if (gso_type & SKB_GSO_UDP) {
321 /* The initial flow key extracted by ovs_flow_key_extract()
322 * in this case is for a first fragment, so we need to
323 * properly mark later fragments.
326 later_key.ip.frag = OVS_FRAG_TYPE_LATER;
329 /* Queue all of the segments. */
332 if (gso_type & SKB_GSO_UDP && skb != segs)
335 err = queue_userspace_packet(dp, skb, key, upcall_info, cutlen);
339 } while ((skb = skb->next));
341 /* Free all of the segments. */
349 } while ((skb = nskb));
353 static size_t upcall_msg_size(const struct dp_upcall_info *upcall_info,
354 unsigned int hdrlen, int actions_attrlen)
356 size_t size = NLMSG_ALIGN(sizeof(struct ovs_header))
357 + nla_total_size(hdrlen) /* OVS_PACKET_ATTR_PACKET */
358 + nla_total_size(ovs_key_attr_size()) /* OVS_PACKET_ATTR_KEY */
359 + nla_total_size(sizeof(unsigned int)); /* OVS_PACKET_ATTR_LEN */
361 /* OVS_PACKET_ATTR_USERDATA */
362 if (upcall_info->userdata)
363 size += NLA_ALIGN(upcall_info->userdata->nla_len);
365 /* OVS_PACKET_ATTR_EGRESS_TUN_KEY */
366 if (upcall_info->egress_tun_info)
367 size += nla_total_size(ovs_tun_key_attr_size());
369 /* OVS_PACKET_ATTR_ACTIONS */
370 if (upcall_info->actions_len)
371 size += nla_total_size(actions_attrlen);
373 /* OVS_PACKET_ATTR_MRU */
374 if (upcall_info->mru)
375 size += nla_total_size(sizeof(upcall_info->mru));
380 static void pad_packet(struct datapath *dp, struct sk_buff *skb)
382 if (!(dp->user_features & OVS_DP_F_UNALIGNED)) {
383 size_t plen = NLA_ALIGN(skb->len) - skb->len;
386 skb_put_zero(skb, plen);
390 static int queue_userspace_packet(struct datapath *dp, struct sk_buff *skb,
391 const struct sw_flow_key *key,
392 const struct dp_upcall_info *upcall_info,
395 struct ovs_header *upcall;
396 struct sk_buff *nskb = NULL;
397 struct sk_buff *user_skb = NULL; /* to be queued to userspace */
403 dp_ifindex = get_dpifindex(dp);
407 if (skb_vlan_tag_present(skb)) {
408 nskb = skb_clone(skb, GFP_ATOMIC);
412 nskb = __vlan_hwaccel_push_inside(nskb);
419 if (nla_attr_size(skb->len) > USHRT_MAX) {
424 /* Complete checksum if needed */
425 if (skb->ip_summed == CHECKSUM_PARTIAL &&
426 (err = skb_csum_hwoffload_help(skb, 0)))
429 /* Older versions of OVS user space enforce alignment of the last
430 * Netlink attribute to NLA_ALIGNTO which would require extensive
431 * padding logic. Only perform zerocopy if padding is not required.
433 if (dp->user_features & OVS_DP_F_UNALIGNED)
434 hlen = skb_zerocopy_headlen(skb);
438 len = upcall_msg_size(upcall_info, hlen - cutlen,
439 OVS_CB(skb)->acts_origlen);
440 user_skb = genlmsg_new(len, GFP_ATOMIC);
446 upcall = genlmsg_put(user_skb, 0, 0, &dp_packet_genl_family,
447 0, upcall_info->cmd);
452 upcall->dp_ifindex = dp_ifindex;
454 err = ovs_nla_put_key(key, key, OVS_PACKET_ATTR_KEY, false, user_skb);
458 if (upcall_info->userdata)
459 __nla_put(user_skb, OVS_PACKET_ATTR_USERDATA,
460 nla_len(upcall_info->userdata),
461 nla_data(upcall_info->userdata));
463 if (upcall_info->egress_tun_info) {
464 nla = nla_nest_start_noflag(user_skb,
465 OVS_PACKET_ATTR_EGRESS_TUN_KEY);
470 err = ovs_nla_put_tunnel_info(user_skb,
471 upcall_info->egress_tun_info);
475 nla_nest_end(user_skb, nla);
478 if (upcall_info->actions_len) {
479 nla = nla_nest_start_noflag(user_skb, OVS_PACKET_ATTR_ACTIONS);
484 err = ovs_nla_put_actions(upcall_info->actions,
485 upcall_info->actions_len,
488 nla_nest_end(user_skb, nla);
490 nla_nest_cancel(user_skb, nla);
493 /* Add OVS_PACKET_ATTR_MRU */
494 if (upcall_info->mru) {
495 if (nla_put_u16(user_skb, OVS_PACKET_ATTR_MRU,
500 pad_packet(dp, user_skb);
503 /* Add OVS_PACKET_ATTR_LEN when packet is truncated */
505 if (nla_put_u32(user_skb, OVS_PACKET_ATTR_LEN,
510 pad_packet(dp, user_skb);
513 /* Only reserve room for attribute header, packet data is added
514 * in skb_zerocopy() */
515 if (!(nla = nla_reserve(user_skb, OVS_PACKET_ATTR_PACKET, 0))) {
519 nla->nla_len = nla_attr_size(skb->len - cutlen);
521 err = skb_zerocopy(user_skb, skb, skb->len - cutlen, hlen);
525 /* Pad OVS_PACKET_ATTR_PACKET if linear copy was performed */
526 pad_packet(dp, user_skb);
528 ((struct nlmsghdr *) user_skb->data)->nlmsg_len = user_skb->len;
530 err = genlmsg_unicast(ovs_dp_get_net(dp), user_skb, upcall_info->portid);
535 consume_skb(user_skb);
541 static int ovs_packet_cmd_execute(struct sk_buff *skb, struct genl_info *info)
543 struct ovs_header *ovs_header = info->userhdr;
544 struct net *net = sock_net(skb->sk);
545 struct nlattr **a = info->attrs;
546 struct sw_flow_actions *acts;
547 struct sk_buff *packet;
548 struct sw_flow *flow;
549 struct sw_flow_actions *sf_acts;
551 struct vport *input_vport;
555 bool log = !a[OVS_PACKET_ATTR_PROBE];
558 if (!a[OVS_PACKET_ATTR_PACKET] || !a[OVS_PACKET_ATTR_KEY] ||
559 !a[OVS_PACKET_ATTR_ACTIONS])
562 len = nla_len(a[OVS_PACKET_ATTR_PACKET]);
563 packet = __dev_alloc_skb(NET_IP_ALIGN + len, GFP_KERNEL);
567 skb_reserve(packet, NET_IP_ALIGN);
569 nla_memcpy(__skb_put(packet, len), a[OVS_PACKET_ATTR_PACKET], len);
571 /* Set packet's mru */
572 if (a[OVS_PACKET_ATTR_MRU]) {
573 mru = nla_get_u16(a[OVS_PACKET_ATTR_MRU]);
574 packet->ignore_df = 1;
576 OVS_CB(packet)->mru = mru;
578 /* Build an sw_flow for sending this packet. */
579 flow = ovs_flow_alloc();
584 err = ovs_flow_key_extract_userspace(net, a[OVS_PACKET_ATTR_KEY],
585 packet, &flow->key, log);
589 err = ovs_nla_copy_actions(net, a[OVS_PACKET_ATTR_ACTIONS],
590 &flow->key, &acts, log);
594 rcu_assign_pointer(flow->sf_acts, acts);
595 packet->priority = flow->key.phy.priority;
596 packet->mark = flow->key.phy.skb_mark;
599 dp = get_dp_rcu(net, ovs_header->dp_ifindex);
604 input_vport = ovs_vport_rcu(dp, flow->key.phy.in_port);
606 input_vport = ovs_vport_rcu(dp, OVSP_LOCAL);
611 packet->dev = input_vport->dev;
612 OVS_CB(packet)->input_vport = input_vport;
613 sf_acts = rcu_dereference(flow->sf_acts);
616 err = ovs_execute_actions(dp, packet, sf_acts, &flow->key);
620 ovs_flow_free(flow, false);
626 ovs_flow_free(flow, false);
633 static const struct nla_policy packet_policy[OVS_PACKET_ATTR_MAX + 1] = {
634 [OVS_PACKET_ATTR_PACKET] = { .len = ETH_HLEN },
635 [OVS_PACKET_ATTR_KEY] = { .type = NLA_NESTED },
636 [OVS_PACKET_ATTR_ACTIONS] = { .type = NLA_NESTED },
637 [OVS_PACKET_ATTR_PROBE] = { .type = NLA_FLAG },
638 [OVS_PACKET_ATTR_MRU] = { .type = NLA_U16 },
641 static const struct genl_ops dp_packet_genl_ops[] = {
642 { .cmd = OVS_PACKET_CMD_EXECUTE,
643 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
644 .flags = GENL_UNS_ADMIN_PERM, /* Requires CAP_NET_ADMIN privilege. */
645 .doit = ovs_packet_cmd_execute
649 static struct genl_family dp_packet_genl_family __ro_after_init = {
650 .hdrsize = sizeof(struct ovs_header),
651 .name = OVS_PACKET_FAMILY,
652 .version = OVS_PACKET_VERSION,
653 .maxattr = OVS_PACKET_ATTR_MAX,
654 .policy = packet_policy,
656 .parallel_ops = true,
657 .ops = dp_packet_genl_ops,
658 .n_ops = ARRAY_SIZE(dp_packet_genl_ops),
659 .module = THIS_MODULE,
662 static void get_dp_stats(const struct datapath *dp, struct ovs_dp_stats *stats,
663 struct ovs_dp_megaflow_stats *mega_stats)
667 memset(mega_stats, 0, sizeof(*mega_stats));
669 stats->n_flows = ovs_flow_tbl_count(&dp->table);
670 mega_stats->n_masks = ovs_flow_tbl_num_masks(&dp->table);
672 stats->n_hit = stats->n_missed = stats->n_lost = 0;
674 for_each_possible_cpu(i) {
675 const struct dp_stats_percpu *percpu_stats;
676 struct dp_stats_percpu local_stats;
679 percpu_stats = per_cpu_ptr(dp->stats_percpu, i);
682 start = u64_stats_fetch_begin_irq(&percpu_stats->syncp);
683 local_stats = *percpu_stats;
684 } while (u64_stats_fetch_retry_irq(&percpu_stats->syncp, start));
686 stats->n_hit += local_stats.n_hit;
687 stats->n_missed += local_stats.n_missed;
688 stats->n_lost += local_stats.n_lost;
689 mega_stats->n_mask_hit += local_stats.n_mask_hit;
693 static bool should_fill_key(const struct sw_flow_id *sfid, uint32_t ufid_flags)
695 return ovs_identifier_is_ufid(sfid) &&
696 !(ufid_flags & OVS_UFID_F_OMIT_KEY);
699 static bool should_fill_mask(uint32_t ufid_flags)
701 return !(ufid_flags & OVS_UFID_F_OMIT_MASK);
704 static bool should_fill_actions(uint32_t ufid_flags)
706 return !(ufid_flags & OVS_UFID_F_OMIT_ACTIONS);
709 static size_t ovs_flow_cmd_msg_size(const struct sw_flow_actions *acts,
710 const struct sw_flow_id *sfid,
713 size_t len = NLMSG_ALIGN(sizeof(struct ovs_header));
715 /* OVS_FLOW_ATTR_UFID, or unmasked flow key as fallback
716 * see ovs_nla_put_identifier()
718 if (sfid && ovs_identifier_is_ufid(sfid))
719 len += nla_total_size(sfid->ufid_len);
721 len += nla_total_size(ovs_key_attr_size());
723 /* OVS_FLOW_ATTR_KEY */
724 if (!sfid || should_fill_key(sfid, ufid_flags))
725 len += nla_total_size(ovs_key_attr_size());
727 /* OVS_FLOW_ATTR_MASK */
728 if (should_fill_mask(ufid_flags))
729 len += nla_total_size(ovs_key_attr_size());
731 /* OVS_FLOW_ATTR_ACTIONS */
732 if (should_fill_actions(ufid_flags))
733 len += nla_total_size(acts->orig_len);
736 + nla_total_size_64bit(sizeof(struct ovs_flow_stats)) /* OVS_FLOW_ATTR_STATS */
737 + nla_total_size(1) /* OVS_FLOW_ATTR_TCP_FLAGS */
738 + nla_total_size_64bit(8); /* OVS_FLOW_ATTR_USED */
741 /* Called with ovs_mutex or RCU read lock. */
742 static int ovs_flow_cmd_fill_stats(const struct sw_flow *flow,
745 struct ovs_flow_stats stats;
749 ovs_flow_stats_get(flow, &stats, &used, &tcp_flags);
752 nla_put_u64_64bit(skb, OVS_FLOW_ATTR_USED, ovs_flow_used_time(used),
756 if (stats.n_packets &&
757 nla_put_64bit(skb, OVS_FLOW_ATTR_STATS,
758 sizeof(struct ovs_flow_stats), &stats,
762 if ((u8)ntohs(tcp_flags) &&
763 nla_put_u8(skb, OVS_FLOW_ATTR_TCP_FLAGS, (u8)ntohs(tcp_flags)))
769 /* Called with ovs_mutex or RCU read lock. */
770 static int ovs_flow_cmd_fill_actions(const struct sw_flow *flow,
771 struct sk_buff *skb, int skb_orig_len)
773 struct nlattr *start;
776 /* If OVS_FLOW_ATTR_ACTIONS doesn't fit, skip dumping the actions if
777 * this is the first flow to be dumped into 'skb'. This is unusual for
778 * Netlink but individual action lists can be longer than
779 * NLMSG_GOODSIZE and thus entirely undumpable if we didn't do this.
780 * The userspace caller can always fetch the actions separately if it
781 * really wants them. (Most userspace callers in fact don't care.)
783 * This can only fail for dump operations because the skb is always
784 * properly sized for single flows.
786 start = nla_nest_start_noflag(skb, OVS_FLOW_ATTR_ACTIONS);
788 const struct sw_flow_actions *sf_acts;
790 sf_acts = rcu_dereference_ovsl(flow->sf_acts);
791 err = ovs_nla_put_actions(sf_acts->actions,
792 sf_acts->actions_len, skb);
795 nla_nest_end(skb, start);
800 nla_nest_cancel(skb, start);
802 } else if (skb_orig_len) {
809 /* Called with ovs_mutex or RCU read lock. */
810 static int ovs_flow_cmd_fill_info(const struct sw_flow *flow, int dp_ifindex,
811 struct sk_buff *skb, u32 portid,
812 u32 seq, u32 flags, u8 cmd, u32 ufid_flags)
814 const int skb_orig_len = skb->len;
815 struct ovs_header *ovs_header;
818 ovs_header = genlmsg_put(skb, portid, seq, &dp_flow_genl_family,
823 ovs_header->dp_ifindex = dp_ifindex;
825 err = ovs_nla_put_identifier(flow, skb);
829 if (should_fill_key(&flow->id, ufid_flags)) {
830 err = ovs_nla_put_masked_key(flow, skb);
835 if (should_fill_mask(ufid_flags)) {
836 err = ovs_nla_put_mask(flow, skb);
841 err = ovs_flow_cmd_fill_stats(flow, skb);
845 if (should_fill_actions(ufid_flags)) {
846 err = ovs_flow_cmd_fill_actions(flow, skb, skb_orig_len);
851 genlmsg_end(skb, ovs_header);
855 genlmsg_cancel(skb, ovs_header);
859 /* May not be called with RCU read lock. */
860 static struct sk_buff *ovs_flow_cmd_alloc_info(const struct sw_flow_actions *acts,
861 const struct sw_flow_id *sfid,
862 struct genl_info *info,
869 if (!always && !ovs_must_notify(&dp_flow_genl_family, info, 0))
872 len = ovs_flow_cmd_msg_size(acts, sfid, ufid_flags);
873 skb = genlmsg_new(len, GFP_KERNEL);
875 return ERR_PTR(-ENOMEM);
880 /* Called with ovs_mutex. */
881 static struct sk_buff *ovs_flow_cmd_build_info(const struct sw_flow *flow,
883 struct genl_info *info, u8 cmd,
884 bool always, u32 ufid_flags)
889 skb = ovs_flow_cmd_alloc_info(ovsl_dereference(flow->sf_acts),
890 &flow->id, info, always, ufid_flags);
891 if (IS_ERR_OR_NULL(skb))
894 retval = ovs_flow_cmd_fill_info(flow, dp_ifindex, skb,
895 info->snd_portid, info->snd_seq, 0,
897 if (WARN_ON_ONCE(retval < 0)) {
899 skb = ERR_PTR(retval);
904 static int ovs_flow_cmd_new(struct sk_buff *skb, struct genl_info *info)
906 struct net *net = sock_net(skb->sk);
907 struct nlattr **a = info->attrs;
908 struct ovs_header *ovs_header = info->userhdr;
909 struct sw_flow *flow = NULL, *new_flow;
910 struct sw_flow_mask mask;
911 struct sk_buff *reply;
913 struct sw_flow_key *key;
914 struct sw_flow_actions *acts;
915 struct sw_flow_match match;
916 u32 ufid_flags = ovs_nla_get_ufid_flags(a[OVS_FLOW_ATTR_UFID_FLAGS]);
918 bool log = !a[OVS_FLOW_ATTR_PROBE];
920 /* Must have key and actions. */
922 if (!a[OVS_FLOW_ATTR_KEY]) {
923 OVS_NLERR(log, "Flow key attr not present in new flow.");
926 if (!a[OVS_FLOW_ATTR_ACTIONS]) {
927 OVS_NLERR(log, "Flow actions attr not present in new flow.");
931 /* Most of the time we need to allocate a new flow, do it before
934 new_flow = ovs_flow_alloc();
935 if (IS_ERR(new_flow)) {
936 error = PTR_ERR(new_flow);
941 key = kzalloc(sizeof(*key), GFP_KERNEL);
947 ovs_match_init(&match, key, false, &mask);
948 error = ovs_nla_get_match(net, &match, a[OVS_FLOW_ATTR_KEY],
949 a[OVS_FLOW_ATTR_MASK], log);
953 ovs_flow_mask_key(&new_flow->key, key, true, &mask);
955 /* Extract flow identifier. */
956 error = ovs_nla_get_identifier(&new_flow->id, a[OVS_FLOW_ATTR_UFID],
961 /* Validate actions. */
962 error = ovs_nla_copy_actions(net, a[OVS_FLOW_ATTR_ACTIONS],
963 &new_flow->key, &acts, log);
965 OVS_NLERR(log, "Flow actions may not be safe on all matching packets.");
969 reply = ovs_flow_cmd_alloc_info(acts, &new_flow->id, info, false,
972 error = PTR_ERR(reply);
977 dp = get_dp(net, ovs_header->dp_ifindex);
983 /* Check if this is a duplicate flow */
984 if (ovs_identifier_is_ufid(&new_flow->id))
985 flow = ovs_flow_tbl_lookup_ufid(&dp->table, &new_flow->id);
987 flow = ovs_flow_tbl_lookup(&dp->table, key);
989 rcu_assign_pointer(new_flow->sf_acts, acts);
991 /* Put flow in bucket. */
992 error = ovs_flow_tbl_insert(&dp->table, new_flow, &mask);
993 if (unlikely(error)) {
998 if (unlikely(reply)) {
999 error = ovs_flow_cmd_fill_info(new_flow,
1000 ovs_header->dp_ifindex,
1001 reply, info->snd_portid,
1009 struct sw_flow_actions *old_acts;
1011 /* Bail out if we're not allowed to modify an existing flow.
1012 * We accept NLM_F_CREATE in place of the intended NLM_F_EXCL
1013 * because Generic Netlink treats the latter as a dump
1014 * request. We also accept NLM_F_EXCL in case that bug ever
1017 if (unlikely(info->nlhdr->nlmsg_flags & (NLM_F_CREATE
1020 goto err_unlock_ovs;
1022 /* The flow identifier has to be the same for flow updates.
1023 * Look for any overlapping flow.
1025 if (unlikely(!ovs_flow_cmp(flow, &match))) {
1026 if (ovs_identifier_is_key(&flow->id))
1027 flow = ovs_flow_tbl_lookup_exact(&dp->table,
1029 else /* UFID matches but key is different */
1033 goto err_unlock_ovs;
1036 /* Update actions. */
1037 old_acts = ovsl_dereference(flow->sf_acts);
1038 rcu_assign_pointer(flow->sf_acts, acts);
1040 if (unlikely(reply)) {
1041 error = ovs_flow_cmd_fill_info(flow,
1042 ovs_header->dp_ifindex,
1043 reply, info->snd_portid,
1051 ovs_nla_free_flow_actions_rcu(old_acts);
1052 ovs_flow_free(new_flow, false);
1056 ovs_notify(&dp_flow_genl_family, reply, info);
1065 ovs_nla_free_flow_actions(acts);
1069 ovs_flow_free(new_flow, false);
1074 /* Factor out action copy to avoid "Wframe-larger-than=1024" warning. */
1075 static noinline_for_stack struct sw_flow_actions *get_flow_actions(struct net *net,
1076 const struct nlattr *a,
1077 const struct sw_flow_key *key,
1078 const struct sw_flow_mask *mask,
1081 struct sw_flow_actions *acts;
1082 struct sw_flow_key masked_key;
1085 ovs_flow_mask_key(&masked_key, key, true, mask);
1086 error = ovs_nla_copy_actions(net, a, &masked_key, &acts, log);
1089 "Actions may not be safe on all matching packets");
1090 return ERR_PTR(error);
1096 /* Factor out match-init and action-copy to avoid
1097 * "Wframe-larger-than=1024" warning. Because mask is only
1098 * used to get actions, we new a function to save some
1101 * If there are not key and action attrs, we return 0
1102 * directly. In the case, the caller will also not use the
1103 * match as before. If there is action attr, we try to get
1104 * actions and save them to *acts. Before returning from
1105 * the function, we reset the match->mask pointer. Because
1106 * we should not to return match object with dangling reference
1109 static noinline_for_stack int
1110 ovs_nla_init_match_and_action(struct net *net,
1111 struct sw_flow_match *match,
1112 struct sw_flow_key *key,
1114 struct sw_flow_actions **acts,
1117 struct sw_flow_mask mask;
1120 if (a[OVS_FLOW_ATTR_KEY]) {
1121 ovs_match_init(match, key, true, &mask);
1122 error = ovs_nla_get_match(net, match, a[OVS_FLOW_ATTR_KEY],
1123 a[OVS_FLOW_ATTR_MASK], log);
1128 if (a[OVS_FLOW_ATTR_ACTIONS]) {
1129 if (!a[OVS_FLOW_ATTR_KEY]) {
1131 "Flow key attribute not present in set flow.");
1136 *acts = get_flow_actions(net, a[OVS_FLOW_ATTR_ACTIONS], key,
1138 if (IS_ERR(*acts)) {
1139 error = PTR_ERR(*acts);
1144 /* On success, error is 0. */
1150 static int ovs_flow_cmd_set(struct sk_buff *skb, struct genl_info *info)
1152 struct net *net = sock_net(skb->sk);
1153 struct nlattr **a = info->attrs;
1154 struct ovs_header *ovs_header = info->userhdr;
1155 struct sw_flow_key key;
1156 struct sw_flow *flow;
1157 struct sk_buff *reply = NULL;
1158 struct datapath *dp;
1159 struct sw_flow_actions *old_acts = NULL, *acts = NULL;
1160 struct sw_flow_match match;
1161 struct sw_flow_id sfid;
1162 u32 ufid_flags = ovs_nla_get_ufid_flags(a[OVS_FLOW_ATTR_UFID_FLAGS]);
1164 bool log = !a[OVS_FLOW_ATTR_PROBE];
1167 ufid_present = ovs_nla_get_ufid(&sfid, a[OVS_FLOW_ATTR_UFID], log);
1168 if (!a[OVS_FLOW_ATTR_KEY] && !ufid_present) {
1170 "Flow set message rejected, Key attribute missing.");
1174 error = ovs_nla_init_match_and_action(net, &match, &key, a,
1180 /* Can allocate before locking if have acts. */
1181 reply = ovs_flow_cmd_alloc_info(acts, &sfid, info, false,
1183 if (IS_ERR(reply)) {
1184 error = PTR_ERR(reply);
1185 goto err_kfree_acts;
1190 dp = get_dp(net, ovs_header->dp_ifindex);
1191 if (unlikely(!dp)) {
1193 goto err_unlock_ovs;
1195 /* Check that the flow exists. */
1197 flow = ovs_flow_tbl_lookup_ufid(&dp->table, &sfid);
1199 flow = ovs_flow_tbl_lookup_exact(&dp->table, &match);
1200 if (unlikely(!flow)) {
1202 goto err_unlock_ovs;
1205 /* Update actions, if present. */
1207 old_acts = ovsl_dereference(flow->sf_acts);
1208 rcu_assign_pointer(flow->sf_acts, acts);
1210 if (unlikely(reply)) {
1211 error = ovs_flow_cmd_fill_info(flow,
1212 ovs_header->dp_ifindex,
1213 reply, info->snd_portid,
1220 /* Could not alloc without acts before locking. */
1221 reply = ovs_flow_cmd_build_info(flow, ovs_header->dp_ifindex,
1222 info, OVS_FLOW_CMD_SET, false,
1225 if (IS_ERR(reply)) {
1226 error = PTR_ERR(reply);
1227 goto err_unlock_ovs;
1232 if (a[OVS_FLOW_ATTR_CLEAR])
1233 ovs_flow_stats_clear(flow);
1237 ovs_notify(&dp_flow_genl_family, reply, info);
1239 ovs_nla_free_flow_actions_rcu(old_acts);
1247 ovs_nla_free_flow_actions(acts);
1252 static int ovs_flow_cmd_get(struct sk_buff *skb, struct genl_info *info)
1254 struct nlattr **a = info->attrs;
1255 struct ovs_header *ovs_header = info->userhdr;
1256 struct net *net = sock_net(skb->sk);
1257 struct sw_flow_key key;
1258 struct sk_buff *reply;
1259 struct sw_flow *flow;
1260 struct datapath *dp;
1261 struct sw_flow_match match;
1262 struct sw_flow_id ufid;
1263 u32 ufid_flags = ovs_nla_get_ufid_flags(a[OVS_FLOW_ATTR_UFID_FLAGS]);
1265 bool log = !a[OVS_FLOW_ATTR_PROBE];
1268 ufid_present = ovs_nla_get_ufid(&ufid, a[OVS_FLOW_ATTR_UFID], log);
1269 if (a[OVS_FLOW_ATTR_KEY]) {
1270 ovs_match_init(&match, &key, true, NULL);
1271 err = ovs_nla_get_match(net, &match, a[OVS_FLOW_ATTR_KEY], NULL,
1273 } else if (!ufid_present) {
1275 "Flow get message rejected, Key attribute missing.");
1282 dp = get_dp(sock_net(skb->sk), ovs_header->dp_ifindex);
1289 flow = ovs_flow_tbl_lookup_ufid(&dp->table, &ufid);
1291 flow = ovs_flow_tbl_lookup_exact(&dp->table, &match);
1297 reply = ovs_flow_cmd_build_info(flow, ovs_header->dp_ifindex, info,
1298 OVS_FLOW_CMD_GET, true, ufid_flags);
1299 if (IS_ERR(reply)) {
1300 err = PTR_ERR(reply);
1305 return genlmsg_reply(reply, info);
1311 static int ovs_flow_cmd_del(struct sk_buff *skb, struct genl_info *info)
1313 struct nlattr **a = info->attrs;
1314 struct ovs_header *ovs_header = info->userhdr;
1315 struct net *net = sock_net(skb->sk);
1316 struct sw_flow_key key;
1317 struct sk_buff *reply;
1318 struct sw_flow *flow = NULL;
1319 struct datapath *dp;
1320 struct sw_flow_match match;
1321 struct sw_flow_id ufid;
1322 u32 ufid_flags = ovs_nla_get_ufid_flags(a[OVS_FLOW_ATTR_UFID_FLAGS]);
1324 bool log = !a[OVS_FLOW_ATTR_PROBE];
1327 ufid_present = ovs_nla_get_ufid(&ufid, a[OVS_FLOW_ATTR_UFID], log);
1328 if (a[OVS_FLOW_ATTR_KEY]) {
1329 ovs_match_init(&match, &key, true, NULL);
1330 err = ovs_nla_get_match(net, &match, a[OVS_FLOW_ATTR_KEY],
1337 dp = get_dp(sock_net(skb->sk), ovs_header->dp_ifindex);
1338 if (unlikely(!dp)) {
1343 if (unlikely(!a[OVS_FLOW_ATTR_KEY] && !ufid_present)) {
1344 err = ovs_flow_tbl_flush(&dp->table);
1349 flow = ovs_flow_tbl_lookup_ufid(&dp->table, &ufid);
1351 flow = ovs_flow_tbl_lookup_exact(&dp->table, &match);
1352 if (unlikely(!flow)) {
1357 ovs_flow_tbl_remove(&dp->table, flow);
1360 reply = ovs_flow_cmd_alloc_info((const struct sw_flow_actions __force *) flow->sf_acts,
1361 &flow->id, info, false, ufid_flags);
1362 if (likely(reply)) {
1363 if (!IS_ERR(reply)) {
1364 rcu_read_lock(); /*To keep RCU checker happy. */
1365 err = ovs_flow_cmd_fill_info(flow, ovs_header->dp_ifindex,
1366 reply, info->snd_portid,
1371 if (WARN_ON_ONCE(err < 0)) {
1376 ovs_notify(&dp_flow_genl_family, reply, info);
1378 netlink_set_err(sock_net(skb->sk)->genl_sock, 0, 0, PTR_ERR(reply));
1383 ovs_flow_free(flow, true);
1390 static int ovs_flow_cmd_dump(struct sk_buff *skb, struct netlink_callback *cb)
1392 struct nlattr *a[__OVS_FLOW_ATTR_MAX];
1393 struct ovs_header *ovs_header = genlmsg_data(nlmsg_data(cb->nlh));
1394 struct table_instance *ti;
1395 struct datapath *dp;
1399 err = genlmsg_parse_deprecated(cb->nlh, &dp_flow_genl_family, a,
1400 OVS_FLOW_ATTR_MAX, flow_policy, NULL);
1403 ufid_flags = ovs_nla_get_ufid_flags(a[OVS_FLOW_ATTR_UFID_FLAGS]);
1406 dp = get_dp_rcu(sock_net(skb->sk), ovs_header->dp_ifindex);
1412 ti = rcu_dereference(dp->table.ti);
1414 struct sw_flow *flow;
1417 bucket = cb->args[0];
1419 flow = ovs_flow_tbl_dump_next(ti, &bucket, &obj);
1423 if (ovs_flow_cmd_fill_info(flow, ovs_header->dp_ifindex, skb,
1424 NETLINK_CB(cb->skb).portid,
1425 cb->nlh->nlmsg_seq, NLM_F_MULTI,
1426 OVS_FLOW_CMD_GET, ufid_flags) < 0)
1429 cb->args[0] = bucket;
1436 static const struct nla_policy flow_policy[OVS_FLOW_ATTR_MAX + 1] = {
1437 [OVS_FLOW_ATTR_KEY] = { .type = NLA_NESTED },
1438 [OVS_FLOW_ATTR_MASK] = { .type = NLA_NESTED },
1439 [OVS_FLOW_ATTR_ACTIONS] = { .type = NLA_NESTED },
1440 [OVS_FLOW_ATTR_CLEAR] = { .type = NLA_FLAG },
1441 [OVS_FLOW_ATTR_PROBE] = { .type = NLA_FLAG },
1442 [OVS_FLOW_ATTR_UFID] = { .type = NLA_UNSPEC, .len = 1 },
1443 [OVS_FLOW_ATTR_UFID_FLAGS] = { .type = NLA_U32 },
1446 static const struct genl_ops dp_flow_genl_ops[] = {
1447 { .cmd = OVS_FLOW_CMD_NEW,
1448 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
1449 .flags = GENL_UNS_ADMIN_PERM, /* Requires CAP_NET_ADMIN privilege. */
1450 .doit = ovs_flow_cmd_new
1452 { .cmd = OVS_FLOW_CMD_DEL,
1453 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
1454 .flags = GENL_UNS_ADMIN_PERM, /* Requires CAP_NET_ADMIN privilege. */
1455 .doit = ovs_flow_cmd_del
1457 { .cmd = OVS_FLOW_CMD_GET,
1458 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
1459 .flags = 0, /* OK for unprivileged users. */
1460 .doit = ovs_flow_cmd_get,
1461 .dumpit = ovs_flow_cmd_dump
1463 { .cmd = OVS_FLOW_CMD_SET,
1464 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
1465 .flags = GENL_UNS_ADMIN_PERM, /* Requires CAP_NET_ADMIN privilege. */
1466 .doit = ovs_flow_cmd_set,
1470 static struct genl_family dp_flow_genl_family __ro_after_init = {
1471 .hdrsize = sizeof(struct ovs_header),
1472 .name = OVS_FLOW_FAMILY,
1473 .version = OVS_FLOW_VERSION,
1474 .maxattr = OVS_FLOW_ATTR_MAX,
1475 .policy = flow_policy,
1477 .parallel_ops = true,
1478 .ops = dp_flow_genl_ops,
1479 .n_ops = ARRAY_SIZE(dp_flow_genl_ops),
1480 .mcgrps = &ovs_dp_flow_multicast_group,
1482 .module = THIS_MODULE,
1485 static size_t ovs_dp_cmd_msg_size(void)
1487 size_t msgsize = NLMSG_ALIGN(sizeof(struct ovs_header));
1489 msgsize += nla_total_size(IFNAMSIZ);
1490 msgsize += nla_total_size_64bit(sizeof(struct ovs_dp_stats));
1491 msgsize += nla_total_size_64bit(sizeof(struct ovs_dp_megaflow_stats));
1492 msgsize += nla_total_size(sizeof(u32)); /* OVS_DP_ATTR_USER_FEATURES */
1497 /* Called with ovs_mutex. */
1498 static int ovs_dp_cmd_fill_info(struct datapath *dp, struct sk_buff *skb,
1499 u32 portid, u32 seq, u32 flags, u8 cmd)
1501 struct ovs_header *ovs_header;
1502 struct ovs_dp_stats dp_stats;
1503 struct ovs_dp_megaflow_stats dp_megaflow_stats;
1506 ovs_header = genlmsg_put(skb, portid, seq, &dp_datapath_genl_family,
1511 ovs_header->dp_ifindex = get_dpifindex(dp);
1513 err = nla_put_string(skb, OVS_DP_ATTR_NAME, ovs_dp_name(dp));
1515 goto nla_put_failure;
1517 get_dp_stats(dp, &dp_stats, &dp_megaflow_stats);
1518 if (nla_put_64bit(skb, OVS_DP_ATTR_STATS, sizeof(struct ovs_dp_stats),
1519 &dp_stats, OVS_DP_ATTR_PAD))
1520 goto nla_put_failure;
1522 if (nla_put_64bit(skb, OVS_DP_ATTR_MEGAFLOW_STATS,
1523 sizeof(struct ovs_dp_megaflow_stats),
1524 &dp_megaflow_stats, OVS_DP_ATTR_PAD))
1525 goto nla_put_failure;
1527 if (nla_put_u32(skb, OVS_DP_ATTR_USER_FEATURES, dp->user_features))
1528 goto nla_put_failure;
1530 genlmsg_end(skb, ovs_header);
1534 genlmsg_cancel(skb, ovs_header);
1539 static struct sk_buff *ovs_dp_cmd_alloc_info(void)
1541 return genlmsg_new(ovs_dp_cmd_msg_size(), GFP_KERNEL);
1544 /* Called with rcu_read_lock or ovs_mutex. */
1545 static struct datapath *lookup_datapath(struct net *net,
1546 const struct ovs_header *ovs_header,
1547 struct nlattr *a[OVS_DP_ATTR_MAX + 1])
1549 struct datapath *dp;
1551 if (!a[OVS_DP_ATTR_NAME])
1552 dp = get_dp(net, ovs_header->dp_ifindex);
1554 struct vport *vport;
1556 vport = ovs_vport_locate(net, nla_data(a[OVS_DP_ATTR_NAME]));
1557 dp = vport && vport->port_no == OVSP_LOCAL ? vport->dp : NULL;
1559 return dp ? dp : ERR_PTR(-ENODEV);
1562 static void ovs_dp_reset_user_features(struct sk_buff *skb, struct genl_info *info)
1564 struct datapath *dp;
1566 dp = lookup_datapath(sock_net(skb->sk), info->userhdr, info->attrs);
1570 pr_warn("%s: Dropping previously announced user features\n",
1572 dp->user_features = 0;
1575 DEFINE_STATIC_KEY_FALSE(tc_recirc_sharing_support);
1577 static int ovs_dp_change(struct datapath *dp, struct nlattr *a[])
1579 u32 user_features = 0;
1581 if (a[OVS_DP_ATTR_USER_FEATURES]) {
1582 user_features = nla_get_u32(a[OVS_DP_ATTR_USER_FEATURES]);
1584 if (user_features & ~(OVS_DP_F_VPORT_PIDS |
1585 OVS_DP_F_UNALIGNED |
1586 OVS_DP_F_TC_RECIRC_SHARING))
1589 #if !IS_ENABLED(CONFIG_NET_TC_SKB_EXT)
1590 if (user_features & OVS_DP_F_TC_RECIRC_SHARING)
1595 dp->user_features = user_features;
1597 if (dp->user_features & OVS_DP_F_TC_RECIRC_SHARING)
1598 static_branch_enable(&tc_recirc_sharing_support);
1600 static_branch_disable(&tc_recirc_sharing_support);
1605 static int ovs_dp_cmd_new(struct sk_buff *skb, struct genl_info *info)
1607 struct nlattr **a = info->attrs;
1608 struct vport_parms parms;
1609 struct sk_buff *reply;
1610 struct datapath *dp;
1611 struct vport *vport;
1612 struct ovs_net *ovs_net;
1616 if (!a[OVS_DP_ATTR_NAME] || !a[OVS_DP_ATTR_UPCALL_PID])
1619 reply = ovs_dp_cmd_alloc_info();
1624 dp = kzalloc(sizeof(*dp), GFP_KERNEL);
1626 goto err_free_reply;
1628 ovs_dp_set_net(dp, sock_net(skb->sk));
1630 /* Allocate table. */
1631 err = ovs_flow_tbl_init(&dp->table);
1635 dp->stats_percpu = netdev_alloc_pcpu_stats(struct dp_stats_percpu);
1636 if (!dp->stats_percpu) {
1638 goto err_destroy_table;
1641 dp->ports = kmalloc_array(DP_VPORT_HASH_BUCKETS,
1642 sizeof(struct hlist_head),
1646 goto err_destroy_percpu;
1649 for (i = 0; i < DP_VPORT_HASH_BUCKETS; i++)
1650 INIT_HLIST_HEAD(&dp->ports[i]);
1652 err = ovs_meters_init(dp);
1654 goto err_destroy_ports_array;
1656 /* Set up our datapath device. */
1657 parms.name = nla_data(a[OVS_DP_ATTR_NAME]);
1658 parms.type = OVS_VPORT_TYPE_INTERNAL;
1659 parms.options = NULL;
1661 parms.port_no = OVSP_LOCAL;
1662 parms.upcall_portids = a[OVS_DP_ATTR_UPCALL_PID];
1664 err = ovs_dp_change(dp, a);
1666 goto err_destroy_meters;
1668 /* So far only local changes have been made, now need the lock. */
1671 vport = new_vport(&parms);
1672 if (IS_ERR(vport)) {
1673 err = PTR_ERR(vport);
1677 if (err == -EEXIST) {
1678 /* An outdated user space instance that does not understand
1679 * the concept of user_features has attempted to create a new
1680 * datapath and is likely to reuse it. Drop all user features.
1682 if (info->genlhdr->version < OVS_DP_VER_FEATURES)
1683 ovs_dp_reset_user_features(skb, info);
1687 goto err_destroy_meters;
1690 err = ovs_dp_cmd_fill_info(dp, reply, info->snd_portid,
1691 info->snd_seq, 0, OVS_DP_CMD_NEW);
1694 ovs_net = net_generic(ovs_dp_get_net(dp), ovs_net_id);
1695 list_add_tail_rcu(&dp->list_node, &ovs_net->dps);
1699 ovs_notify(&dp_datapath_genl_family, reply, info);
1703 ovs_meters_exit(dp);
1704 err_destroy_ports_array:
1707 free_percpu(dp->stats_percpu);
1709 ovs_flow_tbl_destroy(&dp->table);
1718 /* Called with ovs_mutex. */
1719 static void __dp_destroy(struct datapath *dp)
1723 for (i = 0; i < DP_VPORT_HASH_BUCKETS; i++) {
1724 struct vport *vport;
1725 struct hlist_node *n;
1727 hlist_for_each_entry_safe(vport, n, &dp->ports[i], dp_hash_node)
1728 if (vport->port_no != OVSP_LOCAL)
1729 ovs_dp_detach_port(vport);
1732 list_del_rcu(&dp->list_node);
1734 /* OVSP_LOCAL is datapath internal port. We need to make sure that
1735 * all ports in datapath are destroyed first before freeing datapath.
1737 ovs_dp_detach_port(ovs_vport_ovsl(dp, OVSP_LOCAL));
1739 /* RCU destroy the flow table */
1740 call_rcu(&dp->rcu, destroy_dp_rcu);
1743 static int ovs_dp_cmd_del(struct sk_buff *skb, struct genl_info *info)
1745 struct sk_buff *reply;
1746 struct datapath *dp;
1749 reply = ovs_dp_cmd_alloc_info();
1754 dp = lookup_datapath(sock_net(skb->sk), info->userhdr, info->attrs);
1757 goto err_unlock_free;
1759 err = ovs_dp_cmd_fill_info(dp, reply, info->snd_portid,
1760 info->snd_seq, 0, OVS_DP_CMD_DEL);
1766 ovs_notify(&dp_datapath_genl_family, reply, info);
1776 static int ovs_dp_cmd_set(struct sk_buff *skb, struct genl_info *info)
1778 struct sk_buff *reply;
1779 struct datapath *dp;
1782 reply = ovs_dp_cmd_alloc_info();
1787 dp = lookup_datapath(sock_net(skb->sk), info->userhdr, info->attrs);
1790 goto err_unlock_free;
1792 err = ovs_dp_change(dp, info->attrs);
1794 goto err_unlock_free;
1796 err = ovs_dp_cmd_fill_info(dp, reply, info->snd_portid,
1797 info->snd_seq, 0, OVS_DP_CMD_SET);
1801 ovs_notify(&dp_datapath_genl_family, reply, info);
1811 static int ovs_dp_cmd_get(struct sk_buff *skb, struct genl_info *info)
1813 struct sk_buff *reply;
1814 struct datapath *dp;
1817 reply = ovs_dp_cmd_alloc_info();
1822 dp = lookup_datapath(sock_net(skb->sk), info->userhdr, info->attrs);
1825 goto err_unlock_free;
1827 err = ovs_dp_cmd_fill_info(dp, reply, info->snd_portid,
1828 info->snd_seq, 0, OVS_DP_CMD_GET);
1832 return genlmsg_reply(reply, info);
1840 static int ovs_dp_cmd_dump(struct sk_buff *skb, struct netlink_callback *cb)
1842 struct ovs_net *ovs_net = net_generic(sock_net(skb->sk), ovs_net_id);
1843 struct datapath *dp;
1844 int skip = cb->args[0];
1848 list_for_each_entry(dp, &ovs_net->dps, list_node) {
1850 ovs_dp_cmd_fill_info(dp, skb, NETLINK_CB(cb->skb).portid,
1851 cb->nlh->nlmsg_seq, NLM_F_MULTI,
1852 OVS_DP_CMD_GET) < 0)
1863 static const struct nla_policy datapath_policy[OVS_DP_ATTR_MAX + 1] = {
1864 [OVS_DP_ATTR_NAME] = { .type = NLA_NUL_STRING, .len = IFNAMSIZ - 1 },
1865 [OVS_DP_ATTR_UPCALL_PID] = { .type = NLA_U32 },
1866 [OVS_DP_ATTR_USER_FEATURES] = { .type = NLA_U32 },
1869 static const struct genl_ops dp_datapath_genl_ops[] = {
1870 { .cmd = OVS_DP_CMD_NEW,
1871 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
1872 .flags = GENL_UNS_ADMIN_PERM, /* Requires CAP_NET_ADMIN privilege. */
1873 .doit = ovs_dp_cmd_new
1875 { .cmd = OVS_DP_CMD_DEL,
1876 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
1877 .flags = GENL_UNS_ADMIN_PERM, /* Requires CAP_NET_ADMIN privilege. */
1878 .doit = ovs_dp_cmd_del
1880 { .cmd = OVS_DP_CMD_GET,
1881 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
1882 .flags = 0, /* OK for unprivileged users. */
1883 .doit = ovs_dp_cmd_get,
1884 .dumpit = ovs_dp_cmd_dump
1886 { .cmd = OVS_DP_CMD_SET,
1887 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
1888 .flags = GENL_UNS_ADMIN_PERM, /* Requires CAP_NET_ADMIN privilege. */
1889 .doit = ovs_dp_cmd_set,
1893 static struct genl_family dp_datapath_genl_family __ro_after_init = {
1894 .hdrsize = sizeof(struct ovs_header),
1895 .name = OVS_DATAPATH_FAMILY,
1896 .version = OVS_DATAPATH_VERSION,
1897 .maxattr = OVS_DP_ATTR_MAX,
1898 .policy = datapath_policy,
1900 .parallel_ops = true,
1901 .ops = dp_datapath_genl_ops,
1902 .n_ops = ARRAY_SIZE(dp_datapath_genl_ops),
1903 .mcgrps = &ovs_dp_datapath_multicast_group,
1905 .module = THIS_MODULE,
1908 /* Called with ovs_mutex or RCU read lock. */
1909 static int ovs_vport_cmd_fill_info(struct vport *vport, struct sk_buff *skb,
1910 struct net *net, u32 portid, u32 seq,
1911 u32 flags, u8 cmd, gfp_t gfp)
1913 struct ovs_header *ovs_header;
1914 struct ovs_vport_stats vport_stats;
1917 ovs_header = genlmsg_put(skb, portid, seq, &dp_vport_genl_family,
1922 ovs_header->dp_ifindex = get_dpifindex(vport->dp);
1924 if (nla_put_u32(skb, OVS_VPORT_ATTR_PORT_NO, vport->port_no) ||
1925 nla_put_u32(skb, OVS_VPORT_ATTR_TYPE, vport->ops->type) ||
1926 nla_put_string(skb, OVS_VPORT_ATTR_NAME,
1927 ovs_vport_name(vport)) ||
1928 nla_put_u32(skb, OVS_VPORT_ATTR_IFINDEX, vport->dev->ifindex))
1929 goto nla_put_failure;
1931 if (!net_eq(net, dev_net(vport->dev))) {
1932 int id = peernet2id_alloc(net, dev_net(vport->dev), gfp);
1934 if (nla_put_s32(skb, OVS_VPORT_ATTR_NETNSID, id))
1935 goto nla_put_failure;
1938 ovs_vport_get_stats(vport, &vport_stats);
1939 if (nla_put_64bit(skb, OVS_VPORT_ATTR_STATS,
1940 sizeof(struct ovs_vport_stats), &vport_stats,
1941 OVS_VPORT_ATTR_PAD))
1942 goto nla_put_failure;
1944 if (ovs_vport_get_upcall_portids(vport, skb))
1945 goto nla_put_failure;
1947 err = ovs_vport_get_options(vport, skb);
1948 if (err == -EMSGSIZE)
1951 genlmsg_end(skb, ovs_header);
1957 genlmsg_cancel(skb, ovs_header);
1961 static struct sk_buff *ovs_vport_cmd_alloc_info(void)
1963 return nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
1966 /* Called with ovs_mutex, only via ovs_dp_notify_wq(). */
1967 struct sk_buff *ovs_vport_cmd_build_info(struct vport *vport, struct net *net,
1968 u32 portid, u32 seq, u8 cmd)
1970 struct sk_buff *skb;
1973 skb = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
1975 return ERR_PTR(-ENOMEM);
1977 retval = ovs_vport_cmd_fill_info(vport, skb, net, portid, seq, 0, cmd,
1984 /* Called with ovs_mutex or RCU read lock. */
1985 static struct vport *lookup_vport(struct net *net,
1986 const struct ovs_header *ovs_header,
1987 struct nlattr *a[OVS_VPORT_ATTR_MAX + 1])
1989 struct datapath *dp;
1990 struct vport *vport;
1992 if (a[OVS_VPORT_ATTR_IFINDEX])
1993 return ERR_PTR(-EOPNOTSUPP);
1994 if (a[OVS_VPORT_ATTR_NAME]) {
1995 vport = ovs_vport_locate(net, nla_data(a[OVS_VPORT_ATTR_NAME]));
1997 return ERR_PTR(-ENODEV);
1998 if (ovs_header->dp_ifindex &&
1999 ovs_header->dp_ifindex != get_dpifindex(vport->dp))
2000 return ERR_PTR(-ENODEV);
2002 } else if (a[OVS_VPORT_ATTR_PORT_NO]) {
2003 u32 port_no = nla_get_u32(a[OVS_VPORT_ATTR_PORT_NO]);
2005 if (port_no >= DP_MAX_PORTS)
2006 return ERR_PTR(-EFBIG);
2008 dp = get_dp(net, ovs_header->dp_ifindex);
2010 return ERR_PTR(-ENODEV);
2012 vport = ovs_vport_ovsl_rcu(dp, port_no);
2014 return ERR_PTR(-ENODEV);
2017 return ERR_PTR(-EINVAL);
2021 static unsigned int ovs_get_max_headroom(struct datapath *dp)
2023 unsigned int dev_headroom, max_headroom = 0;
2024 struct net_device *dev;
2025 struct vport *vport;
2028 for (i = 0; i < DP_VPORT_HASH_BUCKETS; i++) {
2029 hlist_for_each_entry_rcu(vport, &dp->ports[i], dp_hash_node) {
2031 dev_headroom = netdev_get_fwd_headroom(dev);
2032 if (dev_headroom > max_headroom)
2033 max_headroom = dev_headroom;
2037 return max_headroom;
2040 /* Called with ovs_mutex */
2041 static void ovs_update_headroom(struct datapath *dp, unsigned int new_headroom)
2043 struct vport *vport;
2046 dp->max_headroom = new_headroom;
2047 for (i = 0; i < DP_VPORT_HASH_BUCKETS; i++)
2048 hlist_for_each_entry_rcu(vport, &dp->ports[i], dp_hash_node)
2049 netdev_set_rx_headroom(vport->dev, new_headroom);
2052 static int ovs_vport_cmd_new(struct sk_buff *skb, struct genl_info *info)
2054 struct nlattr **a = info->attrs;
2055 struct ovs_header *ovs_header = info->userhdr;
2056 struct vport_parms parms;
2057 struct sk_buff *reply;
2058 struct vport *vport;
2059 struct datapath *dp;
2060 unsigned int new_headroom;
2064 if (!a[OVS_VPORT_ATTR_NAME] || !a[OVS_VPORT_ATTR_TYPE] ||
2065 !a[OVS_VPORT_ATTR_UPCALL_PID])
2067 if (a[OVS_VPORT_ATTR_IFINDEX])
2070 port_no = a[OVS_VPORT_ATTR_PORT_NO]
2071 ? nla_get_u32(a[OVS_VPORT_ATTR_PORT_NO]) : 0;
2072 if (port_no >= DP_MAX_PORTS)
2075 reply = ovs_vport_cmd_alloc_info();
2081 dp = get_dp(sock_net(skb->sk), ovs_header->dp_ifindex);
2084 goto exit_unlock_free;
2087 vport = ovs_vport_ovsl(dp, port_no);
2090 goto exit_unlock_free;
2092 for (port_no = 1; ; port_no++) {
2093 if (port_no >= DP_MAX_PORTS) {
2095 goto exit_unlock_free;
2097 vport = ovs_vport_ovsl(dp, port_no);
2103 parms.name = nla_data(a[OVS_VPORT_ATTR_NAME]);
2104 parms.type = nla_get_u32(a[OVS_VPORT_ATTR_TYPE]);
2105 parms.options = a[OVS_VPORT_ATTR_OPTIONS];
2107 parms.port_no = port_no;
2108 parms.upcall_portids = a[OVS_VPORT_ATTR_UPCALL_PID];
2110 vport = new_vport(&parms);
2111 err = PTR_ERR(vport);
2112 if (IS_ERR(vport)) {
2115 goto exit_unlock_free;
2118 err = ovs_vport_cmd_fill_info(vport, reply, genl_info_net(info),
2119 info->snd_portid, info->snd_seq, 0,
2120 OVS_VPORT_CMD_NEW, GFP_KERNEL);
2122 new_headroom = netdev_get_fwd_headroom(vport->dev);
2124 if (new_headroom > dp->max_headroom)
2125 ovs_update_headroom(dp, new_headroom);
2127 netdev_set_rx_headroom(vport->dev, dp->max_headroom);
2132 ovs_notify(&dp_vport_genl_family, reply, info);
2141 static int ovs_vport_cmd_set(struct sk_buff *skb, struct genl_info *info)
2143 struct nlattr **a = info->attrs;
2144 struct sk_buff *reply;
2145 struct vport *vport;
2148 reply = ovs_vport_cmd_alloc_info();
2153 vport = lookup_vport(sock_net(skb->sk), info->userhdr, a);
2154 err = PTR_ERR(vport);
2156 goto exit_unlock_free;
2158 if (a[OVS_VPORT_ATTR_TYPE] &&
2159 nla_get_u32(a[OVS_VPORT_ATTR_TYPE]) != vport->ops->type) {
2161 goto exit_unlock_free;
2164 if (a[OVS_VPORT_ATTR_OPTIONS]) {
2165 err = ovs_vport_set_options(vport, a[OVS_VPORT_ATTR_OPTIONS]);
2167 goto exit_unlock_free;
2171 if (a[OVS_VPORT_ATTR_UPCALL_PID]) {
2172 struct nlattr *ids = a[OVS_VPORT_ATTR_UPCALL_PID];
2174 err = ovs_vport_set_upcall_portids(vport, ids);
2176 goto exit_unlock_free;
2179 err = ovs_vport_cmd_fill_info(vport, reply, genl_info_net(info),
2180 info->snd_portid, info->snd_seq, 0,
2181 OVS_VPORT_CMD_SET, GFP_KERNEL);
2185 ovs_notify(&dp_vport_genl_family, reply, info);
2194 static int ovs_vport_cmd_del(struct sk_buff *skb, struct genl_info *info)
2196 bool update_headroom = false;
2197 struct nlattr **a = info->attrs;
2198 struct sk_buff *reply;
2199 struct datapath *dp;
2200 struct vport *vport;
2201 unsigned int new_headroom;
2204 reply = ovs_vport_cmd_alloc_info();
2209 vport = lookup_vport(sock_net(skb->sk), info->userhdr, a);
2210 err = PTR_ERR(vport);
2212 goto exit_unlock_free;
2214 if (vport->port_no == OVSP_LOCAL) {
2216 goto exit_unlock_free;
2219 err = ovs_vport_cmd_fill_info(vport, reply, genl_info_net(info),
2220 info->snd_portid, info->snd_seq, 0,
2221 OVS_VPORT_CMD_DEL, GFP_KERNEL);
2224 /* the vport deletion may trigger dp headroom update */
2226 if (netdev_get_fwd_headroom(vport->dev) == dp->max_headroom)
2227 update_headroom = true;
2229 netdev_reset_rx_headroom(vport->dev);
2230 ovs_dp_detach_port(vport);
2232 if (update_headroom) {
2233 new_headroom = ovs_get_max_headroom(dp);
2235 if (new_headroom < dp->max_headroom)
2236 ovs_update_headroom(dp, new_headroom);
2240 ovs_notify(&dp_vport_genl_family, reply, info);
2249 static int ovs_vport_cmd_get(struct sk_buff *skb, struct genl_info *info)
2251 struct nlattr **a = info->attrs;
2252 struct ovs_header *ovs_header = info->userhdr;
2253 struct sk_buff *reply;
2254 struct vport *vport;
2257 reply = ovs_vport_cmd_alloc_info();
2262 vport = lookup_vport(sock_net(skb->sk), ovs_header, a);
2263 err = PTR_ERR(vport);
2265 goto exit_unlock_free;
2266 err = ovs_vport_cmd_fill_info(vport, reply, genl_info_net(info),
2267 info->snd_portid, info->snd_seq, 0,
2268 OVS_VPORT_CMD_GET, GFP_ATOMIC);
2272 return genlmsg_reply(reply, info);
2280 static int ovs_vport_cmd_dump(struct sk_buff *skb, struct netlink_callback *cb)
2282 struct ovs_header *ovs_header = genlmsg_data(nlmsg_data(cb->nlh));
2283 struct datapath *dp;
2284 int bucket = cb->args[0], skip = cb->args[1];
2288 dp = get_dp_rcu(sock_net(skb->sk), ovs_header->dp_ifindex);
2293 for (i = bucket; i < DP_VPORT_HASH_BUCKETS; i++) {
2294 struct vport *vport;
2297 hlist_for_each_entry_rcu(vport, &dp->ports[i], dp_hash_node) {
2299 ovs_vport_cmd_fill_info(vport, skb,
2301 NETLINK_CB(cb->skb).portid,
2321 static const struct nla_policy vport_policy[OVS_VPORT_ATTR_MAX + 1] = {
2322 [OVS_VPORT_ATTR_NAME] = { .type = NLA_NUL_STRING, .len = IFNAMSIZ - 1 },
2323 [OVS_VPORT_ATTR_STATS] = { .len = sizeof(struct ovs_vport_stats) },
2324 [OVS_VPORT_ATTR_PORT_NO] = { .type = NLA_U32 },
2325 [OVS_VPORT_ATTR_TYPE] = { .type = NLA_U32 },
2326 [OVS_VPORT_ATTR_UPCALL_PID] = { .type = NLA_UNSPEC },
2327 [OVS_VPORT_ATTR_OPTIONS] = { .type = NLA_NESTED },
2328 [OVS_VPORT_ATTR_IFINDEX] = { .type = NLA_U32 },
2329 [OVS_VPORT_ATTR_NETNSID] = { .type = NLA_S32 },
2332 static const struct genl_ops dp_vport_genl_ops[] = {
2333 { .cmd = OVS_VPORT_CMD_NEW,
2334 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
2335 .flags = GENL_UNS_ADMIN_PERM, /* Requires CAP_NET_ADMIN privilege. */
2336 .doit = ovs_vport_cmd_new
2338 { .cmd = OVS_VPORT_CMD_DEL,
2339 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
2340 .flags = GENL_UNS_ADMIN_PERM, /* Requires CAP_NET_ADMIN privilege. */
2341 .doit = ovs_vport_cmd_del
2343 { .cmd = OVS_VPORT_CMD_GET,
2344 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
2345 .flags = 0, /* OK for unprivileged users. */
2346 .doit = ovs_vport_cmd_get,
2347 .dumpit = ovs_vport_cmd_dump
2349 { .cmd = OVS_VPORT_CMD_SET,
2350 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
2351 .flags = GENL_UNS_ADMIN_PERM, /* Requires CAP_NET_ADMIN privilege. */
2352 .doit = ovs_vport_cmd_set,
2356 struct genl_family dp_vport_genl_family __ro_after_init = {
2357 .hdrsize = sizeof(struct ovs_header),
2358 .name = OVS_VPORT_FAMILY,
2359 .version = OVS_VPORT_VERSION,
2360 .maxattr = OVS_VPORT_ATTR_MAX,
2361 .policy = vport_policy,
2363 .parallel_ops = true,
2364 .ops = dp_vport_genl_ops,
2365 .n_ops = ARRAY_SIZE(dp_vport_genl_ops),
2366 .mcgrps = &ovs_dp_vport_multicast_group,
2368 .module = THIS_MODULE,
2371 static struct genl_family * const dp_genl_families[] = {
2372 &dp_datapath_genl_family,
2373 &dp_vport_genl_family,
2374 &dp_flow_genl_family,
2375 &dp_packet_genl_family,
2376 &dp_meter_genl_family,
2377 #if IS_ENABLED(CONFIG_NETFILTER_CONNCOUNT)
2378 &dp_ct_limit_genl_family,
2382 static void dp_unregister_genl(int n_families)
2386 for (i = 0; i < n_families; i++)
2387 genl_unregister_family(dp_genl_families[i]);
2390 static int __init dp_register_genl(void)
2395 for (i = 0; i < ARRAY_SIZE(dp_genl_families); i++) {
2397 err = genl_register_family(dp_genl_families[i]);
2405 dp_unregister_genl(i);
2409 static int __net_init ovs_init_net(struct net *net)
2411 struct ovs_net *ovs_net = net_generic(net, ovs_net_id);
2413 INIT_LIST_HEAD(&ovs_net->dps);
2414 INIT_WORK(&ovs_net->dp_notify_work, ovs_dp_notify_wq);
2415 return ovs_ct_init(net);
2418 static void __net_exit list_vports_from_net(struct net *net, struct net *dnet,
2419 struct list_head *head)
2421 struct ovs_net *ovs_net = net_generic(net, ovs_net_id);
2422 struct datapath *dp;
2424 list_for_each_entry(dp, &ovs_net->dps, list_node) {
2427 for (i = 0; i < DP_VPORT_HASH_BUCKETS; i++) {
2428 struct vport *vport;
2430 hlist_for_each_entry(vport, &dp->ports[i], dp_hash_node) {
2431 if (vport->ops->type != OVS_VPORT_TYPE_INTERNAL)
2434 if (dev_net(vport->dev) == dnet)
2435 list_add(&vport->detach_list, head);
2441 static void __net_exit ovs_exit_net(struct net *dnet)
2443 struct datapath *dp, *dp_next;
2444 struct ovs_net *ovs_net = net_generic(dnet, ovs_net_id);
2445 struct vport *vport, *vport_next;
2453 list_for_each_entry_safe(dp, dp_next, &ovs_net->dps, list_node)
2456 down_read(&net_rwsem);
2458 list_vports_from_net(net, dnet, &head);
2459 up_read(&net_rwsem);
2461 /* Detach all vports from given namespace. */
2462 list_for_each_entry_safe(vport, vport_next, &head, detach_list) {
2463 list_del(&vport->detach_list);
2464 ovs_dp_detach_port(vport);
2469 cancel_work_sync(&ovs_net->dp_notify_work);
2472 static struct pernet_operations ovs_net_ops = {
2473 .init = ovs_init_net,
2474 .exit = ovs_exit_net,
2476 .size = sizeof(struct ovs_net),
2479 static int __init dp_init(void)
2483 BUILD_BUG_ON(sizeof(struct ovs_skb_cb) > FIELD_SIZEOF(struct sk_buff, cb));
2485 pr_info("Open vSwitch switching datapath\n");
2487 err = action_fifos_init();
2491 err = ovs_internal_dev_rtnl_link_register();
2493 goto error_action_fifos_exit;
2495 err = ovs_flow_init();
2497 goto error_unreg_rtnl_link;
2499 err = ovs_vport_init();
2501 goto error_flow_exit;
2503 err = register_pernet_device(&ovs_net_ops);
2505 goto error_vport_exit;
2507 err = register_netdevice_notifier(&ovs_dp_device_notifier);
2509 goto error_netns_exit;
2511 err = ovs_netdev_init();
2513 goto error_unreg_notifier;
2515 err = dp_register_genl();
2517 goto error_unreg_netdev;
2523 error_unreg_notifier:
2524 unregister_netdevice_notifier(&ovs_dp_device_notifier);
2526 unregister_pernet_device(&ovs_net_ops);
2531 error_unreg_rtnl_link:
2532 ovs_internal_dev_rtnl_link_unregister();
2533 error_action_fifos_exit:
2534 action_fifos_exit();
2539 static void dp_cleanup(void)
2541 dp_unregister_genl(ARRAY_SIZE(dp_genl_families));
2543 unregister_netdevice_notifier(&ovs_dp_device_notifier);
2544 unregister_pernet_device(&ovs_net_ops);
2548 ovs_internal_dev_rtnl_link_unregister();
2549 action_fifos_exit();
2552 module_init(dp_init);
2553 module_exit(dp_cleanup);
2555 MODULE_DESCRIPTION("Open vSwitch switching datapath");
2556 MODULE_LICENSE("GPL");
2557 MODULE_ALIAS_GENL_FAMILY(OVS_DATAPATH_FAMILY);
2558 MODULE_ALIAS_GENL_FAMILY(OVS_VPORT_FAMILY);
2559 MODULE_ALIAS_GENL_FAMILY(OVS_FLOW_FAMILY);
2560 MODULE_ALIAS_GENL_FAMILY(OVS_PACKET_FAMILY);
2561 MODULE_ALIAS_GENL_FAMILY(OVS_METER_FAMILY);
2562 MODULE_ALIAS_GENL_FAMILY(OVS_CT_LIMIT_FAMILY);