flow_netlink.c (91de76e661a266731fc2889a398ad1694df9d523) flow_netlink.c (b2d0f5d5dc53532e6f07bc546a476a55ebdfe0f3)
1/*
2 * Copyright (c) 2007-2017 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

--- 34 unchanged lines hidden (view full) ---

43#include <linux/icmpv6.h>
44#include <linux/rculist.h>
45#include <net/geneve.h>
46#include <net/ip.h>
47#include <net/ipv6.h>
48#include <net/ndisc.h>
49#include <net/mpls.h>
50#include <net/vxlan.h>
1/*
2 * Copyright (c) 2007-2017 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

--- 34 unchanged lines hidden (view full) ---

43#include <linux/icmpv6.h>
44#include <linux/rculist.h>
45#include <net/geneve.h>
46#include <net/ip.h>
47#include <net/ipv6.h>
48#include <net/ndisc.h>
49#include <net/mpls.h>
50#include <net/vxlan.h>
51#include <net/tun_proto.h>
52#include <net/erspan.h>
51
52#include "flow_netlink.h"
53
54struct ovs_len_tbl {
55 int len;
56 const struct ovs_len_tbl *next;
57};
58

--- 11 unchanged lines hidden (view full) ---

70 switch (action) {
71 case OVS_ACTION_ATTR_OUTPUT:
72 case OVS_ACTION_ATTR_RECIRC:
73 case OVS_ACTION_ATTR_TRUNC:
74 case OVS_ACTION_ATTR_USERSPACE:
75 break;
76
77 case OVS_ACTION_ATTR_CT:
53
54#include "flow_netlink.h"
55
56struct ovs_len_tbl {
57 int len;
58 const struct ovs_len_tbl *next;
59};
60

--- 11 unchanged lines hidden (view full) ---

72 switch (action) {
73 case OVS_ACTION_ATTR_OUTPUT:
74 case OVS_ACTION_ATTR_RECIRC:
75 case OVS_ACTION_ATTR_TRUNC:
76 case OVS_ACTION_ATTR_USERSPACE:
77 break;
78
79 case OVS_ACTION_ATTR_CT:
80 case OVS_ACTION_ATTR_CT_CLEAR:
78 case OVS_ACTION_ATTR_HASH:
79 case OVS_ACTION_ATTR_POP_ETH:
80 case OVS_ACTION_ATTR_POP_MPLS:
81 case OVS_ACTION_ATTR_HASH:
82 case OVS_ACTION_ATTR_POP_ETH:
83 case OVS_ACTION_ATTR_POP_MPLS:
84 case OVS_ACTION_ATTR_POP_NSH:
81 case OVS_ACTION_ATTR_POP_VLAN:
82 case OVS_ACTION_ATTR_PUSH_ETH:
83 case OVS_ACTION_ATTR_PUSH_MPLS:
85 case OVS_ACTION_ATTR_POP_VLAN:
86 case OVS_ACTION_ATTR_PUSH_ETH:
87 case OVS_ACTION_ATTR_PUSH_MPLS:
88 case OVS_ACTION_ATTR_PUSH_NSH:
84 case OVS_ACTION_ATTR_PUSH_VLAN:
85 case OVS_ACTION_ATTR_SAMPLE:
86 case OVS_ACTION_ATTR_SET:
87 case OVS_ACTION_ATTR_SET_MASKED:
88 default:
89 return true;
90 }
91 }

--- 76 unchanged lines hidden (view full) ---

168 | (1 << OVS_KEY_ATTR_TCP)
169 | (1 << OVS_KEY_ATTR_TCP_FLAGS)
170 | (1 << OVS_KEY_ATTR_UDP)
171 | (1 << OVS_KEY_ATTR_SCTP)
172 | (1 << OVS_KEY_ATTR_ICMP)
173 | (1 << OVS_KEY_ATTR_ICMPV6)
174 | (1 << OVS_KEY_ATTR_ARP)
175 | (1 << OVS_KEY_ATTR_ND)
89 case OVS_ACTION_ATTR_PUSH_VLAN:
90 case OVS_ACTION_ATTR_SAMPLE:
91 case OVS_ACTION_ATTR_SET:
92 case OVS_ACTION_ATTR_SET_MASKED:
93 default:
94 return true;
95 }
96 }

--- 76 unchanged lines hidden (view full) ---

173 | (1 << OVS_KEY_ATTR_TCP)
174 | (1 << OVS_KEY_ATTR_TCP_FLAGS)
175 | (1 << OVS_KEY_ATTR_UDP)
176 | (1 << OVS_KEY_ATTR_SCTP)
177 | (1 << OVS_KEY_ATTR_ICMP)
178 | (1 << OVS_KEY_ATTR_ICMPV6)
179 | (1 << OVS_KEY_ATTR_ARP)
180 | (1 << OVS_KEY_ATTR_ND)
176 | (1 << OVS_KEY_ATTR_MPLS));
181 | (1 << OVS_KEY_ATTR_MPLS)
182 | (1 << OVS_KEY_ATTR_NSH));
177
178 /* Always allowed mask fields. */
179 mask_allowed |= ((1 << OVS_KEY_ATTR_TUNNEL)
180 | (1 << OVS_KEY_ATTR_IN_PORT)
181 | (1 << OVS_KEY_ATTR_ETHERTYPE));
182
183 /* Check key attributes. */
184 if (match->key->eth.type == htons(ETH_P_ARP)

--- 92 unchanged lines hidden (view full) ---

277 mask_allowed &= ~(1ULL << OVS_KEY_ATTR_CT_ORIG_TUPLE_IPV6);
278 if (match->mask && (match->mask->key.tp.src == htons(0xff)))
279 mask_allowed |= 1 << OVS_KEY_ATTR_ND;
280 }
281 }
282 }
283 }
284
183
184 /* Always allowed mask fields. */
185 mask_allowed |= ((1 << OVS_KEY_ATTR_TUNNEL)
186 | (1 << OVS_KEY_ATTR_IN_PORT)
187 | (1 << OVS_KEY_ATTR_ETHERTYPE));
188
189 /* Check key attributes. */
190 if (match->key->eth.type == htons(ETH_P_ARP)

--- 92 unchanged lines hidden (view full) ---

283 mask_allowed &= ~(1ULL << OVS_KEY_ATTR_CT_ORIG_TUPLE_IPV6);
284 if (match->mask && (match->mask->key.tp.src == htons(0xff)))
285 mask_allowed |= 1 << OVS_KEY_ATTR_ND;
286 }
287 }
288 }
289 }
290
291 if (match->key->eth.type == htons(ETH_P_NSH)) {
292 key_expected |= 1 << OVS_KEY_ATTR_NSH;
293 if (match->mask &&
294 match->mask->key.eth.type == htons(0xffff)) {
295 mask_allowed |= 1 << OVS_KEY_ATTR_NSH;
296 }
297 }
298
285 if ((key_attrs & key_expected) != key_expected) {
286 /* Key attributes check failed. */
287 OVS_NLERR(log, "Missing key (keys=%llx, expected=%llx)",
288 (unsigned long long)key_attrs,
289 (unsigned long long)key_expected);
290 return false;
291 }
292

