]> git.proxmox.com Git - ovs.git/blob - datapath/datapath.c
datapath: make generic netlink group const
[ovs.git] / datapath / datapath.c
1 /*
2 * Copyright (c) 2007-2015 Nicira, Inc.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of version 2 of the GNU General Public
6 * License as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
16 * 02110-1301, USA
17 */
18
19 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
20
21 #include <linux/init.h>
22 #include <linux/module.h>
23 #include <linux/if_arp.h>
24 #include <linux/if_vlan.h>
25 #include <linux/in.h>
26 #include <linux/ip.h>
27 #include <linux/jhash.h>
28 #include <linux/delay.h>
29 #include <linux/time.h>
30 #include <linux/etherdevice.h>
31 #include <linux/genetlink.h>
32 #include <linux/kernel.h>
33 #include <linux/kthread.h>
34 #include <linux/mutex.h>
35 #include <linux/percpu.h>
36 #include <linux/rcupdate.h>
37 #include <linux/tcp.h>
38 #include <linux/udp.h>
39 #include <linux/version.h>
40 #include <linux/ethtool.h>
41 #include <linux/wait.h>
42 #include <asm/div64.h>
43 #include <linux/highmem.h>
44 #include <linux/netfilter_bridge.h>
45 #include <linux/netfilter_ipv4.h>
46 #include <linux/inetdevice.h>
47 #include <linux/list.h>
48 #include <linux/openvswitch.h>
49 #include <linux/rculist.h>
50 #include <linux/dmi.h>
51 #include <net/genetlink.h>
52 #include <net/net_namespace.h>
53 #include <net/netns/generic.h>
54 #include <net/nsh.h>
55
56 #include "datapath.h"
57 #include "conntrack.h"
58 #include "flow.h"
59 #include "flow_table.h"
60 #include "flow_netlink.h"
61 #include "meter.h"
62 #include "gso.h"
63 #include "vport-internal_dev.h"
64 #include "vport-netdev.h"
65
66 unsigned int ovs_net_id __read_mostly;
67
68 static struct genl_family dp_packet_genl_family;
69 static struct genl_family dp_flow_genl_family;
70 static struct genl_family dp_datapath_genl_family;
71
72 static const struct nla_policy flow_policy[];
73
74 static const struct genl_multicast_group ovs_dp_flow_multicast_group = {
75 .name = OVS_FLOW_MCGROUP,
76 };
77
78 static const struct genl_multicast_group ovs_dp_datapath_multicast_group = {
79 .name = OVS_DATAPATH_MCGROUP,
80 };
81
82 const struct genl_multicast_group ovs_dp_vport_multicast_group = {
83 .name = OVS_VPORT_MCGROUP,
84 };
85
86 /* Check if need to build a reply message.
87 * OVS userspace sets the NLM_F_ECHO flag if it needs the reply.
88 */
89 static bool ovs_must_notify(struct genl_family *family, struct genl_info *info,
90 unsigned int group)
91 {
92 return info->nlhdr->nlmsg_flags & NLM_F_ECHO ||
93 genl_has_listeners(family, genl_info_net(info), group);
94 }
95
96 static void ovs_notify(struct genl_family *family,
97 const struct genl_multicast_group *grp,
98 struct sk_buff *skb, struct genl_info *info)
99 {
100 genl_notify(family, skb, info, GROUP_ID(grp), GFP_KERNEL);
101 }
102
103 /**
104 * DOC: Locking:
105 *
106 * All writes e.g. Writes to device state (add/remove datapath, port, set
107 * operations on vports, etc.), Writes to other state (flow table
108 * modifications, set miscellaneous datapath parameters, etc.) are protected
109 * by ovs_lock.
110 *
111 * Reads are protected by RCU.
112 *
113 * There are a few special cases (mostly stats) that have their own
114 * synchronization but they nest under all of above and don't interact with
115 * each other.
116 *
117 * The RTNL lock nests inside ovs_mutex.
118 */
119
120 static DEFINE_MUTEX(ovs_mutex);
121
122 void ovs_lock(void)
123 {
124 mutex_lock(&ovs_mutex);
125 }
126
127 void ovs_unlock(void)
128 {
129 mutex_unlock(&ovs_mutex);
130 }
131
132 #ifdef CONFIG_LOCKDEP
133 int lockdep_ovsl_is_held(void)
134 {
135 if (debug_locks)
136 return lockdep_is_held(&ovs_mutex);
137 else
138 return 1;
139 }
140 #endif
141
142 static int queue_gso_packets(struct datapath *dp, struct sk_buff *,
143 const struct sw_flow_key *,
144 const struct dp_upcall_info *,
145 uint32_t cutlen);
146 static int queue_userspace_packet(struct datapath *dp, struct sk_buff *,
147 const struct sw_flow_key *,
148 const struct dp_upcall_info *,
149 uint32_t cutlen);
150
151 /* Must be called with rcu_read_lock or ovs_mutex. */
152 const char *ovs_dp_name(const struct datapath *dp)
153 {
154 struct vport *vport = ovs_vport_ovsl_rcu(dp, OVSP_LOCAL);
155 return ovs_vport_name(vport);
156 }
157
158 static int get_dpifindex(const struct datapath *dp)
159 {
160 struct vport *local;
161 int ifindex;
162
163 rcu_read_lock();
164
165 local = ovs_vport_rcu(dp, OVSP_LOCAL);
166 if (local)
167 ifindex = local->dev->ifindex;
168 else
169 ifindex = 0;
170
171 rcu_read_unlock();
172
173 return ifindex;
174 }
175
176 static void destroy_dp_rcu(struct rcu_head *rcu)
177 {
178 struct datapath *dp = container_of(rcu, struct datapath, rcu);
179
180 ovs_flow_tbl_destroy(&dp->table);
181 free_percpu(dp->stats_percpu);
182 kfree(dp->ports);
183 ovs_meters_exit(dp);
184 kfree(dp);
185 }
186
187 static struct hlist_head *vport_hash_bucket(const struct datapath *dp,
188 u16 port_no)
189 {
190 return &dp->ports[port_no & (DP_VPORT_HASH_BUCKETS - 1)];
191 }
192
193 /* Called with ovs_mutex or RCU read lock. */
194 struct vport *ovs_lookup_vport(const struct datapath *dp, u16 port_no)
195 {
196 struct vport *vport;
197 struct hlist_head *head;
198
199 head = vport_hash_bucket(dp, port_no);
200 hlist_for_each_entry_rcu(vport, head, dp_hash_node) {
201 if (vport->port_no == port_no)
202 return vport;
203 }
204 return NULL;
205 }
206
207 /* Called with ovs_mutex. */
208 static struct vport *new_vport(const struct vport_parms *parms)
209 {
210 struct vport *vport;
211
212 vport = ovs_vport_add(parms);
213 if (!IS_ERR(vport)) {
214 struct datapath *dp = parms->dp;
215 struct hlist_head *head = vport_hash_bucket(dp, vport->port_no);
216
217 hlist_add_head_rcu(&vport->dp_hash_node, head);
218 }
219 return vport;
220 }
221
222 void ovs_dp_detach_port(struct vport *p)
223 {
224 ASSERT_OVSL();
225
226 /* First drop references to device. */
227 hlist_del_rcu(&p->dp_hash_node);
228
229 /* Then destroy it. */
230 ovs_vport_del(p);
231 }
232
233 /* Must be called with rcu_read_lock. */
234 void ovs_dp_process_packet(struct sk_buff *skb, struct sw_flow_key *key)
235 {
236 const struct vport *p = OVS_CB(skb)->input_vport;
237 struct datapath *dp = p->dp;
238 struct sw_flow *flow;
239 struct sw_flow_actions *sf_acts;
240 struct dp_stats_percpu *stats;
241 u64 *stats_counter;
242 u32 n_mask_hit;
243
244 stats = this_cpu_ptr(dp->stats_percpu);
245
246 /* Look up flow. */
247 flow = ovs_flow_tbl_lookup_stats(&dp->table, key, skb_get_hash(skb),
248 &n_mask_hit);
249 if (unlikely(!flow)) {
250 struct dp_upcall_info upcall;
251 int error;
252
253 memset(&upcall, 0, sizeof(upcall));
254 upcall.cmd = OVS_PACKET_CMD_MISS;
255 upcall.portid = ovs_vport_find_upcall_portid(p, skb);
256 upcall.mru = OVS_CB(skb)->mru;
257 error = ovs_dp_upcall(dp, skb, key, &upcall, 0);
258 if (unlikely(error))
259 kfree_skb(skb);
260 else
261 consume_skb(skb);
262 stats_counter = &stats->n_missed;
263 goto out;
264 }
265
266 ovs_flow_stats_update(flow, key->tp.flags, skb);
267 sf_acts = rcu_dereference(flow->sf_acts);
268 ovs_execute_actions(dp, skb, sf_acts, key);
269
270 stats_counter = &stats->n_hit;
271
272 out:
273 /* Update datapath statistics. */
274 u64_stats_update_begin(&stats->syncp);
275 (*stats_counter)++;
276 stats->n_mask_hit += n_mask_hit;
277 u64_stats_update_end(&stats->syncp);
278 }
279
280 int ovs_dp_upcall(struct datapath *dp, struct sk_buff *skb,
281 const struct sw_flow_key *key,
282 const struct dp_upcall_info *upcall_info,
283 uint32_t cutlen)
284 {
285 struct dp_stats_percpu *stats;
286 int err;
287
288 if (upcall_info->portid == 0) {
289 err = -ENOTCONN;
290 goto err;
291 }
292
293 if (!skb_is_gso(skb))
294 err = queue_userspace_packet(dp, skb, key, upcall_info, cutlen);
295 else
296 err = queue_gso_packets(dp, skb, key, upcall_info, cutlen);
297 if (err)
298 goto err;
299
300 return 0;
301
302 err:
303 stats = this_cpu_ptr(dp->stats_percpu);
304
305 u64_stats_update_begin(&stats->syncp);
306 stats->n_lost++;
307 u64_stats_update_end(&stats->syncp);
308
309 return err;
310 }
311
312 static int queue_gso_packets(struct datapath *dp, struct sk_buff *skb,
313 const struct sw_flow_key *key,
314 const struct dp_upcall_info *upcall_info,
315 uint32_t cutlen)
316 {
317 #ifdef HAVE_SKB_GSO_UDP
318 unsigned int gso_type = skb_shinfo(skb)->gso_type;
319 struct sw_flow_key later_key;
320 #endif
321 struct sk_buff *segs, *nskb;
322 struct ovs_skb_cb ovs_cb;
323 int err;
324
325 ovs_cb = *OVS_CB(skb);
326 segs = __skb_gso_segment(skb, NETIF_F_SG, false);
327 *OVS_CB(skb) = ovs_cb;
328 if (IS_ERR(segs))
329 return PTR_ERR(segs);
330 if (segs == NULL)
331 return -EINVAL;
332 #ifdef HAVE_SKB_GSO_UDP
333 if (gso_type & SKB_GSO_UDP) {
334 /* The initial flow key extracted by ovs_flow_key_extract()
335 * in this case is for a first fragment, so we need to
336 * properly mark later fragments.
337 */
338 later_key = *key;
339 later_key.ip.frag = OVS_FRAG_TYPE_LATER;
340 }
341 #endif
342 /* Queue all of the segments. */
343 skb = segs;
344 do {
345 *OVS_CB(skb) = ovs_cb;
346 #ifdef HAVE_SKB_GSO_UDP
347 if (gso_type & SKB_GSO_UDP && skb != segs)
348 key = &later_key;
349 #endif
350 err = queue_userspace_packet(dp, skb, key, upcall_info, cutlen);
351 if (err)
352 break;
353
354 } while ((skb = skb->next));
355
356 /* Free all of the segments. */
357 skb = segs;
358 do {
359 nskb = skb->next;
360 if (err)
361 kfree_skb(skb);
362 else
363 consume_skb(skb);
364 } while ((skb = nskb));
365 return err;
366 }
367
368 static size_t upcall_msg_size(const struct dp_upcall_info *upcall_info,
369 unsigned int hdrlen, int actions_attrlen)
370 {
371 size_t size = NLMSG_ALIGN(sizeof(struct ovs_header))
372 + nla_total_size(hdrlen) /* OVS_PACKET_ATTR_PACKET */
373 + nla_total_size(ovs_key_attr_size()) /* OVS_PACKET_ATTR_KEY */
374 + nla_total_size(sizeof(unsigned int)); /* OVS_PACKET_ATTR_LEN */
375
376 /* OVS_PACKET_ATTR_USERDATA */
377 if (upcall_info->userdata)
378 size += NLA_ALIGN(upcall_info->userdata->nla_len);
379
380 /* OVS_PACKET_ATTR_EGRESS_TUN_KEY */
381 if (upcall_info->egress_tun_info)
382 size += nla_total_size(ovs_tun_key_attr_size());
383
384 /* OVS_PACKET_ATTR_ACTIONS */
385 if (upcall_info->actions_len)
386 size += nla_total_size(actions_attrlen);
387
388 /* OVS_PACKET_ATTR_MRU */
389 if (upcall_info->mru)
390 size += nla_total_size(sizeof(upcall_info->mru));
391
392 return size;
393 }
394
395 static void pad_packet(struct datapath *dp, struct sk_buff *skb)
396 {
397 if (!(dp->user_features & OVS_DP_F_UNALIGNED)) {
398 size_t plen = NLA_ALIGN(skb->len) - skb->len;
399
400 if (plen > 0)
401 skb_put_zero(skb, plen);
402 }
403 }
404
405 static int queue_userspace_packet(struct datapath *dp, struct sk_buff *skb,
406 const struct sw_flow_key *key,
407 const struct dp_upcall_info *upcall_info,
408 uint32_t cutlen)
409 {
410 struct ovs_header *upcall;
411 struct sk_buff *nskb = NULL;
412 struct sk_buff *user_skb = NULL; /* to be queued to userspace */
413 struct nlattr *nla;
414 size_t len;
415 unsigned int hlen;
416 int err, dp_ifindex;
417
418 dp_ifindex = get_dpifindex(dp);
419 if (!dp_ifindex)
420 return -ENODEV;
421
422 if (skb_vlan_tag_present(skb)) {
423 nskb = skb_clone(skb, GFP_ATOMIC);
424 if (!nskb)
425 return -ENOMEM;
426
427 nskb = __vlan_hwaccel_push_inside(nskb);
428 if (!nskb)
429 return -ENOMEM;
430
431 skb = nskb;
432 }
433
434 if (nla_attr_size(skb->len) > USHRT_MAX) {
435 err = -EFBIG;
436 goto out;
437 }
438
439 /* Complete checksum if needed */
440 if (skb->ip_summed == CHECKSUM_PARTIAL &&
441 (err = skb_csum_hwoffload_help(skb, 0)))
442 goto out;
443
444 /* Older versions of OVS user space enforce alignment of the last
445 * Netlink attribute to NLA_ALIGNTO which would require extensive
446 * padding logic. Only perform zerocopy if padding is not required.
447 */
448 if (dp->user_features & OVS_DP_F_UNALIGNED)
449 hlen = skb_zerocopy_headlen(skb);
450 else
451 hlen = skb->len;
452
453 len = upcall_msg_size(upcall_info, hlen - cutlen,
454 OVS_CB(skb)->acts_origlen);
455 user_skb = genlmsg_new(len, GFP_ATOMIC);
456 if (!user_skb) {
457 err = -ENOMEM;
458 goto out;
459 }
460
461 upcall = genlmsg_put(user_skb, 0, 0, &dp_packet_genl_family,
462 0, upcall_info->cmd);
463 if (!upcall) {
464 err = -EINVAL;
465 goto out;
466 }
467 upcall->dp_ifindex = dp_ifindex;
468
469 err = ovs_nla_put_key(key, key, OVS_PACKET_ATTR_KEY, false, user_skb);
470 BUG_ON(err);
471
472 if (upcall_info->userdata)
473 __nla_put(user_skb, OVS_PACKET_ATTR_USERDATA,
474 nla_len(upcall_info->userdata),
475 nla_data(upcall_info->userdata));
476
477
478 if (upcall_info->egress_tun_info) {
479 nla = nla_nest_start_noflag(user_skb,
480 OVS_PACKET_ATTR_EGRESS_TUN_KEY);
481 if (!nla) {
482 err = -EMSGSIZE;
483 goto out;
484 }
485 err = ovs_nla_put_tunnel_info(user_skb,
486 upcall_info->egress_tun_info);
487 BUG_ON(err);
488 nla_nest_end(user_skb, nla);
489 }
490
491 if (upcall_info->actions_len) {
492 nla = nla_nest_start_noflag(user_skb, OVS_PACKET_ATTR_ACTIONS);
493 if (!nla) {
494 err = -EMSGSIZE;
495 goto out;
496 }
497 err = ovs_nla_put_actions(upcall_info->actions,
498 upcall_info->actions_len,
499 user_skb);
500 if (!err)
501 nla_nest_end(user_skb, nla);
502 else
503 nla_nest_cancel(user_skb, nla);
504 }
505
506 /* Add OVS_PACKET_ATTR_MRU */
507 if (upcall_info->mru) {
508 if (nla_put_u16(user_skb, OVS_PACKET_ATTR_MRU,
509 upcall_info->mru)) {
510 err = -ENOBUFS;
511 goto out;
512 }
513 pad_packet(dp, user_skb);
514 }
515
516 /* Add OVS_PACKET_ATTR_LEN when packet is truncated */
517 if (cutlen > 0) {
518 if (nla_put_u32(user_skb, OVS_PACKET_ATTR_LEN,
519 skb->len)) {
520 err = -ENOBUFS;
521 goto out;
522 }
523 pad_packet(dp, user_skb);
524 }
525
526 /* Only reserve room for attribute header, packet data is added
527 * in skb_zerocopy()
528 */
529 if (!(nla = nla_reserve(user_skb, OVS_PACKET_ATTR_PACKET, 0))) {
530 err = -ENOBUFS;
531 goto out;
532 }
533 nla->nla_len = nla_attr_size(skb->len - cutlen);
534
535 err = skb_zerocopy(user_skb, skb, skb->len - cutlen, hlen);
536 if (err)
537 goto out;
538
539 /* Pad OVS_PACKET_ATTR_PACKET if linear copy was performed */
540 pad_packet(dp, user_skb);
541
542 ((struct nlmsghdr *) user_skb->data)->nlmsg_len = user_skb->len;
543
544 err = genlmsg_unicast(ovs_dp_get_net(dp), user_skb, upcall_info->portid);
545 user_skb = NULL;
546 out:
547 if (err)
548 skb_tx_error(skb);
549 kfree_skb(user_skb);
550 kfree_skb(nskb);
551 return err;
552 }
553
554 static int ovs_packet_cmd_execute(struct sk_buff *skb, struct genl_info *info)
555 {
556 struct ovs_header *ovs_header = info->userhdr;
557 struct net *net = sock_net(skb->sk);
558 struct nlattr **a = info->attrs;
559 struct sw_flow_actions *acts;
560 struct sk_buff *packet;
561 struct sw_flow *flow;
562 struct sw_flow_actions *sf_acts;
563 struct datapath *dp;
564 struct vport *input_vport;
565 u16 mru = 0;
566 int len;
567 int err;
568 bool log = !a[OVS_PACKET_ATTR_PROBE];
569
570 err = -EINVAL;
571 if (!a[OVS_PACKET_ATTR_PACKET] || !a[OVS_PACKET_ATTR_KEY] ||
572 !a[OVS_PACKET_ATTR_ACTIONS])
573 goto err;
574
575 len = nla_len(a[OVS_PACKET_ATTR_PACKET]);
576 packet = __dev_alloc_skb(NET_IP_ALIGN + len, GFP_KERNEL);
577 err = -ENOMEM;
578 if (!packet)
579 goto err;
580 skb_reserve(packet, NET_IP_ALIGN);
581
582 nla_memcpy(__skb_put(packet, len), a[OVS_PACKET_ATTR_PACKET], len);
583
584 /* Set packet's mru */
585 if (a[OVS_PACKET_ATTR_MRU]) {
586 mru = nla_get_u16(a[OVS_PACKET_ATTR_MRU]);
587 packet->ignore_df = 1;
588 }
589 OVS_CB(packet)->mru = mru;
590
591 /* Build an sw_flow for sending this packet. */
592 flow = ovs_flow_alloc();
593 err = PTR_ERR(flow);
594 if (IS_ERR(flow))
595 goto err_kfree_skb;
596
597 err = ovs_flow_key_extract_userspace(net, a[OVS_PACKET_ATTR_KEY],
598 packet, &flow->key, log);
599 if (err)
600 goto err_flow_free;
601
602 err = ovs_nla_copy_actions(net, a[OVS_PACKET_ATTR_ACTIONS],
603 &flow->key, &acts, log);
604 if (err)
605 goto err_flow_free;
606
607 rcu_assign_pointer(flow->sf_acts, acts);
608 packet->priority = flow->key.phy.priority;
609 packet->mark = flow->key.phy.skb_mark;
610
611 rcu_read_lock();
612 dp = get_dp_rcu(net, ovs_header->dp_ifindex);
613 err = -ENODEV;
614 if (!dp)
615 goto err_unlock;
616
617 input_vport = ovs_vport_rcu(dp, flow->key.phy.in_port);
618 if (!input_vport)
619 input_vport = ovs_vport_rcu(dp, OVSP_LOCAL);
620
621 if (!input_vport)
622 goto err_unlock;
623
624 packet->dev = input_vport->dev;
625 OVS_CB(packet)->input_vport = input_vport;
626 sf_acts = rcu_dereference(flow->sf_acts);
627
628 local_bh_disable();
629 err = ovs_execute_actions(dp, packet, sf_acts, &flow->key);
630 local_bh_enable();
631 rcu_read_unlock();
632
633 ovs_flow_free(flow, false);
634 return err;
635
636 err_unlock:
637 rcu_read_unlock();
638 err_flow_free:
639 ovs_flow_free(flow, false);
640 err_kfree_skb:
641 kfree_skb(packet);
642 err:
643 return err;
644 }
645
646 static const struct nla_policy packet_policy[OVS_PACKET_ATTR_MAX + 1] = {
647 [OVS_PACKET_ATTR_PACKET] = { .len = ETH_HLEN },
648 [OVS_PACKET_ATTR_KEY] = { .type = NLA_NESTED },
649 [OVS_PACKET_ATTR_ACTIONS] = { .type = NLA_NESTED },
650 [OVS_PACKET_ATTR_PROBE] = { .type = NLA_FLAG },
651 [OVS_PACKET_ATTR_MRU] = { .type = NLA_U16 },
652 };
653
654 static struct genl_ops dp_packet_genl_ops[] = {
655 { .cmd = OVS_PACKET_CMD_EXECUTE,
656 #ifdef HAVE_GENL_VALIDATE_FLAGS
657 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
658 #endif
659 .flags = GENL_UNS_ADMIN_PERM, /* Requires CAP_NET_ADMIN privilege. */
660 .policy = packet_policy,
661 .doit = ovs_packet_cmd_execute
662 }
663 };
664
665 static struct genl_family dp_packet_genl_family __ro_after_init = {
666 .hdrsize = sizeof(struct ovs_header),
667 .name = OVS_PACKET_FAMILY,
668 .version = OVS_PACKET_VERSION,
669 .maxattr = OVS_PACKET_ATTR_MAX,
670 .netnsok = true,
671 .parallel_ops = true,
672 .ops = dp_packet_genl_ops,
673 .n_ops = ARRAY_SIZE(dp_packet_genl_ops),
674 .module = THIS_MODULE,
675 };
676
677 static void get_dp_stats(const struct datapath *dp, struct ovs_dp_stats *stats,
678 struct ovs_dp_megaflow_stats *mega_stats)
679 {
680 int i;
681
682 memset(mega_stats, 0, sizeof(*mega_stats));
683
684 stats->n_flows = ovs_flow_tbl_count(&dp->table);
685 mega_stats->n_masks = ovs_flow_tbl_num_masks(&dp->table);
686
687 stats->n_hit = stats->n_missed = stats->n_lost = 0;
688
689 for_each_possible_cpu(i) {
690 const struct dp_stats_percpu *percpu_stats;
691 struct dp_stats_percpu local_stats;
692 unsigned int start;
693
694 percpu_stats = per_cpu_ptr(dp->stats_percpu, i);
695
696 do {
697 start = u64_stats_fetch_begin_irq(&percpu_stats->syncp);
698 local_stats = *percpu_stats;
699 } while (u64_stats_fetch_retry_irq(&percpu_stats->syncp, start));
700
701 stats->n_hit += local_stats.n_hit;
702 stats->n_missed += local_stats.n_missed;
703 stats->n_lost += local_stats.n_lost;
704 mega_stats->n_mask_hit += local_stats.n_mask_hit;
705 }
706 }
707
708 static bool should_fill_key(const struct sw_flow_id *sfid, uint32_t ufid_flags)
709 {
710 return ovs_identifier_is_ufid(sfid) &&
711 !(ufid_flags & OVS_UFID_F_OMIT_KEY);
712 }
713
714 static bool should_fill_mask(uint32_t ufid_flags)
715 {
716 return !(ufid_flags & OVS_UFID_F_OMIT_MASK);
717 }
718
719 static bool should_fill_actions(uint32_t ufid_flags)
720 {
721 return !(ufid_flags & OVS_UFID_F_OMIT_ACTIONS);
722 }
723
724 static size_t ovs_flow_cmd_msg_size(const struct sw_flow_actions *acts,
725 const struct sw_flow_id *sfid,
726 uint32_t ufid_flags)
727 {
728 size_t len = NLMSG_ALIGN(sizeof(struct ovs_header));
729
730 /* OVS_FLOW_ATTR_UFID */
731 if (sfid && ovs_identifier_is_ufid(sfid))
732 len += nla_total_size(sfid->ufid_len);
733
734 /* OVS_FLOW_ATTR_KEY */
735 if (!sfid || should_fill_key(sfid, ufid_flags))
736 len += nla_total_size(ovs_key_attr_size());
737
738 /* OVS_FLOW_ATTR_MASK */
739 if (should_fill_mask(ufid_flags))
740 len += nla_total_size(ovs_key_attr_size());
741
742 /* OVS_FLOW_ATTR_ACTIONS */
743 if (should_fill_actions(ufid_flags))
744 len += nla_total_size(acts->orig_len);
745
746 return len
747 + nla_total_size_64bit(sizeof(struct ovs_flow_stats)) /* OVS_FLOW_ATTR_STATS */
748 + nla_total_size(1) /* OVS_FLOW_ATTR_TCP_FLAGS */
749 + nla_total_size_64bit(8); /* OVS_FLOW_ATTR_USED */
750 }
751
752 /* Called with ovs_mutex or RCU read lock. */
753 static int ovs_flow_cmd_fill_stats(const struct sw_flow *flow,
754 struct sk_buff *skb)
755 {
756 struct ovs_flow_stats stats;
757 __be16 tcp_flags;
758 unsigned long used;
759
760 ovs_flow_stats_get(flow, &stats, &used, &tcp_flags);
761
762 if (used &&
763 nla_put_u64_64bit(skb, OVS_FLOW_ATTR_USED, ovs_flow_used_time(used),
764 OVS_FLOW_ATTR_PAD))
765 return -EMSGSIZE;
766
767 if (stats.n_packets &&
768 nla_put_64bit(skb, OVS_FLOW_ATTR_STATS,
769 sizeof(struct ovs_flow_stats), &stats,
770 OVS_FLOW_ATTR_PAD))
771 return -EMSGSIZE;
772
773 if ((u8)ntohs(tcp_flags) &&
774 nla_put_u8(skb, OVS_FLOW_ATTR_TCP_FLAGS, (u8)ntohs(tcp_flags)))
775 return -EMSGSIZE;
776
777 return 0;
778 }
779
780 /* Called with ovs_mutex or RCU read lock. */
781 static int ovs_flow_cmd_fill_actions(const struct sw_flow *flow,
782 struct sk_buff *skb, int skb_orig_len)
783 {
784 struct nlattr *start;
785 int err;
786
787 /* If OVS_FLOW_ATTR_ACTIONS doesn't fit, skip dumping the actions if
788 * this is the first flow to be dumped into 'skb'. This is unusual for
789 * Netlink but individual action lists can be longer than
790 * NLMSG_GOODSIZE and thus entirely undumpable if we didn't do this.
791 * The userspace caller can always fetch the actions separately if it
792 * really wants them. (Most userspace callers in fact don't care.)
793 *
794 * This can only fail for dump operations because the skb is always
795 * properly sized for single flows.
796 */
797 start = nla_nest_start_noflag(skb, OVS_FLOW_ATTR_ACTIONS);
798 if (start) {
799 const struct sw_flow_actions *sf_acts;
800
801 sf_acts = rcu_dereference_ovsl(flow->sf_acts);
802 err = ovs_nla_put_actions(sf_acts->actions,
803 sf_acts->actions_len, skb);
804
805 if (!err)
806 nla_nest_end(skb, start);
807 else {
808 if (skb_orig_len)
809 return err;
810
811 nla_nest_cancel(skb, start);
812 }
813 } else if (skb_orig_len) {
814 return -EMSGSIZE;
815 }
816
817 return 0;
818 }
819
820 /* Called with ovs_mutex or RCU read lock. */
821 static int ovs_flow_cmd_fill_info(const struct sw_flow *flow, int dp_ifindex,
822 struct sk_buff *skb, u32 portid,
823 u32 seq, u32 flags, u8 cmd, u32 ufid_flags)
824 {
825 const int skb_orig_len = skb->len;
826 struct ovs_header *ovs_header;
827 int err;
828
829 ovs_header = genlmsg_put(skb, portid, seq, &dp_flow_genl_family,
830 flags, cmd);
831 if (!ovs_header)
832 return -EMSGSIZE;
833
834 ovs_header->dp_ifindex = dp_ifindex;
835
836 err = ovs_nla_put_identifier(flow, skb);
837 if (err)
838 goto error;
839
840 if (should_fill_key(&flow->id, ufid_flags)) {
841 err = ovs_nla_put_masked_key(flow, skb);
842 if (err)
843 goto error;
844 }
845
846 if (should_fill_mask(ufid_flags)) {
847 err = ovs_nla_put_mask(flow, skb);
848 if (err)
849 goto error;
850 }
851
852 err = ovs_flow_cmd_fill_stats(flow, skb);
853 if (err)
854 goto error;
855
856 if (should_fill_actions(ufid_flags)) {
857 err = ovs_flow_cmd_fill_actions(flow, skb, skb_orig_len);
858 if (err)
859 goto error;
860 }
861
862 genlmsg_end(skb, ovs_header);
863 return 0;
864
865 error:
866 genlmsg_cancel(skb, ovs_header);
867 return err;
868 }
869
870 /* May not be called with RCU read lock. */
871 static struct sk_buff *ovs_flow_cmd_alloc_info(const struct sw_flow_actions *acts,
872 const struct sw_flow_id *sfid,
873 struct genl_info *info,
874 bool always,
875 uint32_t ufid_flags)
876 {
877 struct sk_buff *skb;
878 size_t len;
879
880 if (!always && !ovs_must_notify(&dp_flow_genl_family, info,
881 GROUP_ID(&ovs_dp_flow_multicast_group)))
882 return NULL;
883
884 len = ovs_flow_cmd_msg_size(acts, sfid, ufid_flags);
885 skb = genlmsg_new(len, GFP_KERNEL);
886 if (!skb)
887 return ERR_PTR(-ENOMEM);
888
889 return skb;
890 }
891
892 /* Called with ovs_mutex. */
893 static struct sk_buff *ovs_flow_cmd_build_info(const struct sw_flow *flow,
894 int dp_ifindex,
895 struct genl_info *info, u8 cmd,
896 bool always, u32 ufid_flags)
897 {
898 struct sk_buff *skb;
899 int retval;
900
901 skb = ovs_flow_cmd_alloc_info(ovsl_dereference(flow->sf_acts),
902 &flow->id, info, always, ufid_flags);
903 if (IS_ERR_OR_NULL(skb))
904 return skb;
905
906 retval = ovs_flow_cmd_fill_info(flow, dp_ifindex, skb,
907 info->snd_portid, info->snd_seq, 0,
908 cmd, ufid_flags);
909 BUG_ON(retval < 0);
910 return skb;
911 }
912
913 static int ovs_flow_cmd_new(struct sk_buff *skb, struct genl_info *info)
914 {
915 struct net *net = sock_net(skb->sk);
916 struct nlattr **a = info->attrs;
917 struct ovs_header *ovs_header = info->userhdr;
918 struct sw_flow *flow = NULL, *new_flow;
919 struct sw_flow_mask mask;
920 struct sk_buff *reply;
921 struct datapath *dp;
922 struct sw_flow_actions *acts;
923 struct sw_flow_match match;
924 u32 ufid_flags = ovs_nla_get_ufid_flags(a[OVS_FLOW_ATTR_UFID_FLAGS]);
925 int error;
926 bool log = !a[OVS_FLOW_ATTR_PROBE];
927
928 /* Must have key and actions. */
929 error = -EINVAL;
930 if (!a[OVS_FLOW_ATTR_KEY]) {
931 OVS_NLERR(log, "Flow key attr not present in new flow.");
932 goto error;
933 }
934 if (!a[OVS_FLOW_ATTR_ACTIONS]) {
935 OVS_NLERR(log, "Flow actions attr not present in new flow.");
936 goto error;
937 }
938
939 /* Most of the time we need to allocate a new flow, do it before
940 * locking.
941 */
942 new_flow = ovs_flow_alloc();
943 if (IS_ERR(new_flow)) {
944 error = PTR_ERR(new_flow);
945 goto error;
946 }
947
948 /* Extract key. */
949 ovs_match_init(&match, &new_flow->key, false, &mask);
950 error = ovs_nla_get_match(net, &match, a[OVS_FLOW_ATTR_KEY],
951 a[OVS_FLOW_ATTR_MASK], log);
952 if (error)
953 goto err_kfree_flow;
954
955 /* Extract flow identifier. */
956 error = ovs_nla_get_identifier(&new_flow->id, a[OVS_FLOW_ATTR_UFID],
957 &new_flow->key, log);
958 if (error)
959 goto err_kfree_flow;
960
961 /* unmasked key is needed to match when ufid is not used. */
962 if (ovs_identifier_is_key(&new_flow->id))
963 match.key = new_flow->id.unmasked_key;
964
965 ovs_flow_mask_key(&new_flow->key, &new_flow->key, true, &mask);
966
967 /* Validate actions. */
968 error = ovs_nla_copy_actions(net, a[OVS_FLOW_ATTR_ACTIONS],
969 &new_flow->key, &acts, log);
970 if (error) {
971 OVS_NLERR(log, "Flow actions may not be safe on all matching packets.");
972 goto err_kfree_flow;
973 }
974
975 reply = ovs_flow_cmd_alloc_info(acts, &new_flow->id, info, false,
976 ufid_flags);
977 if (IS_ERR(reply)) {
978 error = PTR_ERR(reply);
979 goto err_kfree_acts;
980 }
981
982 ovs_lock();
983 dp = get_dp(net, ovs_header->dp_ifindex);
984 if (unlikely(!dp)) {
985 error = -ENODEV;
986 goto err_unlock_ovs;
987 }
988
989 /* Check if this is a duplicate flow */
990 if (ovs_identifier_is_ufid(&new_flow->id))
991 flow = ovs_flow_tbl_lookup_ufid(&dp->table, &new_flow->id);
992 if (!flow)
993 flow = ovs_flow_tbl_lookup(&dp->table, &new_flow->key);
994 if (likely(!flow)) {
995 rcu_assign_pointer(new_flow->sf_acts, acts);
996
997 /* Put flow in bucket. */
998 error = ovs_flow_tbl_insert(&dp->table, new_flow, &mask);
999 if (unlikely(error)) {
1000 acts = NULL;
1001 goto err_unlock_ovs;
1002 }
1003
1004 if (unlikely(reply)) {
1005 error = ovs_flow_cmd_fill_info(new_flow,
1006 ovs_header->dp_ifindex,
1007 reply, info->snd_portid,
1008 info->snd_seq, 0,
1009 OVS_FLOW_CMD_NEW,
1010 ufid_flags);
1011 BUG_ON(error < 0);
1012 }
1013 ovs_unlock();
1014 } else {
1015 struct sw_flow_actions *old_acts;
1016
1017 /* Bail out if we're not allowed to modify an existing flow.
1018 * We accept NLM_F_CREATE in place of the intended NLM_F_EXCL
1019 * because Generic Netlink treats the latter as a dump
1020 * request. We also accept NLM_F_EXCL in case that bug ever
1021 * gets fixed.
1022 */
1023 if (unlikely(info->nlhdr->nlmsg_flags & (NLM_F_CREATE
1024 | NLM_F_EXCL))) {
1025 error = -EEXIST;
1026 goto err_unlock_ovs;
1027 }
1028 /* The flow identifier has to be the same for flow updates.
1029 * Look for any overlapping flow.
1030 */
1031 if (unlikely(!ovs_flow_cmp(flow, &match))) {
1032 if (ovs_identifier_is_key(&flow->id))
1033 flow = ovs_flow_tbl_lookup_exact(&dp->table,
1034 &match);
1035 else /* UFID matches but key is different */
1036 flow = NULL;
1037 if (!flow) {
1038 error = -ENOENT;
1039 goto err_unlock_ovs;
1040 }
1041 }
1042 /* Update actions. */
1043 old_acts = ovsl_dereference(flow->sf_acts);
1044 rcu_assign_pointer(flow->sf_acts, acts);
1045
1046 if (unlikely(reply)) {
1047 error = ovs_flow_cmd_fill_info(flow,
1048 ovs_header->dp_ifindex,
1049 reply, info->snd_portid,
1050 info->snd_seq, 0,
1051 OVS_FLOW_CMD_NEW,
1052 ufid_flags);
1053 BUG_ON(error < 0);
1054 }
1055 ovs_unlock();
1056
1057 ovs_nla_free_flow_actions_rcu(old_acts);
1058 ovs_flow_free(new_flow, false);
1059 }
1060
1061 if (reply)
1062 ovs_notify(&dp_flow_genl_family, &ovs_dp_flow_multicast_group, reply, info);
1063 return 0;
1064
1065 err_unlock_ovs:
1066 ovs_unlock();
1067 kfree_skb(reply);
1068 err_kfree_acts:
1069 ovs_nla_free_flow_actions(acts);
1070 err_kfree_flow:
1071 ovs_flow_free(new_flow, false);
1072 error:
1073 return error;
1074 }
1075
1076 /* Factor out action copy to avoid "Wframe-larger-than=1024" warning. */
1077 static noinline_for_stack struct sw_flow_actions *get_flow_actions(struct net *net,
1078 const struct nlattr *a,
1079 const struct sw_flow_key *key,
1080 const struct sw_flow_mask *mask,
1081 bool log)
1082 {
1083 struct sw_flow_actions *acts;
1084 struct sw_flow_key masked_key;
1085 int error;
1086
1087 ovs_flow_mask_key(&masked_key, key, true, mask);
1088 error = ovs_nla_copy_actions(net, a, &masked_key, &acts, log);
1089 if (error) {
1090 OVS_NLERR(log,
1091 "Actions may not be safe on all matching packets");
1092 return ERR_PTR(error);
1093 }
1094
1095 return acts;
1096 }
1097
1098 /* Factor out match-init and action-copy to avoid
1099 * "Wframe-larger-than=1024" warning. Because mask is only
1100 * used to get actions, we new a function to save some
1101 * stack space.
1102 *
1103 * If there are not key and action attrs, we return 0
1104 * directly. In the case, the caller will also not use the
1105 * match as before. If there is action attr, we try to get
1106 * actions and save them to *acts. Before returning from
1107 * the function, we reset the match->mask pointer. Because
1108 * we should not to return match object with dangling reference
1109 * to mask.
1110 * */
1111 static noinline_for_stack int
1112 ovs_nla_init_match_and_action(struct net *net,
1113 struct sw_flow_match *match,
1114 struct sw_flow_key *key,
1115 struct nlattr **a,
1116 struct sw_flow_actions **acts,
1117 bool log)
1118 {
1119 struct sw_flow_mask mask;
1120 int error = 0;
1121
1122 if (a[OVS_FLOW_ATTR_KEY]) {
1123 ovs_match_init(match, key, true, &mask);
1124 error = ovs_nla_get_match(net, match, a[OVS_FLOW_ATTR_KEY],
1125 a[OVS_FLOW_ATTR_MASK], log);
1126 if (error)
1127 goto error;
1128 }
1129
1130 if (a[OVS_FLOW_ATTR_ACTIONS]) {
1131 if (!a[OVS_FLOW_ATTR_KEY]) {
1132 OVS_NLERR(log,
1133 "Flow key attribute not present in set flow.");
1134 error = -EINVAL;
1135 goto error;
1136 }
1137
1138 *acts = get_flow_actions(net, a[OVS_FLOW_ATTR_ACTIONS], key,
1139 &mask, log);
1140 if (IS_ERR(*acts)) {
1141 error = PTR_ERR(*acts);
1142 goto error;
1143 }
1144 }
1145
1146 /* On success, error is 0. */
1147 error:
1148 match->mask = NULL;
1149 return error;
1150 }
1151
1152 static int ovs_flow_cmd_set(struct sk_buff *skb, struct genl_info *info)
1153 {
1154 struct net *net = sock_net(skb->sk);
1155 struct nlattr **a = info->attrs;
1156 struct ovs_header *ovs_header = info->userhdr;
1157 struct sw_flow_key key;
1158 struct sw_flow *flow;
1159 struct sk_buff *reply = NULL;
1160 struct datapath *dp;
1161 struct sw_flow_actions *old_acts = NULL, *acts = NULL;
1162 struct sw_flow_match match;
1163 struct sw_flow_id sfid;
1164 u32 ufid_flags = ovs_nla_get_ufid_flags(a[OVS_FLOW_ATTR_UFID_FLAGS]);
1165 int error = 0;
1166 bool log = !a[OVS_FLOW_ATTR_PROBE];
1167 bool ufid_present;
1168
1169 ufid_present = ovs_nla_get_ufid(&sfid, a[OVS_FLOW_ATTR_UFID], log);
1170 if (!a[OVS_FLOW_ATTR_KEY] && !ufid_present) {
1171 OVS_NLERR(log,
1172 "Flow set message rejected, Key attribute missing.");
1173 return -EINVAL;
1174 }
1175
1176 error = ovs_nla_init_match_and_action(net, &match, &key, a,
1177 &acts, log);
1178 if (error)
1179 goto error;
1180
1181 if (acts) {
1182 /* Can allocate before locking if have acts. */
1183 reply = ovs_flow_cmd_alloc_info(acts, &sfid, info, false,
1184 ufid_flags);
1185 if (IS_ERR(reply)) {
1186 error = PTR_ERR(reply);
1187 goto err_kfree_acts;
1188 }
1189 }
1190
1191 ovs_lock();
1192 dp = get_dp(net, ovs_header->dp_ifindex);
1193 if (unlikely(!dp)) {
1194 error = -ENODEV;
1195 goto err_unlock_ovs;
1196 }
1197 /* Check that the flow exists. */
1198 if (ufid_present)
1199 flow = ovs_flow_tbl_lookup_ufid(&dp->table, &sfid);
1200 else
1201 flow = ovs_flow_tbl_lookup_exact(&dp->table, &match);
1202 if (unlikely(!flow)) {
1203 error = -ENOENT;
1204 goto err_unlock_ovs;
1205 }
1206
1207 /* Update actions, if present. */
1208 if (likely(acts)) {
1209 old_acts = ovsl_dereference(flow->sf_acts);
1210 rcu_assign_pointer(flow->sf_acts, acts);
1211
1212 if (unlikely(reply)) {
1213 error = ovs_flow_cmd_fill_info(flow,
1214 ovs_header->dp_ifindex,
1215 reply, info->snd_portid,
1216 info->snd_seq, 0,
1217 OVS_FLOW_CMD_SET,
1218 ufid_flags);
1219 BUG_ON(error < 0);
1220 }
1221 } else {
1222 /* Could not alloc without acts before locking. */
1223 reply = ovs_flow_cmd_build_info(flow, ovs_header->dp_ifindex,
1224 info, OVS_FLOW_CMD_SET, false,
1225 ufid_flags);
1226
1227 if (unlikely(IS_ERR(reply))) {
1228 error = PTR_ERR(reply);
1229 goto err_unlock_ovs;
1230 }
1231 }
1232
1233 /* Clear stats. */
1234 if (a[OVS_FLOW_ATTR_CLEAR])
1235 ovs_flow_stats_clear(flow);
1236 ovs_unlock();
1237
1238 if (reply)
1239 ovs_notify(&dp_flow_genl_family, &ovs_dp_flow_multicast_group, reply, info);
1240 if (old_acts)
1241 ovs_nla_free_flow_actions_rcu(old_acts);
1242
1243 return 0;
1244
1245 err_unlock_ovs:
1246 ovs_unlock();
1247 kfree_skb(reply);
1248 err_kfree_acts:
1249 ovs_nla_free_flow_actions(acts);
1250 error:
1251 return error;
1252 }
1253
1254 static int ovs_flow_cmd_get(struct sk_buff *skb, struct genl_info *info)
1255 {
1256 struct nlattr **a = info->attrs;
1257 struct ovs_header *ovs_header = info->userhdr;
1258 struct net *net = sock_net(skb->sk);
1259 struct sw_flow_key key;
1260 struct sk_buff *reply;
1261 struct sw_flow *flow;
1262 struct datapath *dp;
1263 struct sw_flow_match match;
1264 struct sw_flow_id ufid;
1265 u32 ufid_flags = ovs_nla_get_ufid_flags(a[OVS_FLOW_ATTR_UFID_FLAGS]);
1266 int err = 0;
1267 bool log = !a[OVS_FLOW_ATTR_PROBE];
1268 bool ufid_present;
1269
1270 ufid_present = ovs_nla_get_ufid(&ufid, a[OVS_FLOW_ATTR_UFID], log);
1271 if (a[OVS_FLOW_ATTR_KEY]) {
1272 ovs_match_init(&match, &key, true, NULL);
1273 err = ovs_nla_get_match(net, &match, a[OVS_FLOW_ATTR_KEY], NULL,
1274 log);
1275 } else if (!ufid_present) {
1276 OVS_NLERR(log,
1277 "Flow get message rejected, Key attribute missing.");
1278 err = -EINVAL;
1279 }
1280 if (err)
1281 return err;
1282
1283 ovs_lock();
1284 dp = get_dp(sock_net(skb->sk), ovs_header->dp_ifindex);
1285 if (!dp) {
1286 err = -ENODEV;
1287 goto unlock;
1288 }
1289
1290 if (ufid_present)
1291 flow = ovs_flow_tbl_lookup_ufid(&dp->table, &ufid);
1292 else
1293 flow = ovs_flow_tbl_lookup_exact(&dp->table, &match);
1294 if (!flow) {
1295 err = -ENOENT;
1296 goto unlock;
1297 }
1298
1299 reply = ovs_flow_cmd_build_info(flow, ovs_header->dp_ifindex, info,
1300 OVS_FLOW_CMD_GET, true, ufid_flags);
1301 if (IS_ERR(reply)) {
1302 err = PTR_ERR(reply);
1303 goto unlock;
1304 }
1305
1306 ovs_unlock();
1307 return genlmsg_reply(reply, info);
1308 unlock:
1309 ovs_unlock();
1310 return err;
1311 }
1312
1313 static int ovs_flow_cmd_del(struct sk_buff *skb, struct genl_info *info)
1314 {
1315 struct nlattr **a = info->attrs;
1316 struct ovs_header *ovs_header = info->userhdr;
1317 struct net *net = sock_net(skb->sk);
1318 struct sw_flow_key key;
1319 struct sk_buff *reply;
1320 struct sw_flow *flow = NULL;
1321 struct datapath *dp;
1322 struct sw_flow_match match;
1323 struct sw_flow_id ufid;
1324 u32 ufid_flags = ovs_nla_get_ufid_flags(a[OVS_FLOW_ATTR_UFID_FLAGS]);
1325 int err;
1326 bool log = !a[OVS_FLOW_ATTR_PROBE];
1327 bool ufid_present;
1328
1329 ufid_present = ovs_nla_get_ufid(&ufid, a[OVS_FLOW_ATTR_UFID], log);
1330 if (a[OVS_FLOW_ATTR_KEY]) {
1331 ovs_match_init(&match, &key, true, NULL);
1332 err = ovs_nla_get_match(net, &match, a[OVS_FLOW_ATTR_KEY],
1333 NULL, log);
1334 if (unlikely(err))
1335 return err;
1336 }
1337
1338 ovs_lock();
1339 dp = get_dp(sock_net(skb->sk), ovs_header->dp_ifindex);
1340 if (unlikely(!dp)) {
1341 err = -ENODEV;
1342 goto unlock;
1343 }
1344
1345 if (unlikely(!a[OVS_FLOW_ATTR_KEY] && !ufid_present)) {
1346 err = ovs_flow_tbl_flush(&dp->table);
1347 goto unlock;
1348 }
1349
1350 if (ufid_present)
1351 flow = ovs_flow_tbl_lookup_ufid(&dp->table, &ufid);
1352 else
1353 flow = ovs_flow_tbl_lookup_exact(&dp->table, &match);
1354 if (unlikely(!flow)) {
1355 err = -ENOENT;
1356 goto unlock;
1357 }
1358
1359 ovs_flow_tbl_remove(&dp->table, flow);
1360 ovs_unlock();
1361
1362 reply = ovs_flow_cmd_alloc_info(rcu_dereference_raw(flow->sf_acts),
1363 &flow->id, info, false, ufid_flags);
1364
1365 if (likely(reply)) {
1366 if (likely(!IS_ERR(reply))) {
1367 rcu_read_lock(); /*To keep RCU checker happy. */
1368 err = ovs_flow_cmd_fill_info(flow, ovs_header->dp_ifindex,
1369 reply, info->snd_portid,
1370 info->snd_seq, 0,
1371 OVS_FLOW_CMD_DEL,
1372 ufid_flags);
1373 rcu_read_unlock();
1374 BUG_ON(err < 0);
1375 ovs_notify(&dp_flow_genl_family, &ovs_dp_flow_multicast_group, reply, info);
1376 } else {
1377 genl_set_err(&dp_flow_genl_family, sock_net(skb->sk), 0,
1378 GROUP_ID(&ovs_dp_flow_multicast_group), PTR_ERR(reply));
1379
1380 }
1381 }
1382
1383 ovs_flow_free(flow, true);
1384 return 0;
1385 unlock:
1386 ovs_unlock();
1387 return err;
1388 }
1389
1390 static int ovs_flow_cmd_dump(struct sk_buff *skb, struct netlink_callback *cb)
1391 {
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;
1396 u32 ufid_flags;
1397 int err;
1398
1399 err = genlmsg_parse(cb->nlh, &dp_flow_genl_family, a,
1400 OVS_FLOW_ATTR_MAX, flow_policy, NULL);
1401 if (err)
1402 return err;
1403 ufid_flags = ovs_nla_get_ufid_flags(a[OVS_FLOW_ATTR_UFID_FLAGS]);
1404
1405 rcu_read_lock();
1406 dp = get_dp_rcu(sock_net(skb->sk), ovs_header->dp_ifindex);
1407 if (!dp) {
1408 rcu_read_unlock();
1409 return -ENODEV;
1410 }
1411
1412 ti = rcu_dereference(dp->table.ti);
1413 for (;;) {
1414 struct sw_flow *flow;
1415 u32 bucket, obj;
1416
1417 bucket = cb->args[0];
1418 obj = cb->args[1];
1419 flow = ovs_flow_tbl_dump_next(ti, &bucket, &obj);
1420 if (!flow)
1421 break;
1422
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)
1427 break;
1428
1429 cb->args[0] = bucket;
1430 cb->args[1] = obj;
1431 }
1432 rcu_read_unlock();
1433 return skb->len;
1434 }
1435
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 },
1444 };
1445
1446 static const struct genl_ops dp_flow_genl_ops[] = {
1447 { .cmd = OVS_FLOW_CMD_NEW,
1448 #ifdef HAVE_GENL_VALIDATE_FLAGS
1449 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
1450 #endif
1451 .flags = GENL_UNS_ADMIN_PERM, /* Requires CAP_NET_ADMIN privilege. */
1452 .policy = flow_policy,
1453 .doit = ovs_flow_cmd_new
1454 },
1455 { .cmd = OVS_FLOW_CMD_DEL,
1456 #ifdef HAVE_GENL_VALIDATE_FLAGS
1457 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
1458 #endif
1459 .flags = GENL_UNS_ADMIN_PERM, /* Requires CAP_NET_ADMIN privilege. */
1460 .policy = flow_policy,
1461 .doit = ovs_flow_cmd_del
1462 },
1463 { .cmd = OVS_FLOW_CMD_GET,
1464 #ifdef HAVE_GENL_VALIDATE_FLAGS
1465 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
1466 #endif
1467 .flags = 0, /* OK for unprivileged users. */
1468 .policy = flow_policy,
1469 .doit = ovs_flow_cmd_get,
1470 .dumpit = ovs_flow_cmd_dump
1471 },
1472 { .cmd = OVS_FLOW_CMD_SET,
1473 #ifdef HAVE_GENL_VALIDATE_FLAGS
1474 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
1475 #endif
1476 .flags = GENL_UNS_ADMIN_PERM, /* Requires CAP_NET_ADMIN privilege. */
1477 .policy = flow_policy,
1478 .doit = ovs_flow_cmd_set,
1479 },
1480 };
1481
1482 static struct genl_family dp_flow_genl_family __ro_after_init = {
1483 .hdrsize = sizeof(struct ovs_header),
1484 .name = OVS_FLOW_FAMILY,
1485 .version = OVS_FLOW_VERSION,
1486 .maxattr = OVS_FLOW_ATTR_MAX,
1487 .netnsok = true,
1488 .parallel_ops = true,
1489 .ops = dp_flow_genl_ops,
1490 .n_ops = ARRAY_SIZE(dp_flow_genl_ops),
1491 .mcgrps = &ovs_dp_flow_multicast_group,
1492 .n_mcgrps = 1,
1493 .module = THIS_MODULE,
1494 };
1495
1496 static size_t ovs_dp_cmd_msg_size(void)
1497 {
1498 size_t msgsize = NLMSG_ALIGN(sizeof(struct ovs_header));
1499
1500 msgsize += nla_total_size(IFNAMSIZ);
1501 msgsize += nla_total_size_64bit(sizeof(struct ovs_dp_stats));
1502 msgsize += nla_total_size_64bit(sizeof(struct ovs_dp_megaflow_stats));
1503 msgsize += nla_total_size(sizeof(u32)); /* OVS_DP_ATTR_USER_FEATURES */
1504
1505 return msgsize;
1506 }
1507
1508 /* Called with ovs_mutex. */
1509 static int ovs_dp_cmd_fill_info(struct datapath *dp, struct sk_buff *skb,
1510 u32 portid, u32 seq, u32 flags, u8 cmd)
1511 {
1512 struct ovs_header *ovs_header;
1513 struct ovs_dp_stats dp_stats;
1514 struct ovs_dp_megaflow_stats dp_megaflow_stats;
1515 int err;
1516
1517 ovs_header = genlmsg_put(skb, portid, seq, &dp_datapath_genl_family,
1518 flags, cmd);
1519 if (!ovs_header)
1520 goto error;
1521
1522 ovs_header->dp_ifindex = get_dpifindex(dp);
1523
1524 err = nla_put_string(skb, OVS_DP_ATTR_NAME, ovs_dp_name(dp));
1525 if (err)
1526 goto nla_put_failure;
1527
1528 get_dp_stats(dp, &dp_stats, &dp_megaflow_stats);
1529 if (nla_put_64bit(skb, OVS_DP_ATTR_STATS, sizeof(struct ovs_dp_stats),
1530 &dp_stats, OVS_DP_ATTR_PAD))
1531 goto nla_put_failure;
1532
1533 if (nla_put_64bit(skb, OVS_DP_ATTR_MEGAFLOW_STATS,
1534 sizeof(struct ovs_dp_megaflow_stats),
1535 &dp_megaflow_stats, OVS_DP_ATTR_PAD))
1536 goto nla_put_failure;
1537
1538 if (nla_put_u32(skb, OVS_DP_ATTR_USER_FEATURES, dp->user_features))
1539 goto nla_put_failure;
1540
1541 genlmsg_end(skb, ovs_header);
1542 return 0;
1543
1544 nla_put_failure:
1545 genlmsg_cancel(skb, ovs_header);
1546 error:
1547 return -EMSGSIZE;
1548 }
1549
1550 static struct sk_buff *ovs_dp_cmd_alloc_info(void)
1551 {
1552 return genlmsg_new(ovs_dp_cmd_msg_size(), GFP_KERNEL);
1553 }
1554
1555 /* Called with rcu_read_lock or ovs_mutex. */
1556 static struct datapath *lookup_datapath(struct net *net,
1557 const struct ovs_header *ovs_header,
1558 struct nlattr *a[OVS_DP_ATTR_MAX + 1])
1559 {
1560 struct datapath *dp;
1561
1562 if (!a[OVS_DP_ATTR_NAME])
1563 dp = get_dp(net, ovs_header->dp_ifindex);
1564 else {
1565 struct vport *vport;
1566
1567 vport = ovs_vport_locate(net, nla_data(a[OVS_DP_ATTR_NAME]));
1568 dp = vport && vport->port_no == OVSP_LOCAL ? vport->dp : NULL;
1569 }
1570 return dp ? dp : ERR_PTR(-ENODEV);
1571 }
1572
1573 static void ovs_dp_reset_user_features(struct sk_buff *skb, struct genl_info *info)
1574 {
1575 struct datapath *dp;
1576
1577 dp = lookup_datapath(sock_net(skb->sk), info->userhdr, info->attrs);
1578 if (IS_ERR(dp))
1579 return;
1580
1581 WARN(dp->user_features, "Dropping previously announced user features\n");
1582 dp->user_features = 0;
1583 }
1584
1585 static void ovs_dp_change(struct datapath *dp, struct nlattr *a[])
1586 {
1587 if (a[OVS_DP_ATTR_USER_FEATURES])
1588 dp->user_features = nla_get_u32(a[OVS_DP_ATTR_USER_FEATURES]);
1589 }
1590
1591 static int ovs_dp_cmd_new(struct sk_buff *skb, struct genl_info *info)
1592 {
1593 struct nlattr **a = info->attrs;
1594 struct vport_parms parms;
1595 struct sk_buff *reply;
1596 struct datapath *dp;
1597 struct vport *vport;
1598 struct ovs_net *ovs_net;
1599 int err, i;
1600
1601 err = -EINVAL;
1602 if (!a[OVS_DP_ATTR_NAME] || !a[OVS_DP_ATTR_UPCALL_PID])
1603 goto err;
1604
1605 reply = ovs_dp_cmd_alloc_info();
1606 if (!reply)
1607 return -ENOMEM;
1608
1609 err = -ENOMEM;
1610 dp = kzalloc(sizeof(*dp), GFP_KERNEL);
1611 if (dp == NULL)
1612 goto err_free_reply;
1613
1614 ovs_dp_set_net(dp, sock_net(skb->sk));
1615
1616 /* Allocate table. */
1617 err = ovs_flow_tbl_init(&dp->table);
1618 if (err)
1619 goto err_free_dp;
1620
1621 dp->stats_percpu = netdev_alloc_pcpu_stats(struct dp_stats_percpu);
1622 if (!dp->stats_percpu) {
1623 err = -ENOMEM;
1624 goto err_destroy_table;
1625 }
1626
1627 dp->ports = kmalloc_array(DP_VPORT_HASH_BUCKETS,
1628 sizeof(struct hlist_head),
1629 GFP_KERNEL);
1630 if (!dp->ports) {
1631 err = -ENOMEM;
1632 goto err_destroy_percpu;
1633 }
1634
1635 for (i = 0; i < DP_VPORT_HASH_BUCKETS; i++)
1636 INIT_HLIST_HEAD(&dp->ports[i]);
1637
1638 err = ovs_meters_init(dp);
1639 if (err)
1640 goto err_destroy_ports_array;
1641
1642 /* Set up our datapath device. */
1643 parms.name = nla_data(a[OVS_DP_ATTR_NAME]);
1644 parms.type = OVS_VPORT_TYPE_INTERNAL;
1645 parms.options = NULL;
1646 parms.dp = dp;
1647 parms.port_no = OVSP_LOCAL;
1648 parms.upcall_portids = a[OVS_DP_ATTR_UPCALL_PID];
1649
1650 ovs_dp_change(dp, a);
1651
1652 /* So far only local changes have been made, now need the lock. */
1653 ovs_lock();
1654
1655 vport = new_vport(&parms);
1656 if (IS_ERR(vport)) {
1657 err = PTR_ERR(vport);
1658 if (err == -EBUSY)
1659 err = -EEXIST;
1660
1661 if (err == -EEXIST) {
1662 /* An outdated user space instance that does not understand
1663 * the concept of user_features has attempted to create a new
1664 * datapath and is likely to reuse it. Drop all user features.
1665 */
1666 if (info->genlhdr->version < OVS_DP_VER_FEATURES)
1667 ovs_dp_reset_user_features(skb, info);
1668 }
1669
1670 goto err_destroy_meters;
1671 }
1672
1673 err = ovs_dp_cmd_fill_info(dp, reply, info->snd_portid,
1674 info->snd_seq, 0, OVS_DP_CMD_NEW);
1675 BUG_ON(err < 0);
1676
1677 ovs_net = net_generic(ovs_dp_get_net(dp), ovs_net_id);
1678 list_add_tail_rcu(&dp->list_node, &ovs_net->dps);
1679
1680 ovs_unlock();
1681
1682 ovs_notify(&dp_datapath_genl_family, &ovs_dp_datapath_multicast_group, reply, info);
1683 return 0;
1684
1685 err_destroy_meters:
1686 ovs_unlock();
1687 ovs_meters_exit(dp);
1688 err_destroy_ports_array:
1689 kfree(dp->ports);
1690 err_destroy_percpu:
1691 free_percpu(dp->stats_percpu);
1692 err_destroy_table:
1693 ovs_flow_tbl_destroy(&dp->table);
1694 err_free_dp:
1695 kfree(dp);
1696 err_free_reply:
1697 kfree_skb(reply);
1698 err:
1699 return err;
1700 }
1701
1702 /* Called with ovs_mutex. */
1703 static void __dp_destroy(struct datapath *dp)
1704 {
1705 int i;
1706
1707 for (i = 0; i < DP_VPORT_HASH_BUCKETS; i++) {
1708 struct vport *vport;
1709 struct hlist_node *n;
1710
1711 hlist_for_each_entry_safe(vport, n, &dp->ports[i], dp_hash_node)
1712 if (vport->port_no != OVSP_LOCAL)
1713 ovs_dp_detach_port(vport);
1714 }
1715
1716 list_del_rcu(&dp->list_node);
1717
1718 /* OVSP_LOCAL is datapath internal port. We need to make sure that
1719 * all ports in datapath are destroyed first before freeing datapath.
1720 */
1721 ovs_dp_detach_port(ovs_vport_ovsl(dp, OVSP_LOCAL));
1722
1723 /* RCU destroy the flow table */
1724 call_rcu(&dp->rcu, destroy_dp_rcu);
1725 }
1726
1727 static int ovs_dp_cmd_del(struct sk_buff *skb, struct genl_info *info)
1728 {
1729 struct sk_buff *reply;
1730 struct datapath *dp;
1731 int err;
1732
1733 reply = ovs_dp_cmd_alloc_info();
1734 if (!reply)
1735 return -ENOMEM;
1736
1737 ovs_lock();
1738 dp = lookup_datapath(sock_net(skb->sk), info->userhdr, info->attrs);
1739 err = PTR_ERR(dp);
1740 if (IS_ERR(dp))
1741 goto err_unlock_free;
1742
1743 err = ovs_dp_cmd_fill_info(dp, reply, info->snd_portid,
1744 info->snd_seq, 0, OVS_DP_CMD_DEL);
1745 BUG_ON(err < 0);
1746
1747 __dp_destroy(dp);
1748 ovs_unlock();
1749
1750 ovs_notify(&dp_datapath_genl_family, &ovs_dp_datapath_multicast_group, reply, info);
1751 return 0;
1752
1753 err_unlock_free:
1754 ovs_unlock();
1755 kfree_skb(reply);
1756 return err;
1757 }
1758
1759 static int ovs_dp_cmd_set(struct sk_buff *skb, struct genl_info *info)
1760 {
1761 struct sk_buff *reply;
1762 struct datapath *dp;
1763 int err;
1764
1765 reply = ovs_dp_cmd_alloc_info();
1766 if (!reply)
1767 return -ENOMEM;
1768
1769 ovs_lock();
1770 dp = lookup_datapath(sock_net(skb->sk), info->userhdr, info->attrs);
1771 err = PTR_ERR(dp);
1772 if (IS_ERR(dp))
1773 goto err_unlock_free;
1774
1775 ovs_dp_change(dp, info->attrs);
1776
1777 err = ovs_dp_cmd_fill_info(dp, reply, info->snd_portid,
1778 info->snd_seq, 0, OVS_DP_CMD_GET);
1779 BUG_ON(err < 0);
1780
1781 ovs_unlock();
1782
1783 ovs_notify(&dp_datapath_genl_family, &ovs_dp_datapath_multicast_group, reply, info);
1784 return 0;
1785
1786 err_unlock_free:
1787 ovs_unlock();
1788 kfree_skb(reply);
1789 return err;
1790 }
1791
1792 static int ovs_dp_cmd_get(struct sk_buff *skb, struct genl_info *info)
1793 {
1794 struct sk_buff *reply;
1795 struct datapath *dp;
1796 int err;
1797
1798 reply = ovs_dp_cmd_alloc_info();
1799 if (!reply)
1800 return -ENOMEM;
1801
1802 ovs_lock();
1803 dp = lookup_datapath(sock_net(skb->sk), info->userhdr, info->attrs);
1804 if (IS_ERR(dp)) {
1805 err = PTR_ERR(dp);
1806 goto err_unlock_free;
1807 }
1808 err = ovs_dp_cmd_fill_info(dp, reply, info->snd_portid,
1809 info->snd_seq, 0, OVS_DP_CMD_GET);
1810 BUG_ON(err < 0);
1811 ovs_unlock();
1812
1813 return genlmsg_reply(reply, info);
1814
1815 err_unlock_free:
1816 ovs_unlock();
1817 kfree_skb(reply);
1818 return err;
1819 }
1820
1821 static int ovs_dp_cmd_dump(struct sk_buff *skb, struct netlink_callback *cb)
1822 {
1823 struct ovs_net *ovs_net = net_generic(sock_net(skb->sk), ovs_net_id);
1824 struct datapath *dp;
1825 int skip = cb->args[0];
1826 int i = 0;
1827
1828 ovs_lock();
1829 list_for_each_entry(dp, &ovs_net->dps, list_node) {
1830 if (i >= skip &&
1831 ovs_dp_cmd_fill_info(dp, skb, NETLINK_CB(cb->skb).portid,
1832 cb->nlh->nlmsg_seq, NLM_F_MULTI,
1833 OVS_DP_CMD_GET) < 0)
1834 break;
1835 i++;
1836 }
1837 ovs_unlock();
1838
1839 cb->args[0] = i;
1840
1841 return skb->len;
1842 }
1843
1844 static const struct nla_policy datapath_policy[OVS_DP_ATTR_MAX + 1] = {
1845 [OVS_DP_ATTR_NAME] = { .type = NLA_NUL_STRING, .len = IFNAMSIZ - 1 },
1846 [OVS_DP_ATTR_UPCALL_PID] = { .type = NLA_U32 },
1847 [OVS_DP_ATTR_USER_FEATURES] = { .type = NLA_U32 },
1848 };
1849
1850 static const struct genl_ops dp_datapath_genl_ops[] = {
1851 { .cmd = OVS_DP_CMD_NEW,
1852 #ifdef HAVE_GENL_VALIDATE_FLAGS
1853 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
1854 #endif
1855 .flags = GENL_UNS_ADMIN_PERM, /* Requires CAP_NET_ADMIN privilege. */
1856 .policy = datapath_policy,
1857 .doit = ovs_dp_cmd_new
1858 },
1859 { .cmd = OVS_DP_CMD_DEL,
1860 #ifdef HAVE_GENL_VALIDATE_FLAGS
1861 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
1862 #endif
1863 .flags = GENL_UNS_ADMIN_PERM, /* Requires CAP_NET_ADMIN privilege. */
1864 .policy = datapath_policy,
1865 .doit = ovs_dp_cmd_del
1866 },
1867 { .cmd = OVS_DP_CMD_GET,
1868 #ifdef HAVE_GENL_VALIDATE_FLAGS
1869 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
1870 #endif
1871 .flags = 0, /* OK for unprivileged users. */
1872 .policy = datapath_policy,
1873 .doit = ovs_dp_cmd_get,
1874 .dumpit = ovs_dp_cmd_dump
1875 },
1876 { .cmd = OVS_DP_CMD_SET,
1877 #ifdef HAVE_GENL_VALIDATE_FLAGS
1878 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
1879 #endif
1880 .flags = GENL_UNS_ADMIN_PERM, /* Requires CAP_NET_ADMIN privilege. */
1881 .policy = datapath_policy,
1882 .doit = ovs_dp_cmd_set,
1883 },
1884 };
1885
1886 static struct genl_family dp_datapath_genl_family __ro_after_init = {
1887 .hdrsize = sizeof(struct ovs_header),
1888 .name = OVS_DATAPATH_FAMILY,
1889 .version = OVS_DATAPATH_VERSION,
1890 .maxattr = OVS_DP_ATTR_MAX,
1891 .netnsok = true,
1892 .parallel_ops = true,
1893 .ops = dp_datapath_genl_ops,
1894 .n_ops = ARRAY_SIZE(dp_datapath_genl_ops),
1895 .mcgrps = &ovs_dp_datapath_multicast_group,
1896 .n_mcgrps = 1,
1897 .module = THIS_MODULE,
1898 };
1899
1900 /* Called with ovs_mutex or RCU read lock. */
1901 static int ovs_vport_cmd_fill_info(struct vport *vport, struct sk_buff *skb,
1902 struct net *net, u32 portid, u32 seq,
1903 u32 flags, u8 cmd)
1904 {
1905 struct ovs_header *ovs_header;
1906 struct ovs_vport_stats vport_stats;
1907 int err;
1908
1909 ovs_header = genlmsg_put(skb, portid, seq, &dp_vport_genl_family,
1910 flags, cmd);
1911 if (!ovs_header)
1912 return -EMSGSIZE;
1913
1914 ovs_header->dp_ifindex = get_dpifindex(vport->dp);
1915
1916 if (nla_put_u32(skb, OVS_VPORT_ATTR_PORT_NO, vport->port_no) ||
1917 nla_put_u32(skb, OVS_VPORT_ATTR_TYPE, vport->ops->type) ||
1918 nla_put_string(skb, OVS_VPORT_ATTR_NAME,
1919 ovs_vport_name(vport)) ||
1920 nla_put_u32(skb, OVS_VPORT_ATTR_IFINDEX, vport->dev->ifindex))
1921 goto nla_put_failure;
1922
1923 #ifdef HAVE_PEERNET2ID_ALLOC
1924 if (!net_eq(net, dev_net(vport->dev))) {
1925 int id = peernet2id_alloc(net, dev_net(vport->dev));
1926
1927 if (nla_put_s32(skb, OVS_VPORT_ATTR_NETNSID, id))
1928 goto nla_put_failure;
1929 }
1930
1931 #endif
1932 ovs_vport_get_stats(vport, &vport_stats);
1933 if (nla_put_64bit(skb, OVS_VPORT_ATTR_STATS,
1934 sizeof(struct ovs_vport_stats), &vport_stats,
1935 OVS_VPORT_ATTR_PAD))
1936 goto nla_put_failure;
1937
1938 if (ovs_vport_get_upcall_portids(vport, skb))
1939 goto nla_put_failure;
1940
1941 err = ovs_vport_get_options(vport, skb);
1942 if (err == -EMSGSIZE)
1943 goto error;
1944
1945 genlmsg_end(skb, ovs_header);
1946 return 0;
1947
1948 nla_put_failure:
1949 err = -EMSGSIZE;
1950 error:
1951 genlmsg_cancel(skb, ovs_header);
1952 return err;
1953 }
1954
1955 static struct sk_buff *ovs_vport_cmd_alloc_info(void)
1956 {
1957 return nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
1958 }
1959
1960 /* Called with ovs_mutex, only via ovs_dp_notify_wq(). */
1961 struct sk_buff *ovs_vport_cmd_build_info(struct vport *vport, struct net *net,
1962 u32 portid, u32 seq, u8 cmd)
1963 {
1964 struct sk_buff *skb;
1965 int retval;
1966
1967 skb = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC);
1968 if (!skb)
1969 return ERR_PTR(-ENOMEM);
1970
1971 retval = ovs_vport_cmd_fill_info(vport, skb, net, portid, seq, 0, cmd);
1972 BUG_ON(retval < 0);
1973
1974 return skb;
1975 }
1976
1977 /* Called with ovs_mutex or RCU read lock. */
1978 static struct vport *lookup_vport(struct net *net,
1979 const struct ovs_header *ovs_header,
1980 struct nlattr *a[OVS_VPORT_ATTR_MAX + 1])
1981 {
1982 struct datapath *dp;
1983 struct vport *vport;
1984
1985 if (a[OVS_VPORT_ATTR_IFINDEX])
1986 return ERR_PTR(-EOPNOTSUPP);
1987 if (a[OVS_VPORT_ATTR_NAME]) {
1988 vport = ovs_vport_locate(net, nla_data(a[OVS_VPORT_ATTR_NAME]));
1989 if (!vport)
1990 return ERR_PTR(-ENODEV);
1991 if (ovs_header->dp_ifindex &&
1992 ovs_header->dp_ifindex != get_dpifindex(vport->dp))
1993 return ERR_PTR(-ENODEV);
1994 return vport;
1995 } else if (a[OVS_VPORT_ATTR_PORT_NO]) {
1996 u32 port_no = nla_get_u32(a[OVS_VPORT_ATTR_PORT_NO]);
1997
1998 if (port_no >= DP_MAX_PORTS)
1999 return ERR_PTR(-EFBIG);
2000
2001 dp = get_dp(net, ovs_header->dp_ifindex);
2002 if (!dp)
2003 return ERR_PTR(-ENODEV);
2004
2005 vport = ovs_vport_ovsl_rcu(dp, port_no);
2006 if (!vport)
2007 return ERR_PTR(-ENODEV);
2008 return vport;
2009 } else
2010 return ERR_PTR(-EINVAL);
2011
2012 }
2013
2014 /* Called with ovs_mutex */
2015 static void update_headroom(struct datapath *dp)
2016 {
2017 unsigned dev_headroom, max_headroom = 0;
2018 struct net_device *dev;
2019 struct vport *vport;
2020 int i;
2021
2022 for (i = 0; i < DP_VPORT_HASH_BUCKETS; i++) {
2023 hlist_for_each_entry_rcu(vport, &dp->ports[i], dp_hash_node) {
2024 dev = vport->dev;
2025 dev_headroom = netdev_get_fwd_headroom(dev);
2026 if (dev_headroom > max_headroom)
2027 max_headroom = dev_headroom;
2028 }
2029 }
2030
2031 dp->max_headroom = max_headroom;
2032 for (i = 0; i < DP_VPORT_HASH_BUCKETS; i++)
2033 hlist_for_each_entry_rcu(vport, &dp->ports[i], dp_hash_node)
2034 netdev_set_rx_headroom(vport->dev, max_headroom);
2035 }
2036
2037 static int ovs_vport_cmd_new(struct sk_buff *skb, struct genl_info *info)
2038 {
2039 struct nlattr **a = info->attrs;
2040 struct ovs_header *ovs_header = info->userhdr;
2041 struct vport_parms parms;
2042 struct sk_buff *reply;
2043 struct vport *vport;
2044 struct datapath *dp;
2045 u32 port_no;
2046 int err;
2047
2048 if (!a[OVS_VPORT_ATTR_NAME] || !a[OVS_VPORT_ATTR_TYPE] ||
2049 !a[OVS_VPORT_ATTR_UPCALL_PID])
2050 return -EINVAL;
2051 if (a[OVS_VPORT_ATTR_IFINDEX])
2052 return -EOPNOTSUPP;
2053
2054 port_no = a[OVS_VPORT_ATTR_PORT_NO]
2055 ? nla_get_u32(a[OVS_VPORT_ATTR_PORT_NO]) : 0;
2056 if (port_no >= DP_MAX_PORTS)
2057 return -EFBIG;
2058
2059 reply = ovs_vport_cmd_alloc_info();
2060 if (!reply)
2061 return -ENOMEM;
2062
2063 ovs_lock();
2064 restart:
2065 dp = get_dp(sock_net(skb->sk), ovs_header->dp_ifindex);
2066 err = -ENODEV;
2067 if (!dp)
2068 goto exit_unlock_free;
2069
2070 if (port_no) {
2071 vport = ovs_vport_ovsl(dp, port_no);
2072 err = -EBUSY;
2073 if (vport)
2074 goto exit_unlock_free;
2075 } else {
2076 for (port_no = 1; ; port_no++) {
2077 if (port_no >= DP_MAX_PORTS) {
2078 err = -EFBIG;
2079 goto exit_unlock_free;
2080 }
2081 vport = ovs_vport_ovsl(dp, port_no);
2082 if (!vport)
2083 break;
2084 }
2085 }
2086
2087 parms.name = nla_data(a[OVS_VPORT_ATTR_NAME]);
2088 parms.type = nla_get_u32(a[OVS_VPORT_ATTR_TYPE]);
2089 parms.options = a[OVS_VPORT_ATTR_OPTIONS];
2090 parms.dp = dp;
2091 parms.port_no = port_no;
2092 parms.upcall_portids = a[OVS_VPORT_ATTR_UPCALL_PID];
2093
2094 vport = new_vport(&parms);
2095 err = PTR_ERR(vport);
2096 if (IS_ERR(vport)) {
2097 if (err == -EAGAIN)
2098 goto restart;
2099 goto exit_unlock_free;
2100 }
2101
2102 err = ovs_vport_cmd_fill_info(vport, reply, genl_info_net(info),
2103 info->snd_portid, info->snd_seq, 0,
2104 OVS_VPORT_CMD_NEW);
2105 BUG_ON(err < 0);
2106
2107 if (netdev_get_fwd_headroom(vport->dev) > dp->max_headroom)
2108 update_headroom(dp);
2109 else
2110 netdev_set_rx_headroom(vport->dev, dp->max_headroom);
2111
2112 ovs_unlock();
2113
2114 ovs_notify(&dp_vport_genl_family, &ovs_dp_vport_multicast_group, reply, info);
2115 return 0;
2116
2117 exit_unlock_free:
2118 ovs_unlock();
2119 kfree_skb(reply);
2120 return err;
2121 }
2122
2123 static int ovs_vport_cmd_set(struct sk_buff *skb, struct genl_info *info)
2124 {
2125 struct nlattr **a = info->attrs;
2126 struct sk_buff *reply;
2127 struct vport *vport;
2128 int err;
2129
2130 reply = ovs_vport_cmd_alloc_info();
2131 if (!reply)
2132 return -ENOMEM;
2133
2134 ovs_lock();
2135 vport = lookup_vport(sock_net(skb->sk), info->userhdr, a);
2136 err = PTR_ERR(vport);
2137 if (IS_ERR(vport))
2138 goto exit_unlock_free;
2139
2140 if (a[OVS_VPORT_ATTR_TYPE] &&
2141 nla_get_u32(a[OVS_VPORT_ATTR_TYPE]) != vport->ops->type) {
2142 err = -EINVAL;
2143 goto exit_unlock_free;
2144 }
2145
2146 if (a[OVS_VPORT_ATTR_OPTIONS]) {
2147 err = ovs_vport_set_options(vport, a[OVS_VPORT_ATTR_OPTIONS]);
2148 if (err)
2149 goto exit_unlock_free;
2150 }
2151
2152 if (a[OVS_VPORT_ATTR_UPCALL_PID]) {
2153 struct nlattr *ids = a[OVS_VPORT_ATTR_UPCALL_PID];
2154
2155 err = ovs_vport_set_upcall_portids(vport, ids);
2156 if (err)
2157 goto exit_unlock_free;
2158 }
2159
2160 err = ovs_vport_cmd_fill_info(vport, reply, genl_info_net(info),
2161 info->snd_portid, info->snd_seq, 0,
2162 OVS_VPORT_CMD_SET);
2163 BUG_ON(err < 0);
2164 ovs_unlock();
2165
2166 ovs_notify(&dp_vport_genl_family, &ovs_dp_vport_multicast_group, reply, info);
2167 return 0;
2168
2169 exit_unlock_free:
2170 ovs_unlock();
2171 kfree_skb(reply);
2172 return err;
2173 }
2174
2175 static int ovs_vport_cmd_del(struct sk_buff *skb, struct genl_info *info)
2176 {
2177 bool must_update_headroom = false;
2178 struct nlattr **a = info->attrs;
2179 struct sk_buff *reply;
2180 struct datapath *dp;
2181 struct vport *vport;
2182 int err;
2183
2184 reply = ovs_vport_cmd_alloc_info();
2185 if (!reply)
2186 return -ENOMEM;
2187
2188 ovs_lock();
2189 vport = lookup_vport(sock_net(skb->sk), info->userhdr, a);
2190 err = PTR_ERR(vport);
2191 if (IS_ERR(vport))
2192 goto exit_unlock_free;
2193
2194 if (vport->port_no == OVSP_LOCAL) {
2195 err = -EINVAL;
2196 goto exit_unlock_free;
2197 }
2198
2199 err = ovs_vport_cmd_fill_info(vport, reply, genl_info_net(info),
2200 info->snd_portid, info->snd_seq, 0,
2201 OVS_VPORT_CMD_DEL);
2202 BUG_ON(err < 0);
2203
2204 /* the vport deletion may trigger dp headroom update */
2205 dp = vport->dp;
2206 if (netdev_get_fwd_headroom(vport->dev) == dp->max_headroom)
2207 must_update_headroom = true;
2208 netdev_reset_rx_headroom(vport->dev);
2209 ovs_dp_detach_port(vport);
2210
2211 if (must_update_headroom)
2212 update_headroom(dp);
2213
2214 ovs_unlock();
2215
2216 ovs_notify(&dp_vport_genl_family, &ovs_dp_vport_multicast_group, reply, info);
2217 return 0;
2218
2219 exit_unlock_free:
2220 ovs_unlock();
2221 kfree_skb(reply);
2222 return err;
2223 }
2224
2225 static int ovs_vport_cmd_get(struct sk_buff *skb, struct genl_info *info)
2226 {
2227 struct nlattr **a = info->attrs;
2228 struct ovs_header *ovs_header = info->userhdr;
2229 struct sk_buff *reply;
2230 struct vport *vport;
2231 int err;
2232
2233 reply = ovs_vport_cmd_alloc_info();
2234 if (!reply)
2235 return -ENOMEM;
2236
2237 rcu_read_lock();
2238 vport = lookup_vport(sock_net(skb->sk), ovs_header, a);
2239 err = PTR_ERR(vport);
2240 if (IS_ERR(vport))
2241 goto exit_unlock_free;
2242 err = ovs_vport_cmd_fill_info(vport, reply, genl_info_net(info),
2243 info->snd_portid, info->snd_seq, 0,
2244 OVS_VPORT_CMD_GET);
2245 BUG_ON(err < 0);
2246 rcu_read_unlock();
2247
2248 return genlmsg_reply(reply, info);
2249
2250 exit_unlock_free:
2251 rcu_read_unlock();
2252 kfree_skb(reply);
2253 return err;
2254 }
2255
2256 static int ovs_vport_cmd_dump(struct sk_buff *skb, struct netlink_callback *cb)
2257 {
2258 struct ovs_header *ovs_header = genlmsg_data(nlmsg_data(cb->nlh));
2259 struct datapath *dp;
2260 int bucket = cb->args[0], skip = cb->args[1];
2261 int i, j = 0;
2262
2263 rcu_read_lock();
2264 dp = get_dp_rcu(sock_net(skb->sk), ovs_header->dp_ifindex);
2265 if (!dp) {
2266 rcu_read_unlock();
2267 return -ENODEV;
2268 }
2269 for (i = bucket; i < DP_VPORT_HASH_BUCKETS; i++) {
2270 struct vport *vport;
2271
2272 j = 0;
2273 hlist_for_each_entry_rcu(vport, &dp->ports[i], dp_hash_node) {
2274 if (j >= skip &&
2275 ovs_vport_cmd_fill_info(vport, skb,
2276 sock_net(skb->sk),
2277 NETLINK_CB(cb->skb).portid,
2278 cb->nlh->nlmsg_seq,
2279 NLM_F_MULTI,
2280 OVS_VPORT_CMD_GET) < 0)
2281 goto out;
2282
2283 j++;
2284 }
2285 skip = 0;
2286 }
2287 out:
2288 rcu_read_unlock();
2289
2290 cb->args[0] = i;
2291 cb->args[1] = j;
2292
2293 return skb->len;
2294 }
2295
2296 static const struct nla_policy vport_policy[OVS_VPORT_ATTR_MAX + 1] = {
2297 [OVS_VPORT_ATTR_NAME] = { .type = NLA_NUL_STRING, .len = IFNAMSIZ - 1 },
2298 [OVS_VPORT_ATTR_STATS] = { .len = sizeof(struct ovs_vport_stats) },
2299 [OVS_VPORT_ATTR_PORT_NO] = { .type = NLA_U32 },
2300 [OVS_VPORT_ATTR_TYPE] = { .type = NLA_U32 },
2301 [OVS_VPORT_ATTR_UPCALL_PID] = { .type = NLA_UNSPEC },
2302 [OVS_VPORT_ATTR_OPTIONS] = { .type = NLA_NESTED },
2303 [OVS_VPORT_ATTR_IFINDEX] = { .type = NLA_U32 },
2304 [OVS_VPORT_ATTR_NETNSID] = { .type = NLA_S32 },
2305 };
2306
2307 static const struct genl_ops dp_vport_genl_ops[] = {
2308 { .cmd = OVS_VPORT_CMD_NEW,
2309 #ifdef HAVE_GENL_VALIDATE_FLAGS
2310 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
2311 #endif
2312 .flags = GENL_UNS_ADMIN_PERM, /* Requires CAP_NET_ADMIN privilege. */
2313 .policy = vport_policy,
2314 .doit = ovs_vport_cmd_new
2315 },
2316 { .cmd = OVS_VPORT_CMD_DEL,
2317 #ifdef HAVE_GENL_VALIDATE_FLAGS
2318 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
2319 #endif
2320 .flags = GENL_UNS_ADMIN_PERM, /* Requires CAP_NET_ADMIN privilege. */
2321 .policy = vport_policy,
2322 .doit = ovs_vport_cmd_del
2323 },
2324 { .cmd = OVS_VPORT_CMD_GET,
2325 #ifdef HAVE_GENL_VALIDATE_FLAGS
2326 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
2327 #endif
2328 .flags = 0, /* OK for unprivileged users. */
2329 .policy = vport_policy,
2330 .doit = ovs_vport_cmd_get,
2331 .dumpit = ovs_vport_cmd_dump
2332 },
2333 { .cmd = OVS_VPORT_CMD_SET,
2334 #ifdef HAVE_GENL_VALIDATE_FLAGS
2335 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
2336 #endif
2337 .flags = GENL_UNS_ADMIN_PERM, /* Requires CAP_NET_ADMIN privilege. */
2338 .policy = vport_policy,
2339 .doit = ovs_vport_cmd_set,
2340 },
2341 };
2342
2343 struct genl_family dp_vport_genl_family __ro_after_init = {
2344 .hdrsize = sizeof(struct ovs_header),
2345 .name = OVS_VPORT_FAMILY,
2346 .version = OVS_VPORT_VERSION,
2347 .maxattr = OVS_VPORT_ATTR_MAX,
2348 .netnsok = true,
2349 .parallel_ops = true,
2350 .ops = dp_vport_genl_ops,
2351 .n_ops = ARRAY_SIZE(dp_vport_genl_ops),
2352 .mcgrps = &ovs_dp_vport_multicast_group,
2353 .n_mcgrps = 1,
2354 .module = THIS_MODULE,
2355 };
2356
2357 static struct genl_family *dp_genl_families[] = {
2358 &dp_datapath_genl_family,
2359 &dp_vport_genl_family,
2360 &dp_flow_genl_family,
2361 &dp_packet_genl_family,
2362 &dp_meter_genl_family,
2363 #if IS_ENABLED(CONFIG_NETFILTER_CONNCOUNT)
2364 &dp_ct_limit_genl_family,
2365 #endif
2366 };
2367
2368 static void dp_unregister_genl(int n_families)
2369 {
2370 int i;
2371
2372 for (i = 0; i < n_families; i++)
2373 genl_unregister_family(dp_genl_families[i]);
2374 }
2375
2376 static int __init dp_register_genl(void)
2377 {
2378 int err;
2379 int i;
2380
2381 for (i = 0; i < ARRAY_SIZE(dp_genl_families); i++) {
2382
2383 err = genl_register_family(dp_genl_families[i]);
2384 if (err)
2385 goto error;
2386 }
2387
2388 return 0;
2389
2390 error:
2391 dp_unregister_genl(i);
2392 return err;
2393 }
2394
2395 static int __net_init ovs_init_net(struct net *net)
2396 {
2397 struct ovs_net *ovs_net = net_generic(net, ovs_net_id);
2398
2399 INIT_LIST_HEAD(&ovs_net->dps);
2400 INIT_WORK(&ovs_net->dp_notify_work, ovs_dp_notify_wq);
2401 ovs_netns_frags_init(net);
2402 ovs_netns_frags6_init(net);
2403 return ovs_ct_init(net);
2404 }
2405
2406 static void __net_exit list_vports_from_net(struct net *net, struct net *dnet,
2407 struct list_head *head)
2408 {
2409 struct ovs_net *ovs_net = net_generic(net, ovs_net_id);
2410 struct datapath *dp;
2411
2412 list_for_each_entry(dp, &ovs_net->dps, list_node) {
2413 int i;
2414
2415 for (i = 0; i < DP_VPORT_HASH_BUCKETS; i++) {
2416 struct vport *vport;
2417
2418 hlist_for_each_entry(vport, &dp->ports[i], dp_hash_node) {
2419
2420 if (vport->ops->type != OVS_VPORT_TYPE_INTERNAL)
2421 continue;
2422
2423 if (dev_net(vport->dev) == dnet)
2424 list_add(&vport->detach_list, head);
2425 }
2426 }
2427 }
2428 }
2429
2430 static void __net_exit ovs_exit_net(struct net *dnet)
2431 {
2432 struct datapath *dp, *dp_next;
2433 struct ovs_net *ovs_net = net_generic(dnet, ovs_net_id);
2434 struct vport *vport, *vport_next;
2435 struct net *net;
2436 LIST_HEAD(head);
2437
2438 ovs_netns_frags6_exit(dnet);
2439 ovs_netns_frags_exit(dnet);
2440 ovs_ct_exit(dnet);
2441 ovs_lock();
2442 list_for_each_entry_safe(dp, dp_next, &ovs_net->dps, list_node)
2443 __dp_destroy(dp);
2444
2445 #ifdef HAVE_NET_RWSEM
2446 down_read(&net_rwsem);
2447 #else
2448 rtnl_lock();
2449 #endif
2450 for_each_net(net)
2451 list_vports_from_net(net, dnet, &head);
2452 #ifdef HAVE_NET_RWSEM
2453 up_read(&net_rwsem);
2454 #else
2455 rtnl_unlock();
2456 #endif
2457
2458 /* Detach all vports from given namespace. */
2459 list_for_each_entry_safe(vport, vport_next, &head, detach_list) {
2460 list_del(&vport->detach_list);
2461 ovs_dp_detach_port(vport);
2462 }
2463
2464 ovs_unlock();
2465
2466 cancel_work_sync(&ovs_net->dp_notify_work);
2467 }
2468
2469 static struct pernet_operations ovs_net_ops = {
2470 .init = ovs_init_net,
2471 .exit = ovs_exit_net,
2472 .id = &ovs_net_id,
2473 .size = sizeof(struct ovs_net),
2474 };
2475
2476 static int __init dp_init(void)
2477 {
2478 int err;
2479
2480 BUILD_BUG_ON(sizeof(struct ovs_skb_cb) > FIELD_SIZEOF(struct sk_buff, cb));
2481
2482 pr_info("Open vSwitch switching datapath %s\n", VERSION);
2483
2484 ovs_nsh_init();
2485 err = action_fifos_init();
2486 if (err)
2487 goto error;
2488
2489 err = ovs_internal_dev_rtnl_link_register();
2490 if (err)
2491 goto error_action_fifos_exit;
2492
2493 err = ovs_flow_init();
2494 if (err)
2495 goto error_unreg_rtnl_link;
2496
2497 err = ovs_vport_init();
2498 if (err)
2499 goto error_flow_exit;
2500
2501 err = register_pernet_device(&ovs_net_ops);
2502 if (err)
2503 goto error_vport_exit;
2504
2505 err = compat_init();
2506 if (err)
2507 goto error_netns_exit;
2508
2509 err = register_netdevice_notifier(&ovs_dp_device_notifier);
2510 if (err)
2511 goto error_compat_exit;
2512
2513 err = ovs_netdev_init();
2514 if (err)
2515 goto error_unreg_notifier;
2516
2517 err = dp_register_genl();
2518 if (err < 0)
2519 goto error_unreg_netdev;
2520
2521 return 0;
2522
2523 error_unreg_netdev:
2524 ovs_netdev_exit();
2525 error_unreg_notifier:
2526 unregister_netdevice_notifier(&ovs_dp_device_notifier);
2527 error_compat_exit:
2528 compat_exit();
2529 error_netns_exit:
2530 unregister_pernet_device(&ovs_net_ops);
2531 error_vport_exit:
2532 ovs_vport_exit();
2533 error_flow_exit:
2534 ovs_flow_exit();
2535 error_unreg_rtnl_link:
2536 ovs_internal_dev_rtnl_link_unregister();
2537 error_action_fifos_exit:
2538 action_fifos_exit();
2539 error:
2540 ovs_nsh_cleanup();
2541 return err;
2542 }
2543
2544 static void dp_cleanup(void)
2545 {
2546 dp_unregister_genl(ARRAY_SIZE(dp_genl_families));
2547 ovs_netdev_exit();
2548 unregister_netdevice_notifier(&ovs_dp_device_notifier);
2549 compat_exit();
2550 unregister_pernet_device(&ovs_net_ops);
2551 rcu_barrier();
2552 ovs_vport_exit();
2553 ovs_flow_exit();
2554 ovs_internal_dev_rtnl_link_unregister();
2555 action_fifos_exit();
2556 ovs_nsh_cleanup();
2557 }
2558
2559 module_init(dp_init);
2560 module_exit(dp_cleanup);
2561
2562 MODULE_DESCRIPTION("Open vSwitch switching datapath");
2563 MODULE_LICENSE("GPL");
2564 MODULE_VERSION(VERSION);
2565 MODULE_ALIAS_GENL_FAMILY(OVS_DATAPATH_FAMILY);
2566 MODULE_ALIAS_GENL_FAMILY(OVS_VPORT_FAMILY);
2567 MODULE_ALIAS_GENL_FAMILY(OVS_FLOW_FAMILY);
2568 MODULE_ALIAS_GENL_FAMILY(OVS_PACKET_FAMILY);
2569 MODULE_ALIAS_GENL_FAMILY(OVS_METER_FAMILY);
2570 MODULE_ALIAS_GENL_FAMILY(OVS_CT_LIMIT_FAMILY);