--- 21 unchanged lines hidden (view full) ---

314 + nla_total_size(0) /* OVS_TUNNEL_KEY_ATTR_DONT_FRAGMENT */
315 + nla_total_size(0) /* OVS_TUNNEL_KEY_ATTR_CSUM */
316 + nla_total_size(0) /* OVS_TUNNEL_KEY_ATTR_OAM */
317 + nla_total_size(256) /* OVS_TUNNEL_KEY_ATTR_GENEVE_OPTS */
318 /* OVS_TUNNEL_KEY_ATTR_VXLAN_OPTS is mutually exclusive with
319 * OVS_TUNNEL_KEY_ATTR_GENEVE_OPTS and covered by it.
320 */
321 + nla_total_size(2) /* OVS_TUNNEL_KEY_ATTR_TP_SRC */
299 if ((key_attrs & key_expected) != key_expected) {
300 /* Key attributes check failed. */
301 OVS_NLERR(log, "Missing key (keys=%llx, expected=%llx)",
302 (unsigned long long)key_attrs,
303 (unsigned long long)key_expected);
304 return false;
305 }
306

--- 21 unchanged lines hidden (view full) ---

328 + nla_total_size(0) /* OVS_TUNNEL_KEY_ATTR_DONT_FRAGMENT */
329 + nla_total_size(0) /* OVS_TUNNEL_KEY_ATTR_CSUM */
330 + nla_total_size(0) /* OVS_TUNNEL_KEY_ATTR_OAM */
331 + nla_total_size(256) /* OVS_TUNNEL_KEY_ATTR_GENEVE_OPTS */
332 /* OVS_TUNNEL_KEY_ATTR_VXLAN_OPTS is mutually exclusive with
333 * OVS_TUNNEL_KEY_ATTR_GENEVE_OPTS and covered by it.
334 */
335 + nla_total_size(2) /* OVS_TUNNEL_KEY_ATTR_TP_SRC */
322 + nla_total_size(2); /* OVS_TUNNEL_KEY_ATTR_TP_DST */
336 + nla_total_size(2) /* OVS_TUNNEL_KEY_ATTR_TP_DST */
337 + nla_total_size(4); /* OVS_TUNNEL_KEY_ATTR_ERSPAN_OPTS */
323}
324
338}
339
340size_t ovs_nsh_key_attr_size(void)
341{
342 /* Whenever adding new OVS_NSH_KEY_ FIELDS, we should consider
343 * updating this function.
344 */
345 return nla_total_size(NSH_BASE_HDR_LEN) /* OVS_NSH_KEY_ATTR_BASE */
346 /* OVS_NSH_KEY_ATTR_MD1 and OVS_NSH_KEY_ATTR_MD2 are
347 * mutually exclusive, so the bigger one can cover
348 * the small one.
349 */
350 + nla_total_size(NSH_CTX_HDRS_MAX_LEN);
351}
352
325size_t ovs_key_attr_size(void)
326{
327 /* Whenever adding new OVS_KEY_ FIELDS, we should consider
328 * updating this function.
329 */
353size_t ovs_key_attr_size(void)
354{
355 /* Whenever adding new OVS_KEY_ FIELDS, we should consider
356 * updating this function.
357 */
330 BUILD_BUG_ON(OVS_KEY_ATTR_TUNNEL_INFO != 28);
358 BUILD_BUG_ON(OVS_KEY_ATTR_TUNNEL_INFO != 29);
331
332 return nla_total_size(4) /* OVS_KEY_ATTR_PRIORITY */
333 + nla_total_size(0) /* OVS_KEY_ATTR_TUNNEL */
334 + ovs_tun_key_attr_size()
335 + nla_total_size(4) /* OVS_KEY_ATTR_IN_PORT */
336 + nla_total_size(4) /* OVS_KEY_ATTR_SKB_MARK */
337 + nla_total_size(4) /* OVS_KEY_ATTR_DP_HASH */
338 + nla_total_size(4) /* OVS_KEY_ATTR_RECIRC_ID */
339 + nla_total_size(4) /* OVS_KEY_ATTR_CT_STATE */
340 + nla_total_size(2) /* OVS_KEY_ATTR_CT_ZONE */
341 + nla_total_size(4) /* OVS_KEY_ATTR_CT_MARK */
342 + nla_total_size(16) /* OVS_KEY_ATTR_CT_LABELS */
343 + nla_total_size(40) /* OVS_KEY_ATTR_CT_ORIG_TUPLE_IPV6 */
359
360 return nla_total_size(4) /* OVS_KEY_ATTR_PRIORITY */
361 + nla_total_size(0) /* OVS_KEY_ATTR_TUNNEL */
362 + ovs_tun_key_attr_size()
363 + nla_total_size(4) /* OVS_KEY_ATTR_IN_PORT */
364 + nla_total_size(4) /* OVS_KEY_ATTR_SKB_MARK */
365 + nla_total_size(4) /* OVS_KEY_ATTR_DP_HASH */
366 + nla_total_size(4) /* OVS_KEY_ATTR_RECIRC_ID */
367 + nla_total_size(4) /* OVS_KEY_ATTR_CT_STATE */
368 + nla_total_size(2) /* OVS_KEY_ATTR_CT_ZONE */
369 + nla_total_size(4) /* OVS_KEY_ATTR_CT_MARK */
370 + nla_total_size(16) /* OVS_KEY_ATTR_CT_LABELS */
371 + nla_total_size(40) /* OVS_KEY_ATTR_CT_ORIG_TUPLE_IPV6 */
372 + nla_total_size(0) /* OVS_KEY_ATTR_NSH */
373 + ovs_nsh_key_attr_size()
344 + nla_total_size(12) /* OVS_KEY_ATTR_ETHERNET */
345 + nla_total_size(2) /* OVS_KEY_ATTR_ETHERTYPE */
346 + nla_total_size(4) /* OVS_KEY_ATTR_VLAN */
347 + nla_total_size(0) /* OVS_KEY_ATTR_ENCAP */
348 + nla_total_size(2) /* OVS_KEY_ATTR_ETHERTYPE */
349 + nla_total_size(40) /* OVS_KEY_ATTR_IPV6 */
350 + nla_total_size(2) /* OVS_KEY_ATTR_ICMPV6 */
351 + nla_total_size(28); /* OVS_KEY_ATTR_ND */

--- 14 unchanged lines hidden (view full) ---

366 [OVS_TUNNEL_KEY_ATTR_TP_SRC] = { .len = sizeof(u16) },
367 [OVS_TUNNEL_KEY_ATTR_TP_DST] = { .len = sizeof(u16) },
368 [OVS_TUNNEL_KEY_ATTR_OAM] = { .len = 0 },
369 [OVS_TUNNEL_KEY_ATTR_GENEVE_OPTS] = { .len = OVS_ATTR_VARIABLE },
370 [OVS_TUNNEL_KEY_ATTR_VXLAN_OPTS] = { .len = OVS_ATTR_NESTED,
371 .next = ovs_vxlan_ext_key_lens },
372 [OVS_TUNNEL_KEY_ATTR_IPV6_SRC] = { .len = sizeof(struct in6_addr) },
373 [OVS_TUNNEL_KEY_ATTR_IPV6_DST] = { .len = sizeof(struct in6_addr) },
374 + nla_total_size(12) /* OVS_KEY_ATTR_ETHERNET */
375 + nla_total_size(2) /* OVS_KEY_ATTR_ETHERTYPE */
376 + nla_total_size(4) /* OVS_KEY_ATTR_VLAN */
377 + nla_total_size(0) /* OVS_KEY_ATTR_ENCAP */
378 + nla_total_size(2) /* OVS_KEY_ATTR_ETHERTYPE */
379 + nla_total_size(40) /* OVS_KEY_ATTR_IPV6 */
380 + nla_total_size(2) /* OVS_KEY_ATTR_ICMPV6 */
381 + nla_total_size(28); /* OVS_KEY_ATTR_ND */

--- 14 unchanged lines hidden (view full) ---

396 [OVS_TUNNEL_KEY_ATTR_TP_SRC] = { .len = sizeof(u16) },
397 [OVS_TUNNEL_KEY_ATTR_TP_DST] = { .len = sizeof(u16) },
398 [OVS_TUNNEL_KEY_ATTR_OAM] = { .len = 0 },
399 [OVS_TUNNEL_KEY_ATTR_GENEVE_OPTS] = { .len = OVS_ATTR_VARIABLE },
400 [OVS_TUNNEL_KEY_ATTR_VXLAN_OPTS] = { .len = OVS_ATTR_NESTED,
401 .next = ovs_vxlan_ext_key_lens },
402 [OVS_TUNNEL_KEY_ATTR_IPV6_SRC] = { .len = sizeof(struct in6_addr) },
403 [OVS_TUNNEL_KEY_ATTR_IPV6_DST] = { .len = sizeof(struct in6_addr) },
404 [OVS_TUNNEL_KEY_ATTR_ERSPAN_OPTS] = { .len = sizeof(u32) },
374};
375
405};
406
407static const struct ovs_len_tbl
408ovs_nsh_key_attr_lens[OVS_NSH_KEY_ATTR_MAX + 1] = {
409 [OVS_NSH_KEY_ATTR_BASE] = { .len = sizeof(struct ovs_nsh_key_base) },
410 [OVS_NSH_KEY_ATTR_MD1] = { .len = sizeof(struct ovs_nsh_key_md1) },
411 [OVS_NSH_KEY_ATTR_MD2] = { .len = OVS_ATTR_VARIABLE },
412};
413
376/* The size of the argument for each %OVS_KEY_ATTR_* Netlink attribute. */
377static const struct ovs_len_tbl ovs_key_lens[OVS_KEY_ATTR_MAX + 1] = {
378 [OVS_KEY_ATTR_ENCAP] = { .len = OVS_ATTR_NESTED },
379 [OVS_KEY_ATTR_PRIORITY] = { .len = sizeof(u32) },
380 [OVS_KEY_ATTR_IN_PORT] = { .len = sizeof(u32) },
381 [OVS_KEY_ATTR_SKB_MARK] = { .len = sizeof(u32) },
382 [OVS_KEY_ATTR_ETHERNET] = { .len = sizeof(struct ovs_key_ethernet) },
383 [OVS_KEY_ATTR_VLAN] = { .len = sizeof(__be16) },

--- 16 unchanged lines hidden (view full) ---

400 [OVS_KEY_ATTR_CT_STATE] = { .len = sizeof(u32) },
401 [OVS_KEY_ATTR_CT_ZONE] = { .len = sizeof(u16) },
402 [OVS_KEY_ATTR_CT_MARK] = { .len = sizeof(u32) },
403 [OVS_KEY_ATTR_CT_LABELS] = { .len = sizeof(struct ovs_key_ct_labels) },
404 [OVS_KEY_ATTR_CT_ORIG_TUPLE_IPV4] = {
405 .len = sizeof(struct ovs_key_ct_tuple_ipv4) },
406 [OVS_KEY_ATTR_CT_ORIG_TUPLE_IPV6] = {
407 .len = sizeof(struct ovs_key_ct_tuple_ipv6) },
414/* The size of the argument for each %OVS_KEY_ATTR_* Netlink attribute. */
415static const struct ovs_len_tbl ovs_key_lens[OVS_KEY_ATTR_MAX + 1] = {
416 [OVS_KEY_ATTR_ENCAP] = { .len = OVS_ATTR_NESTED },
417 [OVS_KEY_ATTR_PRIORITY] = { .len = sizeof(u32) },
418 [OVS_KEY_ATTR_IN_PORT] = { .len = sizeof(u32) },
419 [OVS_KEY_ATTR_SKB_MARK] = { .len = sizeof(u32) },
420 [OVS_KEY_ATTR_ETHERNET] = { .len = sizeof(struct ovs_key_ethernet) },
421 [OVS_KEY_ATTR_VLAN] = { .len = sizeof(__be16) },

--- 16 unchanged lines hidden (view full) ---

438 [OVS_KEY_ATTR_CT_STATE] = { .len = sizeof(u32) },
439 [OVS_KEY_ATTR_CT_ZONE] = { .len = sizeof(u16) },
440 [OVS_KEY_ATTR_CT_MARK] = { .len = sizeof(u32) },
441 [OVS_KEY_ATTR_CT_LABELS] = { .len = sizeof(struct ovs_key_ct_labels) },
442 [OVS_KEY_ATTR_CT_ORIG_TUPLE_IPV4] = {
443 .len = sizeof(struct ovs_key_ct_tuple_ipv4) },
444 [OVS_KEY_ATTR_CT_ORIG_TUPLE_IPV6] = {
445 .len = sizeof(struct ovs_key_ct_tuple_ipv6) },
446 [OVS_KEY_ATTR_NSH] = { .len = OVS_ATTR_NESTED,
447 .next = ovs_nsh_key_attr_lens, },
408};
409
410static bool check_attr_len(unsigned int attr_len, unsigned int expected_len)
411{
412 return expected_len == attr_len ||
413 expected_len == OVS_ATTR_NESTED ||
414 expected_len == OVS_ATTR_VARIABLE;
415}

--- 172 unchanged lines hidden (view full) ---

588 SW_FLOW_KEY_PUT(match, tun_opts_len, 0xff, true);
589
590 opt_key_offset = TUN_METADATA_OFFSET(sizeof(opts));
591 SW_FLOW_KEY_MEMCPY_OFFSET(match, opt_key_offset, &opts, sizeof(opts),
592 is_mask);
593 return 0;
594}
595
448};
449
450static bool check_attr_len(unsigned int attr_len, unsigned int expected_len)
451{
452 return expected_len == attr_len ||
453 expected_len == OVS_ATTR_NESTED ||
454 expected_len == OVS_ATTR_VARIABLE;
455}

--- 172 unchanged lines hidden (view full) ---

628 SW_FLOW_KEY_PUT(match, tun_opts_len, 0xff, true);
629
630 opt_key_offset = TUN_METADATA_OFFSET(sizeof(opts));
631 SW_FLOW_KEY_MEMCPY_OFFSET(match, opt_key_offset, &opts, sizeof(opts),
632 is_mask);
633 return 0;
634}
635
636static int erspan_tun_opt_from_nlattr(const struct nlattr *attr,
637 struct sw_flow_match *match, bool is_mask,
638 bool log)
639{
640 unsigned long opt_key_offset;
641 struct erspan_metadata opts;
642
643 BUILD_BUG_ON(sizeof(opts) > sizeof(match->key->tun_opts));
644
645 memset(&opts, 0, sizeof(opts));
646 opts.index = nla_get_be32(attr);
647
648 /* Index has only 20-bit */
649 if (ntohl(opts.index) & ~INDEX_MASK) {
650 OVS_NLERR(log, "ERSPAN index number %x too large.",
651 ntohl(opts.index));
652 return -EINVAL;
653 }
654
655 SW_FLOW_KEY_PUT(match, tun_opts_len, sizeof(opts), is_mask);
656 opt_key_offset = TUN_METADATA_OFFSET(sizeof(opts));
657 SW_FLOW_KEY_MEMCPY_OFFSET(match, opt_key_offset, &opts, sizeof(opts),
658 is_mask);
659
660 return 0;
661}
662
596static int ip_tun_from_nlattr(const struct nlattr *attr,
597 struct sw_flow_match *match, bool is_mask,
598 bool log)
599{
600 bool ttl = false, ipv4 = false, ipv6 = false;
601 __be16 tun_flags = 0;
602 int opts_type = 0;
603 struct nlattr *a;

--- 91 unchanged lines hidden (view full) ---

695 if (err)
696 return err;
697
698 tun_flags |= TUNNEL_VXLAN_OPT;
699 opts_type = type;
700 break;
701 case OVS_TUNNEL_KEY_ATTR_PAD:
702 break;
663static int ip_tun_from_nlattr(const struct nlattr *attr,
664 struct sw_flow_match *match, bool is_mask,
665 bool log)
666{
667 bool ttl = false, ipv4 = false, ipv6 = false;
668 __be16 tun_flags = 0;
669 int opts_type = 0;
670 struct nlattr *a;

--- 91 unchanged lines hidden (view full) ---

762 if (err)
763 return err;
764
765 tun_flags |= TUNNEL_VXLAN_OPT;
766 opts_type = type;
767 break;
768 case OVS_TUNNEL_KEY_ATTR_PAD:
769 break;
770 case OVS_TUNNEL_KEY_ATTR_ERSPAN_OPTS:
771 if (opts_type) {
772 OVS_NLERR(log, "Multiple metadata blocks provided");
773 return -EINVAL;
774 }
775
776 err = erspan_tun_opt_from_nlattr(a, match, is_mask, log);
777 if (err)
778 return err;
779
780 tun_flags |= TUNNEL_ERSPAN_OPT;
781 opts_type = type;
782 break;
703 default:
704 OVS_NLERR(log, "Unknown IP tunnel attribute %d",
705 type);
706 return -EINVAL;
707 }
708 }
709
710 SW_FLOW_KEY_PUT(match, tun_key.tun_flags, tun_flags, is_mask);

--- 108 unchanged lines hidden (view full) ---

819 if (swkey_tun_opts_len) {
820 if (output->tun_flags & TUNNEL_GENEVE_OPT &&
821 nla_put(skb, OVS_TUNNEL_KEY_ATTR_GENEVE_OPTS,
822 swkey_tun_opts_len, tun_opts))
823 return -EMSGSIZE;
824 else if (output->tun_flags & TUNNEL_VXLAN_OPT &&
825 vxlan_opt_to_nlattr(skb, tun_opts, swkey_tun_opts_len))
826 return -EMSGSIZE;
783 default:
784 OVS_NLERR(log, "Unknown IP tunnel attribute %d",
785 type);
786 return -EINVAL;
787 }
788 }
789
790 SW_FLOW_KEY_PUT(match, tun_key.tun_flags, tun_flags, is_mask);

--- 108 unchanged lines hidden (view full) ---

899 if (swkey_tun_opts_len) {
900 if (output->tun_flags & TUNNEL_GENEVE_OPT &&
901 nla_put(skb, OVS_TUNNEL_KEY_ATTR_GENEVE_OPTS,
902 swkey_tun_opts_len, tun_opts))
903 return -EMSGSIZE;
904 else if (output->tun_flags & TUNNEL_VXLAN_OPT &&
905 vxlan_opt_to_nlattr(skb, tun_opts, swkey_tun_opts_len))
906 return -EMSGSIZE;
907 else if (output->tun_flags & TUNNEL_ERSPAN_OPT &&
908 nla_put_be32(skb, OVS_TUNNEL_KEY_ATTR_ERSPAN_OPTS,
909 ((struct erspan_metadata *)tun_opts)->index))
910 return -EMSGSIZE;
827 }
828
829 return 0;
830}
831
832static int ip_tun_to_nlattr(struct sk_buff *skb,
833 const struct ip_tunnel_key *output,
834 const void *tun_opts, int swkey_tun_opts_len,

--- 339 unchanged lines hidden (view full) ---

1174
1175 if (mac_proto == MAC_PROTO_NONE)
1176 return parse_eth_type_from_nlattrs(match, attrs, a, is_mask,
1177 log);
1178
1179 return 0;
1180}
1181
911 }
912
913 return 0;
914}
915
916static int ip_tun_to_nlattr(struct sk_buff *skb,
917 const struct ip_tunnel_key *output,
918 const void *tun_opts, int swkey_tun_opts_len,

--- 339 unchanged lines hidden (view full) ---

1258
1259 if (mac_proto == MAC_PROTO_NONE)
1260 return parse_eth_type_from_nlattrs(match, attrs, a, is_mask,
1261 log);
1262
1263 return 0;
1264}
1265
1266int nsh_hdr_from_nlattr(const struct nlattr *attr,
1267 struct nshhdr *nh, size_t size)
1268{
1269 struct nlattr *a;
1270 int rem;
1271 u8 flags = 0;
1272 u8 ttl = 0;
1273 int mdlen = 0;
1274
1275 /* validate_nsh has check this, so we needn't do duplicate check here
1276 */
1277 if (size < NSH_BASE_HDR_LEN)
1278 return -ENOBUFS;
1279
1280 nla_for_each_nested(a, attr, rem) {
1281 int type = nla_type(a);
1282
1283 switch (type) {
1284 case OVS_NSH_KEY_ATTR_BASE: {
1285 const struct ovs_nsh_key_base *base = nla_data(a);
1286
1287 flags = base->flags;
1288 ttl = base->ttl;
1289 nh->np = base->np;
1290 nh->mdtype = base->mdtype;
1291 nh->path_hdr = base->path_hdr;
1292 break;
1293 }
1294 case OVS_NSH_KEY_ATTR_MD1:
1295 mdlen = nla_len(a);
1296 if (mdlen > size - NSH_BASE_HDR_LEN)
1297 return -ENOBUFS;
1298 memcpy(&nh->md1, nla_data(a), mdlen);
1299 break;
1300
1301 case OVS_NSH_KEY_ATTR_MD2:
1302 mdlen = nla_len(a);
1303 if (mdlen > size - NSH_BASE_HDR_LEN)
1304 return -ENOBUFS;
1305 memcpy(&nh->md2, nla_data(a), mdlen);
1306 break;
1307
1308 default:
1309 return -EINVAL;
1310 }
1311 }
1312
1313 /* nsh header length = NSH_BASE_HDR_LEN + mdlen */
1314 nh->ver_flags_ttl_len = 0;
1315 nsh_set_flags_ttl_len(nh, flags, ttl, NSH_BASE_HDR_LEN + mdlen);
1316
1317 return 0;
1318}
1319
1320int nsh_key_from_nlattr(const struct nlattr *attr,
1321 struct ovs_key_nsh *nsh, struct ovs_key_nsh *nsh_mask)
1322{
1323 struct nlattr *a;
1324 int rem;
1325
1326 /* validate_nsh has check this, so we needn't do duplicate check here
1327 */
1328 nla_for_each_nested(a, attr, rem) {
1329 int type = nla_type(a);
1330
1331 switch (type) {
1332 case OVS_NSH_KEY_ATTR_BASE: {
1333 const struct ovs_nsh_key_base *base = nla_data(a);
1334 const struct ovs_nsh_key_base *base_mask = base + 1;
1335
1336 nsh->base = *base;
1337 nsh_mask->base = *base_mask;
1338 break;
1339 }
1340 case OVS_NSH_KEY_ATTR_MD1: {
1341 const struct ovs_nsh_key_md1 *md1 = nla_data(a);
1342 const struct ovs_nsh_key_md1 *md1_mask = md1 + 1;
1343
1344 memcpy(nsh->context, md1->context, sizeof(*md1));
1345 memcpy(nsh_mask->context, md1_mask->context,
1346 sizeof(*md1_mask));
1347 break;
1348 }
1349 case OVS_NSH_KEY_ATTR_MD2:
1350 /* Not supported yet */
1351 return -ENOTSUPP;
1352 default:
1353 return -EINVAL;
1354 }
1355 }
1356
1357 return 0;
1358}
1359
1360static int nsh_key_put_from_nlattr(const struct nlattr *attr,
1361 struct sw_flow_match *match, bool is_mask,
1362 bool is_push_nsh, bool log)
1363{
1364 struct nlattr *a;
1365 int rem;
1366 bool has_base = false;
1367 bool has_md1 = false;
1368 bool has_md2 = false;
1369 u8 mdtype = 0;
1370 int mdlen = 0;
1371
1372 if (WARN_ON(is_push_nsh && is_mask))
1373 return -EINVAL;
1374
1375 nla_for_each_nested(a, attr, rem) {
1376 int type = nla_type(a);
1377 int i;
1378
1379 if (type > OVS_NSH_KEY_ATTR_MAX) {
1380 OVS_NLERR(log, "nsh attr %d is out of range max %d",
1381 type, OVS_NSH_KEY_ATTR_MAX);
1382 return -EINVAL;
1383 }
1384
1385 if (!check_attr_len(nla_len(a),
1386 ovs_nsh_key_attr_lens[type].len)) {
1387 OVS_NLERR(
1388 log,
1389 "nsh attr %d has unexpected len %d expected %d",
1390 type,
1391 nla_len(a),
1392 ovs_nsh_key_attr_lens[type].len
1393 );
1394 return -EINVAL;
1395 }
1396
1397 switch (type) {
1398 case OVS_NSH_KEY_ATTR_BASE: {
1399 const struct ovs_nsh_key_base *base = nla_data(a);
1400
1401 has_base = true;
1402 mdtype = base->mdtype;
1403 SW_FLOW_KEY_PUT(match, nsh.base.flags,
1404 base->flags, is_mask);
1405 SW_FLOW_KEY_PUT(match, nsh.base.ttl,
1406 base->ttl, is_mask);
1407 SW_FLOW_KEY_PUT(match, nsh.base.mdtype,
1408 base->mdtype, is_mask);
1409 SW_FLOW_KEY_PUT(match, nsh.base.np,
1410 base->np, is_mask);
1411 SW_FLOW_KEY_PUT(match, nsh.base.path_hdr,
1412 base->path_hdr, is_mask);
1413 break;
1414 }
1415 case OVS_NSH_KEY_ATTR_MD1: {
1416 const struct ovs_nsh_key_md1 *md1 = nla_data(a);
1417
1418 has_md1 = true;
1419 for (i = 0; i < NSH_MD1_CONTEXT_SIZE; i++)
1420 SW_FLOW_KEY_PUT(match, nsh.context[i],
1421 md1->context[i], is_mask);
1422 break;
1423 }
1424 case OVS_NSH_KEY_ATTR_MD2:
1425 if (!is_push_nsh) /* Not supported MD type 2 yet */
1426 return -ENOTSUPP;
1427
1428 has_md2 = true;
1429 mdlen = nla_len(a);
1430 if (mdlen > NSH_CTX_HDRS_MAX_LEN || mdlen <= 0) {
1431 OVS_NLERR(
1432 log,
1433 "Invalid MD length %d for MD type %d",
1434 mdlen,
1435 mdtype
1436 );
1437 return -EINVAL;
1438 }
1439 break;
1440 default:
1441 OVS_NLERR(log, "Unknown nsh attribute %d",
1442 type);
1443 return -EINVAL;
1444 }
1445 }
1446
1447 if (rem > 0) {
1448 OVS_NLERR(log, "nsh attribute has %d unknown bytes.", rem);
1449 return -EINVAL;
1450 }
1451
1452 if (has_md1 && has_md2) {
1453 OVS_NLERR(
1454 1,
1455 "invalid nsh attribute: md1 and md2 are exclusive."
1456 );
1457 return -EINVAL;
1458 }
1459
1460 if (!is_mask) {
1461 if ((has_md1 && mdtype != NSH_M_TYPE1) ||
1462 (has_md2 && mdtype != NSH_M_TYPE2)) {
1463 OVS_NLERR(1, "nsh attribute has unmatched MD type %d.",
1464 mdtype);
1465 return -EINVAL;
1466 }
1467
1468 if (is_push_nsh &&
1469 (!has_base || (!has_md1 && !has_md2))) {
1470 OVS_NLERR(
1471 1,
1472 "push_nsh: missing base or metadata attributes"
1473 );
1474 return -EINVAL;
1475 }
1476 }
1477
1478 return 0;
1479}
1480
1182static int ovs_key_from_nlattrs(struct net *net, struct sw_flow_match *match,
1183 u64 attrs, const struct nlattr **a,
1184 bool is_mask, bool log)
1185{
1186 int err;
1187
1188 err = metadata_from_nlattrs(net, match, &attrs, a, is_mask, log);
1189 if (err)

--- 111 unchanged lines hidden (view full) ---

1301 SW_FLOW_KEY_MEMCPY(match, ipv4.arp.sha,
1302 arp_key->arp_sha, ETH_ALEN, is_mask);
1303 SW_FLOW_KEY_MEMCPY(match, ipv4.arp.tha,
1304 arp_key->arp_tha, ETH_ALEN, is_mask);
1305
1306 attrs &= ~(1 << OVS_KEY_ATTR_ARP);
1307 }
1308
1481static int ovs_key_from_nlattrs(struct net *net, struct sw_flow_match *match,
1482 u64 attrs, const struct nlattr **a,
1483 bool is_mask, bool log)
1484{
1485 int err;
1486
1487 err = metadata_from_nlattrs(net, match, &attrs, a, is_mask, log);
1488 if (err)

--- 111 unchanged lines hidden (view full) ---

1600 SW_FLOW_KEY_MEMCPY(match, ipv4.arp.sha,
1601 arp_key->arp_sha, ETH_ALEN, is_mask);
1602 SW_FLOW_KEY_MEMCPY(match, ipv4.arp.tha,
1603 arp_key->arp_tha, ETH_ALEN, is_mask);
1604
1605 attrs &= ~(1 << OVS_KEY_ATTR_ARP);
1606 }
1607
1608 if (attrs & (1 << OVS_KEY_ATTR_NSH)) {
1609 if (nsh_key_put_from_nlattr(a[OVS_KEY_ATTR_NSH], match,
1610 is_mask, false, log) < 0)
1611 return -EINVAL;
1612 attrs &= ~(1 << OVS_KEY_ATTR_NSH);
1613 }
1614
1309 if (attrs & (1 << OVS_KEY_ATTR_MPLS)) {
1310 const struct ovs_key_mpls *mpls_key;
1311
1312 mpls_key = nla_data(a[OVS_KEY_ATTR_MPLS]);
1313 SW_FLOW_KEY_PUT(match, mpls.top_lse,
1314 mpls_key->mpls_lse, is_mask);
1315
1316 attrs &= ~(1 << OVS_KEY_ATTR_MPLS);

--- 300 unchanged lines hidden (view full) ---

1617 __be16 eth_type = !is_mask ? vh->tpid : htons(0xffff);
1618
1619 if (nla_put_be16(skb, OVS_KEY_ATTR_ETHERTYPE, eth_type) ||
1620 nla_put_be16(skb, OVS_KEY_ATTR_VLAN, vh->tci))
1621 return -EMSGSIZE;
1622 return 0;
1623}
1624
1615 if (attrs & (1 << OVS_KEY_ATTR_MPLS)) {
1616 const struct ovs_key_mpls *mpls_key;
1617
1618 mpls_key = nla_data(a[OVS_KEY_ATTR_MPLS]);
1619 SW_FLOW_KEY_PUT(match, mpls.top_lse,
1620 mpls_key->mpls_lse, is_mask);
1621
1622 attrs &= ~(1 << OVS_KEY_ATTR_MPLS);

--- 300 unchanged lines hidden (view full) ---

1923 __be16 eth_type = !is_mask ? vh->tpid : htons(0xffff);
1924
1925 if (nla_put_be16(skb, OVS_KEY_ATTR_ETHERTYPE, eth_type) ||
1926 nla_put_be16(skb, OVS_KEY_ATTR_VLAN, vh->tci))
1927 return -EMSGSIZE;
1928 return 0;
1929}
1930
1931static int nsh_key_to_nlattr(const struct ovs_key_nsh *nsh, bool is_mask,
1932 struct sk_buff *skb)
1933{
1934 struct nlattr *start;
1935
1936 start = nla_nest_start(skb, OVS_KEY_ATTR_NSH);
1937 if (!start)
1938 return -EMSGSIZE;
1939
1940 if (nla_put(skb, OVS_NSH_KEY_ATTR_BASE, sizeof(nsh->base), &nsh->base))
1941 goto nla_put_failure;
1942
1943 if (is_mask || nsh->base.mdtype == NSH_M_TYPE1) {
1944 if (nla_put(skb, OVS_NSH_KEY_ATTR_MD1,
1945 sizeof(nsh->context), nsh->context))
1946 goto nla_put_failure;
1947 }
1948
1949 /* Don't support MD type 2 yet */
1950
1951 nla_nest_end(skb, start);
1952
1953 return 0;
1954
1955nla_put_failure:
1956 return -EMSGSIZE;
1957}
1958
1625static int __ovs_nla_put_key(const struct sw_flow_key *swkey,
1626 const struct sw_flow_key *output, bool is_mask,
1627 struct sk_buff *skb)
1628{
1629 struct ovs_key_ethernet *eth_key;
1630 struct nlattr *nla;
1631 struct nlattr *encap = NULL;
1632 struct nlattr *in_encap = NULL;

--- 112 unchanged lines hidden (view full) ---

1745 sizeof(ipv6_key->ipv6_src));
1746 memcpy(ipv6_key->ipv6_dst, &output->ipv6.addr.dst,
1747 sizeof(ipv6_key->ipv6_dst));
1748 ipv6_key->ipv6_label = output->ipv6.label;
1749 ipv6_key->ipv6_proto = output->ip.proto;
1750 ipv6_key->ipv6_tclass = output->ip.tos;
1751 ipv6_key->ipv6_hlimit = output->ip.ttl;
1752 ipv6_key->ipv6_frag = output->ip.frag;
1959static int __ovs_nla_put_key(const struct sw_flow_key *swkey,
1960 const struct sw_flow_key *output, bool is_mask,
1961 struct sk_buff *skb)
1962{
1963 struct ovs_key_ethernet *eth_key;
1964 struct nlattr *nla;
1965 struct nlattr *encap = NULL;
1966 struct nlattr *in_encap = NULL;

--- 112 unchanged lines hidden (view full) ---

2079 sizeof(ipv6_key->ipv6_src));
2080 memcpy(ipv6_key->ipv6_dst, &output->ipv6.addr.dst,
2081 sizeof(ipv6_key->ipv6_dst));
2082 ipv6_key->ipv6_label = output->ipv6.label;
2083 ipv6_key->ipv6_proto = output->ip.proto;
2084 ipv6_key->ipv6_tclass = output->ip.tos;
2085 ipv6_key->ipv6_hlimit = output->ip.ttl;
2086 ipv6_key->ipv6_frag = output->ip.frag;
2087 } else if (swkey->eth.type == htons(ETH_P_NSH)) {
2088 if (nsh_key_to_nlattr(&output->nsh, is_mask, skb))
2089 goto nla_put_failure;
1753 } else if (swkey->eth.type == htons(ETH_P_ARP) ||
1754 swkey->eth.type == htons(ETH_P_RARP)) {
1755 struct ovs_key_arp *arp_key;
1756
1757 nla = nla_reserve(skb, OVS_KEY_ATTR_ARP, sizeof(*arp_key));
1758 if (!nla)
1759 goto nla_put_failure;
1760 arp_key = nla_data(nla);

--- 429 unchanged lines hidden (view full) ---

2190 switch (opts_type) {
2191 case OVS_TUNNEL_KEY_ATTR_GENEVE_OPTS:
2192 err = validate_geneve_opts(&key);
2193 if (err < 0)
2194 return err;
2195 break;
2196 case OVS_TUNNEL_KEY_ATTR_VXLAN_OPTS:
2197 break;
2090 } else if (swkey->eth.type == htons(ETH_P_ARP) ||
2091 swkey->eth.type == htons(ETH_P_RARP)) {
2092 struct ovs_key_arp *arp_key;
2093
2094 nla = nla_reserve(skb, OVS_KEY_ATTR_ARP, sizeof(*arp_key));
2095 if (!nla)
2096 goto nla_put_failure;
2097 arp_key = nla_data(nla);

--- 429 unchanged lines hidden (view full) ---

2527 switch (opts_type) {
2528 case OVS_TUNNEL_KEY_ATTR_GENEVE_OPTS:
2529 err = validate_geneve_opts(&key);
2530 if (err < 0)
2531 return err;
2532 break;
2533 case OVS_TUNNEL_KEY_ATTR_VXLAN_OPTS:
2534 break;
2535 case OVS_TUNNEL_KEY_ATTR_ERSPAN_OPTS:
2536 break;
2198 }
2199 };
2200
2201 start = add_nested_action_start(sfa, OVS_ACTION_ATTR_SET, log);
2202 if (start < 0)
2203 return start;
2204
2205 tun_dst = metadata_dst_alloc(key.tun_opts_len, METADATA_IP_TUNNEL,

--- 31 unchanged lines hidden (view full) ---

2237 ip_tunnel_info_opts_set(tun_info,
2238 TUN_METADATA_OPTS(&key, key.tun_opts_len),
2239 key.tun_opts_len);
2240 add_nested_action_end(*sfa, start);
2241
2242 return err;
2243}
2244
2537 }
2538 };
2539
2540 start = add_nested_action_start(sfa, OVS_ACTION_ATTR_SET, log);
2541 if (start < 0)
2542 return start;
2543
2544 tun_dst = metadata_dst_alloc(key.tun_opts_len, METADATA_IP_TUNNEL,

--- 31 unchanged lines hidden (view full) ---

2576 ip_tunnel_info_opts_set(tun_info,
2577 TUN_METADATA_OPTS(&key, key.tun_opts_len),
2578 key.tun_opts_len);
2579 add_nested_action_end(*sfa, start);
2580
2581 return err;
2582}
2583
2584static bool validate_nsh(const struct nlattr *attr, bool is_mask,
2585 bool is_push_nsh, bool log)
2586{
2587 struct sw_flow_match match;
2588 struct sw_flow_key key;
2589 int ret = 0;
2590
2591 ovs_match_init(&match, &key, true, NULL);
2592 ret = nsh_key_put_from_nlattr(attr, &match, is_mask,
2593 is_push_nsh, log);
2594 return !ret;
2595}
2596
2245/* Return false if there are any non-masked bits set.
2246 * Mask follows data immediately, before any netlink padding.
2247 */
2248static bool validate_masked(u8 *data, int len)
2249{
2250 u8 *mask = data + len;
2251
2252 while (len--)

--- 126 unchanged lines hidden (view full) ---

2379 case OVS_KEY_ATTR_SCTP:
2380 if ((eth_type != htons(ETH_P_IP) &&
2381 eth_type != htons(ETH_P_IPV6)) ||
2382 flow_key->ip.proto != IPPROTO_SCTP)
2383 return -EINVAL;
2384
2385 break;
2386
2597/* Return false if there are any non-masked bits set.
2598 * Mask follows data immediately, before any netlink padding.
2599 */
2600static bool validate_masked(u8 *data, int len)
2601{
2602 u8 *mask = data + len;
2603
2604 while (len--)

--- 126 unchanged lines hidden (view full) ---

2731 case OVS_KEY_ATTR_SCTP:
2732 if ((eth_type != htons(ETH_P_IP) &&
2733 eth_type != htons(ETH_P_IPV6)) ||
2734 flow_key->ip.proto != IPPROTO_SCTP)
2735 return -EINVAL;
2736
2737 break;
2738
2739 case OVS_KEY_ATTR_NSH:
2740 if (eth_type != htons(ETH_P_NSH))
2741 return -EINVAL;
2742 if (!validate_nsh(nla_data(a), masked, false, log))
2743 return -EINVAL;
2744 break;
2745
2387 default:
2388 return -EINVAL;
2389 }
2390
2391 /* Convert non-masked non-tunnel set actions to masked set actions. */
2392 if (!masked && key_type != OVS_KEY_ATTR_TUNNEL) {
2393 int start, len = key_len * 2;
2394 struct nlattr *at;

--- 79 unchanged lines hidden (view full) ---

2474 [OVS_ACTION_ATTR_POP_MPLS] = sizeof(__be16),
2475 [OVS_ACTION_ATTR_PUSH_VLAN] = sizeof(struct ovs_action_push_vlan),
2476 [OVS_ACTION_ATTR_POP_VLAN] = 0,
2477 [OVS_ACTION_ATTR_SET] = (u32)-1,
2478 [OVS_ACTION_ATTR_SET_MASKED] = (u32)-1,
2479 [OVS_ACTION_ATTR_SAMPLE] = (u32)-1,
2480 [OVS_ACTION_ATTR_HASH] = sizeof(struct ovs_action_hash),
2481 [OVS_ACTION_ATTR_CT] = (u32)-1,
2746 default:
2747 return -EINVAL;
2748 }
2749
2750 /* Convert non-masked non-tunnel set actions to masked set actions. */
2751 if (!masked && key_type != OVS_KEY_ATTR_TUNNEL) {
2752 int start, len = key_len * 2;
2753 struct nlattr *at;

--- 79 unchanged lines hidden (view full) ---

2833 [OVS_ACTION_ATTR_POP_MPLS] = sizeof(__be16),
2834 [OVS_ACTION_ATTR_PUSH_VLAN] = sizeof(struct ovs_action_push_vlan),
2835 [OVS_ACTION_ATTR_POP_VLAN] = 0,
2836 [OVS_ACTION_ATTR_SET] = (u32)-1,
2837 [OVS_ACTION_ATTR_SET_MASKED] = (u32)-1,
2838 [OVS_ACTION_ATTR_SAMPLE] = (u32)-1,
2839 [OVS_ACTION_ATTR_HASH] = sizeof(struct ovs_action_hash),
2840 [OVS_ACTION_ATTR_CT] = (u32)-1,
2841 [OVS_ACTION_ATTR_CT_CLEAR] = 0,
2482 [OVS_ACTION_ATTR_TRUNC] = sizeof(struct ovs_action_trunc),
2483 [OVS_ACTION_ATTR_PUSH_ETH] = sizeof(struct ovs_action_push_eth),
2484 [OVS_ACTION_ATTR_POP_ETH] = 0,
2842 [OVS_ACTION_ATTR_TRUNC] = sizeof(struct ovs_action_trunc),
2843 [OVS_ACTION_ATTR_PUSH_ETH] = sizeof(struct ovs_action_push_eth),
2844 [OVS_ACTION_ATTR_POP_ETH] = 0,
2845 [OVS_ACTION_ATTR_PUSH_NSH] = (u32)-1,
2846 [OVS_ACTION_ATTR_POP_NSH] = 0,
2485 };
2486 const struct ovs_action_push_vlan *vlan;
2487 int type = nla_type(a);
2488 bool skip_copy;
2489
2490 if (type > OVS_ACTION_ATTR_MAX ||
2491 (action_lens[type] != nla_len(a) &&
2492 action_lens[type] != (u32)-1))

--- 122 unchanged lines hidden (view full) ---

2615
2616 case OVS_ACTION_ATTR_CT:
2617 err = ovs_ct_copy_action(net, a, key, sfa, log);
2618 if (err)
2619 return err;
2620 skip_copy = true;
2621 break;
2622
2847 };
2848 const struct ovs_action_push_vlan *vlan;
2849 int type = nla_type(a);
2850 bool skip_copy;
2851
2852 if (type > OVS_ACTION_ATTR_MAX ||
2853 (action_lens[type] != nla_len(a) &&
2854 action_lens[type] != (u32)-1))

--- 122 unchanged lines hidden (view full) ---

2977
2978 case OVS_ACTION_ATTR_CT:
2979 err = ovs_ct_copy_action(net, a, key, sfa, log);
2980 if (err)
2981 return err;
2982 skip_copy = true;
2983 break;
2984
2985 case OVS_ACTION_ATTR_CT_CLEAR:
2986 break;
2987
2623 case OVS_ACTION_ATTR_PUSH_ETH:
2624 /* Disallow pushing an Ethernet header if one
2625 * is already present */
2626 if (mac_proto != MAC_PROTO_NONE)
2627 return -EINVAL;
2628 mac_proto = MAC_PROTO_NONE;
2629 break;
2630
2631 case OVS_ACTION_ATTR_POP_ETH:
2632 if (mac_proto != MAC_PROTO_ETHERNET)
2633 return -EINVAL;
2634 if (vlan_tci & htons(VLAN_TAG_PRESENT))
2635 return -EINVAL;
2636 mac_proto = MAC_PROTO_ETHERNET;
2637 break;
2638
2988 case OVS_ACTION_ATTR_PUSH_ETH:
2989 /* Disallow pushing an Ethernet header if one
2990 * is already present */
2991 if (mac_proto != MAC_PROTO_NONE)
2992 return -EINVAL;
2993 mac_proto = MAC_PROTO_NONE;
2994 break;
2995
2996 case OVS_ACTION_ATTR_POP_ETH:
2997 if (mac_proto != MAC_PROTO_ETHERNET)
2998 return -EINVAL;
2999 if (vlan_tci & htons(VLAN_TAG_PRESENT))
3000 return -EINVAL;
3001 mac_proto = MAC_PROTO_ETHERNET;
3002 break;
3003
3004 case OVS_ACTION_ATTR_PUSH_NSH:
3005 if (mac_proto != MAC_PROTO_ETHERNET) {
3006 u8 next_proto;
3007
3008 next_proto = tun_p_from_eth_p(eth_type);
3009 if (!next_proto)
3010 return -EINVAL;
3011 }
3012 mac_proto = MAC_PROTO_NONE;
3013 if (!validate_nsh(nla_data(a), false, true, true))
3014 return -EINVAL;
3015 break;
3016
3017 case OVS_ACTION_ATTR_POP_NSH: {
3018 __be16 inner_proto;
3019
3020 if (eth_type != htons(ETH_P_NSH))
3021 return -EINVAL;
3022 inner_proto = tun_p_to_eth_p(key->nsh.base.np);
3023 if (!inner_proto)
3024 return -EINVAL;
3025 if (key->nsh.base.np == TUN_P_ETHERNET)
3026 mac_proto = MAC_PROTO_ETHERNET;
3027 else
3028 mac_proto = MAC_PROTO_NONE;
3029 break;
3030 }
3031
2639 default:
2640 OVS_NLERR(log, "Unknown Action type %d", type);
2641 return -EINVAL;
2642 }
2643 if (!skip_copy) {
2644 err = copy_action(a, sfa, log);
2645 if (err)
2646 return err;

--- 167 unchanged lines hidden ---
3032 default:
3033 OVS_NLERR(log, "Unknown Action type %d", type);
3034 return -EINVAL;
3035 }
3036 if (!skip_copy) {
3037 err = copy_action(a, sfa, log);
3038 if (err)
3039 return err;

--- 167 unchanged lines hidden ---