History

Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next

Pull networking updates from David Miller: "Highlights: 1) Support more Realtek wireless chips, from Jes Sorenson. 2) New BPF types for per-cpu hash and arrap maps, from Alexei Starovoitov. 3) Make several TCP sysctls per-namespace, from Nikolay Borisov. 4) Allow the use of SO_REUSEPORT in order to do per-thread processing of incoming TCP/UDP connections. The muxing can be done using a BPF program which hashes the incoming packet. From Craig Gallek. 5) Add a multiplexer for TCP streams, to provide a messaged based interface. BPF programs can be used to determine the message boundaries. From Tom Herbert. 6) Add 802.1AE MACSEC support, from Sabrina Dubroca. 7) Avoid factorial complexity when taking down an inetdev interface with lots of configured addresses. We were doing things like traversing the entire address less for each address removed, and flushing the entire netfilter conntrack table for every address as well. 8) Add and use SKB bulk free infrastructure, from Jesper Brouer. 9) Allow offloading u32 classifiers to hardware, and implement for ixgbe, from John Fastabend. 10) Allow configuring IRQ coalescing parameters on a per-queue basis, from Kan Liang. 11) Extend ethtool so that larger link mode masks can be supported. From David Decotigny. 12) Introduce devlink, which can be used to configure port link types (ethernet vs Infiniband, etc.), port splitting, and switch device level attributes as a whole. From Jiri Pirko. 13) Hardware offload support for flower classifiers, from Amir Vadai. 14) Add "Local Checksum Offload". Basically, for a tunneled packet the checksum of the outer header is 'constant' (because with the checksum field filled into the inner protocol header, the payload of the outer frame checksums to 'zero'), and we can take advantage of that in various ways. From Edward Cree" * git://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next: (1548 commits) bonding: fix bond_get_stats() net: bcmgenet: fix dma api length mismatch net/mlx4_core: Fix backward compatibility on VFs phy: mdio-thunder: Fix some Kconfig typos lan78xx: add ndo_get_stats64 lan78xx: handle statistics counter rollover RDS: TCP: Remove unused constant RDS: TCP: Add sysctl tunables for sndbuf/rcvbuf on rds-tcp socket net: smc911x: convert pxa dma to dmaengine team: remove duplicate set of flag IFF_MULTICAST bonding: remove duplicate set of flag IFF_MULTICAST net: fix a comment typo ethernet: micrel: fix some error codes ip_tunnels, bpf: define IP_TUNNEL_OPTS_MAX and use it bpf, dst: add and use dst_tclassid helper bpf: make skb->tc_classid also readable net: mvneta: bm: clarify dependencies cls_bpf: reset class and reuse major in da ldmvsw: Checkpatch sunvnet.c and sunvnet_common.c ldmvsw: Add ldmvsw.c driver code ...

Linus Torvalds committed 10 years ago

Commit 1200b682 parents 6b5f04b fe309371281 files · +79030 −34010Browse files

Showing the changes to net/openvswitch (11 of 1281 files). Show all

Unified · Split

11 files
  1. net/openvswitch/Kconfig +3 −1
  2. net/openvswitch/actions.c +3 −5
  3. net/openvswitch/conntrack.c +622 −38
  4. net/openvswitch/conntrack.h +2 −1
  5. net/openvswitch/datapath.c +75 −33
  6. net/openvswitch/datapath.h +4 −0
  7. net/openvswitch/flow.h +1 −1
  8. net/openvswitch/flow_netlink.c +6 −3
  9. net/openvswitch/vport-internal_dev.c +9 −1
  10. net/openvswitch/vport-netdev.c +1 −1
  11. net/openvswitch/vport.h +0 −7
net/openvswitch/Kconfig+3−1
@@ -6,10 +6,12 @@ config OPENVSWITCH · 5 unmodified lines
66 tristate "Open vSwitch"
77 depends on INET
88 depends on !NF_CONNTRACK || \
9− (NF_CONNTRACK && (!NF_DEFRAG_IPV6 || NF_DEFRAG_IPV6))
9+ (NF_CONNTRACK && ((!NF_DEFRAG_IPV6 || NF_DEFRAG_IPV6) && \
10+ (!NF_NAT || NF_NAT)))
1011 select LIBCRC32C
1112 select MPLS
1213 select NET_MPLS_GSO
14+ select DST_CACHE
1315 ---help---
1416 Open vSwitch is a multilayer Ethernet switch targeted at virtualized
1517 environments. In addition to supporting a variety of features
net/openvswitch/actions.c+3−5
@@ -158,9 +158,7 @@ static int push_mpls(struct sk_buff *skb, struct sw_flow_key *key, · 157 unmodified lines
158158 new_mpls_lse = (__be32 *)skb_mpls_header(skb);
159159 *new_mpls_lse = mpls->mpls_lse;
160160
161− if (skb->ip_summed == CHECKSUM_COMPLETE)
162− skb->csum = csum_add(skb->csum, csum_partial(new_mpls_lse,
163− MPLS_HLEN, 0));
161+ skb_postpush_rcsum(skb, new_mpls_lse, MPLS_HLEN);
164162
165163 hdr = eth_hdr(skb);
166164 hdr->h_proto = mpls->mpls_ethertype;
@@ -280,7 +278,7 @@ static int set_eth_addr(struct sk_buff *skb, struct sw_flow_key *flow_key, · 113 unmodified lines
280278 ether_addr_copy_masked(eth_hdr(skb)->h_dest, key->eth_dst,
281279 mask->eth_dst);
282280
283− ovs_skb_postpush_rcsum(skb, eth_hdr(skb), ETH_ALEN * 2);
281+ skb_postpush_rcsum(skb, eth_hdr(skb), ETH_ALEN * 2);
284282
285283 ether_addr_copy(flow_key->eth.src, eth_hdr(skb)->h_source);
286284 ether_addr_copy(flow_key->eth.dst, eth_hdr(skb)->h_dest);
@@ -639,7 +637,7 @@ static int ovs_vport_output(struct net *net, struct sock *sk, struct sk_buff *sk · 352 unmodified lines
639637 /* Reconstruct the MAC header. */
640638 skb_push(skb, data->l2_len);
641639 memcpy(skb->data, &data->l2_data, data->l2_len);
642− ovs_skb_postpush_rcsum(skb, skb->data, data->l2_len);
640+ skb_postpush_rcsum(skb, skb->data, data->l2_len);
643641 skb_reset_mac_header(skb);
644642
645643 ovs_vport_send(vport, skb);
net/openvswitch/conntrack.c+622−38
@@ -13,21 +13,31 @@ · 12 unmodified lines
1313
1414 #include <linux/module.h>
1515 #include <linux/openvswitch.h>
16+#include <linux/tcp.h>
17+#include <linux/udp.h>
18+#include <linux/sctp.h>
1619 #include <net/ip.h>
1720 #include <net/netfilter/nf_conntrack_core.h>
1821 #include <net/netfilter/nf_conntrack_helper.h>
1922 #include <net/netfilter/nf_conntrack_labels.h>
23+#include <net/netfilter/nf_conntrack_seqadj.h>
2024 #include <net/netfilter/nf_conntrack_zones.h>
2125 #include <net/netfilter/ipv6/nf_defrag_ipv6.h>
2226
27+#ifdef CONFIG_NF_NAT_NEEDED
28+#include <linux/netfilter/nf_nat.h>
29+#include <net/netfilter/nf_nat_core.h>
30+#include <net/netfilter/nf_nat_l3proto.h>
31+#endif
32+
2333 #include "datapath.h"
2434 #include "conntrack.h"
2535 #include "flow.h"
2636 #include "flow_netlink.h"
2737
2838 struct ovs_ct_len_tbl {
29− size_t maxlen;
30− size_t minlen;
39+ int maxlen;
40+ int minlen;
3141 };
3242
3343 /* Metadata mark for masked write to conntrack mark */
@@ -42,15 +52,25 @@ struct md_labels { · 8 unmodified lines
4252 struct ovs_key_ct_labels mask;
4353 };
4454
55+enum ovs_ct_nat {
56+ OVS_CT_NAT = 1 << 0, /* NAT for committed connections only. */
57+ OVS_CT_SRC_NAT = 1 << 1, /* Source NAT for NEW connections. */
58+ OVS_CT_DST_NAT = 1 << 2, /* Destination NAT for NEW connections. */
59+};
60+
4561 /* Conntrack action context for execution. */
4662 struct ovs_conntrack_info {
4763 struct nf_conntrack_helper *helper;
4864 struct nf_conntrack_zone zone;
4965 struct nf_conn *ct;
5066 u8 commit : 1;
67+ u8 nat : 3; /* enum ovs_ct_nat */
5168 u16 family;
5269 struct md_mark mark;
5370 struct md_labels labels;
71+#ifdef CONFIG_NF_NAT_NEEDED
72+ struct nf_nat_range range; /* Only present for SRC NAT and DST NAT. */
73+#endif
5474 };
5575
5676 static void __ovs_ct_free_action(struct ovs_conntrack_info *ct_info);
@@ -75,7 +95,6 @@ static u8 ovs_ct_get_state(enum ip_conntrack_info ctinfo) · 18 unmodified lines
7595 switch (ctinfo) {
7696 case IP_CT_ESTABLISHED_REPLY:
7797 case IP_CT_RELATED_REPLY:
78− case IP_CT_NEW_REPLY:
7998 ct_state |= OVS_CS_F_REPLY_DIR;
8099 break;
81100 default:
@@ -92,7 +111,6 @@ static u8 ovs_ct_get_state(enum ip_conntrack_info ctinfo) · 10 unmodified lines
92111 ct_state |= OVS_CS_F_RELATED;
93112 break;
94113 case IP_CT_NEW:
95− case IP_CT_NEW_REPLY:
96114 ct_state |= OVS_CS_F_NEW;
97115 break;
98116 default:
@@ -139,12 +157,15 @@ static void __ovs_ct_update_key(struct sw_flow_key *key, u8 state, · 40 unmodified lines
139157 ovs_ct_get_labels(ct, &key->ct.labels);
140158 }
141159
142−/* Update 'key' based on skb->nfct. If 'post_ct' is true, then OVS has
143− * previously sent the packet to conntrack via the ct action.
160+/* Update 'key' based on skb->nfct. If 'post_ct' is true, then OVS has
161+ * previously sent the packet to conntrack via the ct action. If
162+ * 'keep_nat_flags' is true, the existing NAT flags retained, else they are
163+ * initialized from the connection status.
144164 */
145165 static void ovs_ct_update_key(const struct sk_buff *skb,
146166 const struct ovs_conntrack_info *info,
147− struct sw_flow_key *key, bool post_ct)
167+ struct sw_flow_key *key, bool post_ct,
168+ bool keep_nat_flags)
148169 {
149170 const struct nf_conntrack_zone *zone = &nf_ct_zone_dflt;
150171 enum ip_conntrack_info ctinfo;
@@ -154,10 +175,22 @@ static void ovs_ct_update_key(const struct sk_buff *skb, · 3 unmodified lines
154175 ct = nf_ct_get(skb, &ctinfo);
155176 if (ct) {
156177 state = ovs_ct_get_state(ctinfo);
178+ /* All unconfirmed entries are NEW connections. */
157179 if (!nf_ct_is_confirmed(ct))
158180 state |= OVS_CS_F_NEW;
181+ /* OVS persists the related flag for the duration of the
182+ * connection.
183+ */
159184 if (ct->master)
160185 state |= OVS_CS_F_RELATED;
186+ if (keep_nat_flags) {
187+ state |= key->ct.state & OVS_CS_F_NAT_MASK;
188+ } else {
189+ if (ct->status & IPS_SRC_NAT)
190+ state |= OVS_CS_F_SRC_NAT;
191+ if (ct->status & IPS_DST_NAT)
192+ state |= OVS_CS_F_DST_NAT;
193+ }
161194 zone = nf_ct_zone(ct);
162195 } else if (post_ct) {
163196 state = OVS_CS_F_TRACKED | OVS_CS_F_INVALID;
@@ -167,9 +200,12 @@ static void ovs_ct_update_key(const struct sk_buff *skb, · 3 unmodified lines
167200 __ovs_ct_update_key(key, state, zone, ct);
168201 }
169202
203+/* This is called to initialize CT key fields possibly coming in from the local
204+ * stack.
205+ */
170206 void ovs_ct_fill_key(const struct sk_buff *skb, struct sw_flow_key *key)
171207 {
172− ovs_ct_update_key(skb, NULL, key, false);
208+ ovs_ct_update_key(skb, NULL, key, false, false);
173209 }
174210
175211 int ovs_ct_put_key(const struct sw_flow_key *key, struct sk_buff *skb)
@@ -201,7 +237,6 @@ static int ovs_ct_set_mark(struct sk_buff *skb, struct sw_flow_key *key, · 25 unmodified lines
201237 struct nf_conn *ct;
202238 u32 new_mark;
203239
204−
205240 /* The connection could be invalid, in which case set_mark is no-op. */
206241 ct = nf_ct_get(skb, &ctinfo);
207242 if (!ct)
@@ -259,6 +294,7 @@ static int ovs_ct_helper(struct sk_buff *skb, u16 proto) · 51 unmodified lines
259294 enum ip_conntrack_info ctinfo;
260295 unsigned int protoff;
261296 struct nf_conn *ct;
297+ int err;
262298
263299 ct = nf_ct_get(skb, &ctinfo);
264300 if (!ct || ctinfo == IP_CT_RELATED_REPLY)
@@ -295,7 +331,18 @@ static int ovs_ct_helper(struct sk_buff *skb, u16 proto) · 30 unmodified lines
295331 return NF_DROP;
296332 }
297333
298− return helper->help(skb, protoff, ct, ctinfo);
334+ err = helper->help(skb, protoff, ct, ctinfo);
335+ if (err != NF_ACCEPT)
336+ return err;
337+
338+ /* Adjust seqs after helper. This is needed due to some helpers (e.g.,
339+ * FTP with NAT) adusting the TCP payload size when mangling IP
340+ * addresses and/or port numbers in the text-based control connection.
341+ */
342+ if (test_bit(IPS_SEQ_ADJUST_BIT, &ct->status) &&
343+ !nf_ct_seq_adjust(skb, ct, ctinfo, protoff))
344+ return NF_DROP;
345+ return NF_ACCEPT;
299346 }
300347
301348 /* Returns 0 on success, -EINPROGRESS if 'skb' is stolen, or other nonzero
@@ -352,14 +399,101 @@ ovs_ct_expect_find(struct net *net, const struct nf_conntrack_zone *zone, · 50 unmodified lines
352399 return __nf_ct_expect_find(net, zone, &tuple);
353400 }
354401
402+/* This replicates logic from nf_conntrack_core.c that is not exported. */
403+static enum ip_conntrack_info
404+ovs_ct_get_info(const struct nf_conntrack_tuple_hash *h)
405+{
406+ const struct nf_conn *ct = nf_ct_tuplehash_to_ctrack(h);
407+
408+ if (NF_CT_DIRECTION(h) == IP_CT_DIR_REPLY)
409+ return IP_CT_ESTABLISHED_REPLY;
410+ /* Once we've had two way comms, always ESTABLISHED. */
411+ if (test_bit(IPS_SEEN_REPLY_BIT, &ct->status))
412+ return IP_CT_ESTABLISHED;
413+ if (test_bit(IPS_EXPECTED_BIT, &ct->status))
414+ return IP_CT_RELATED;
415+ return IP_CT_NEW;
416+}
417+
418+/* Find an existing connection which this packet belongs to without
419+ * re-attributing statistics or modifying the connection state. This allows an
420+ * skb->nfct lost due to an upcall to be recovered during actions execution.
421+ *
422+ * Must be called with rcu_read_lock.
423+ *
424+ * On success, populates skb->nfct and skb->nfctinfo, and returns the
425+ * connection. Returns NULL if there is no existing entry.
426+ */
427+static struct nf_conn *
428+ovs_ct_find_existing(struct net *net, const struct nf_conntrack_zone *zone,
429+ u8 l3num, struct sk_buff *skb)
430+{
431+ struct nf_conntrack_l3proto *l3proto;
432+ struct nf_conntrack_l4proto *l4proto;
433+ struct nf_conntrack_tuple tuple;
434+ struct nf_conntrack_tuple_hash *h;
435+ enum ip_conntrack_info ctinfo;
436+ struct nf_conn *ct;
437+ unsigned int dataoff;
438+ u8 protonum;
439+
440+ l3proto = __nf_ct_l3proto_find(l3num);
441+ if (!l3proto) {
442+ pr_debug("ovs_ct_find_existing: Can't get l3proto\n");
443+ return NULL;
444+ }
445+ if (l3proto->get_l4proto(skb, skb_network_offset(skb), &dataoff,
446+ &protonum) <= 0) {
447+ pr_debug("ovs_ct_find_existing: Can't get protonum\n");
448+ return NULL;
449+ }
450+ l4proto = __nf_ct_l4proto_find(l3num, protonum);
451+ if (!l4proto) {
452+ pr_debug("ovs_ct_find_existing: Can't get l4proto\n");
453+ return NULL;
454+ }
455+ if (!nf_ct_get_tuple(skb, skb_network_offset(skb), dataoff, l3num,
456+ protonum, net, &tuple, l3proto, l4proto)) {
457+ pr_debug("ovs_ct_find_existing: Can't get tuple\n");
458+ return NULL;
459+ }
460+
461+ /* look for tuple match */
462+ h = nf_conntrack_find_get(net, zone, &tuple);
463+ if (!h)
464+ return NULL; /* Not found. */
465+
466+ ct = nf_ct_tuplehash_to_ctrack(h);
467+
468+ ctinfo = ovs_ct_get_info(h);
469+ if (ctinfo == IP_CT_NEW) {
470+ /* This should not happen. */
471+ WARN_ONCE(1, "ovs_ct_find_existing: new packet for %p\n", ct);
472+ }
473+ skb->nfct = &ct->ct_general;
474+ skb->nfctinfo = ctinfo;
475+ return ct;
476+}
477+
355478 /* Determine whether skb->nfct is equal to the result of conntrack lookup. */
356−static bool skb_nfct_cached(const struct net *net, const struct sk_buff *skb,
357− const struct ovs_conntrack_info *info)
479+static bool skb_nfct_cached(struct net *net,
480+ const struct sw_flow_key *key,
481+ const struct ovs_conntrack_info *info,
482+ struct sk_buff *skb)
358483 {
359484 enum ip_conntrack_info ctinfo;
360485 struct nf_conn *ct;
361486
362487 ct = nf_ct_get(skb, &ctinfo);
488+ /* If no ct, check if we have evidence that an existing conntrack entry
489+ * might be found for this skb. This happens when we lose a skb->nfct
490+ * due to an upcall. If the connection was not confirmed, it is not
491+ * cached and needs to be run through conntrack again.
492+ */
493+ if (!ct && key->ct.state & OVS_CS_F_TRACKED &&
494+ !(key->ct.state & OVS_CS_F_INVALID) &&
495+ key->ct.zone == info->zone.id)
496+ ct = ovs_ct_find_existing(net, &info->zone, info->family, skb);
363497 if (!ct)
364498 return false;
365499 if (!net_eq(net, read_pnet(&ct->ct_net)))
@@ -377,6 +511,206 @@ static bool skb_nfct_cached(const struct net *net, const struct sk_buff *skb, · 11 unmodified lines
377511 return true;
378512 }
379513
514+#ifdef CONFIG_NF_NAT_NEEDED
515+/* Modelled after nf_nat_ipv[46]_fn().
516+ * range is only used for new, uninitialized NAT state.
517+ * Returns either NF_ACCEPT or NF_DROP.
518+ */
519+static int ovs_ct_nat_execute(struct sk_buff *skb, struct nf_conn *ct,
520+ enum ip_conntrack_info ctinfo,
521+ const struct nf_nat_range *range,
522+ enum nf_nat_manip_type maniptype)
523+{
524+ int hooknum, nh_off, err = NF_ACCEPT;
525+
526+ nh_off = skb_network_offset(skb);
527+ skb_pull(skb, nh_off);
528+
529+ /* See HOOK2MANIP(). */
530+ if (maniptype == NF_NAT_MANIP_SRC)
531+ hooknum = NF_INET_LOCAL_IN; /* Source NAT */
532+ else
533+ hooknum = NF_INET_LOCAL_OUT; /* Destination NAT */
534+
535+ switch (ctinfo) {
536+ case IP_CT_RELATED:
537+ case IP_CT_RELATED_REPLY:
538+ if (skb->protocol == htons(ETH_P_IP) &&
539+ ip_hdr(skb)->protocol == IPPROTO_ICMP) {
540+ if (!nf_nat_icmp_reply_translation(skb, ct, ctinfo,
541+ hooknum))
542+ err = NF_DROP;
543+ goto push;
544+#if IS_ENABLED(CONFIG_NF_NAT_IPV6)
545+ } else if (skb->protocol == htons(ETH_P_IPV6)) {
546+ __be16 frag_off;
547+ u8 nexthdr = ipv6_hdr(skb)->nexthdr;
548+ int hdrlen = ipv6_skip_exthdr(skb,
549+ sizeof(struct ipv6hdr),
550+ &nexthdr, &frag_off);
551+
552+ if (hdrlen >= 0 && nexthdr == IPPROTO_ICMPV6) {
553+ if (!nf_nat_icmpv6_reply_translation(skb, ct,
554+ ctinfo,
555+ hooknum,
556+ hdrlen))
557+ err = NF_DROP;
558+ goto push;
559+ }
560+#endif
561+ }
562+ /* Non-ICMP, fall thru to initialize if needed. */
563+ case IP_CT_NEW:
564+ /* Seen it before? This can happen for loopback, retrans,
565+ * or local packets.
566+ */
567+ if (!nf_nat_initialized(ct, maniptype)) {
568+ /* Initialize according to the NAT action. */
569+ err = (range && range->flags & NF_NAT_RANGE_MAP_IPS)
570+ /* Action is set up to establish a new
571+ * mapping.
572+ */
573+ ? nf_nat_setup_info(ct, range, maniptype)
574+ : nf_nat_alloc_null_binding(ct, hooknum);
575+ if (err != NF_ACCEPT)
576+ goto push;
577+ }
578+ break;
579+
580+ case IP_CT_ESTABLISHED:
581+ case IP_CT_ESTABLISHED_REPLY:
582+ break;
583+
584+ default:
585+ err = NF_DROP;
586+ goto push;
587+ }
588+
589+ err = nf_nat_packet(ct, ctinfo, hooknum, skb);
590+push:
591+ skb_push(skb, nh_off);
592+
593+ return err;
594+}
595+
596+static void ovs_nat_update_key(struct sw_flow_key *key,
597+ const struct sk_buff *skb,
598+ enum nf_nat_manip_type maniptype)
599+{
600+ if (maniptype == NF_NAT_MANIP_SRC) {
601+ __be16 src;
602+
603+ key->ct.state |= OVS_CS_F_SRC_NAT;
604+ if (key->eth.type == htons(ETH_P_IP))
605+ key->ipv4.addr.src = ip_hdr(skb)->saddr;
606+ else if (key->eth.type == htons(ETH_P_IPV6))
607+ memcpy(&key->ipv6.addr.src, &ipv6_hdr(skb)->saddr,
608+ sizeof(key->ipv6.addr.src));
609+ else
610+ return;
611+
612+ if (key->ip.proto == IPPROTO_UDP)
613+ src = udp_hdr(skb)->source;
614+ else if (key->ip.proto == IPPROTO_TCP)
615+ src = tcp_hdr(skb)->source;
616+ else if (key->ip.proto == IPPROTO_SCTP)
617+ src = sctp_hdr(skb)->source;
618+ else
619+ return;
620+
621+ key->tp.src = src;
622+ } else {
623+ __be16 dst;
624+
625+ key->ct.state |= OVS_CS_F_DST_NAT;
626+ if (key->eth.type == htons(ETH_P_IP))
627+ key->ipv4.addr.dst = ip_hdr(skb)->daddr;
628+ else if (key->eth.type == htons(ETH_P_IPV6))
629+ memcpy(&key->ipv6.addr.dst, &ipv6_hdr(skb)->daddr,
630+ sizeof(key->ipv6.addr.dst));
631+ else
632+ return;
633+
634+ if (key->ip.proto == IPPROTO_UDP)
635+ dst = udp_hdr(skb)->dest;
636+ else if (key->ip.proto == IPPROTO_TCP)
637+ dst = tcp_hdr(skb)->dest;
638+ else if (key->ip.proto == IPPROTO_SCTP)
639+ dst = sctp_hdr(skb)->dest;
640+ else
641+ return;
642+
643+ key->tp.dst = dst;
644+ }
645+}
646+
647+/* Returns NF_DROP if the packet should be dropped, NF_ACCEPT otherwise. */
648+static int ovs_ct_nat(struct net *net, struct sw_flow_key *key,
649+ const struct ovs_conntrack_info *info,
650+ struct sk_buff *skb, struct nf_conn *ct,
651+ enum ip_conntrack_info ctinfo)
652+{
653+ enum nf_nat_manip_type maniptype;
654+ int err;
655+
656+ if (nf_ct_is_untracked(ct)) {
657+ /* A NAT action may only be performed on tracked packets. */
658+ return NF_ACCEPT;
659+ }
660+
661+ /* Add NAT extension if not confirmed yet. */
662+ if (!nf_ct_is_confirmed(ct) && !nf_ct_nat_ext_add(ct))
663+ return NF_ACCEPT; /* Can't NAT. */
664+
665+ /* Determine NAT type.
666+ * Check if the NAT type can be deduced from the tracked connection.
667+ * Make sure expected traffic is NATted only when committing.
668+ */
669+ if (info->nat & OVS_CT_NAT && ctinfo != IP_CT_NEW &&
670+ ct->status & IPS_NAT_MASK &&
671+ (!(ct->status & IPS_EXPECTED_BIT) || info->commit)) {
672+ /* NAT an established or related connection like before. */
673+ if (CTINFO2DIR(ctinfo) == IP_CT_DIR_REPLY)
674+ /* This is the REPLY direction for a connection
675+ * for which NAT was applied in the forward
676+ * direction. Do the reverse NAT.
677+ */
678+ maniptype = ct->status & IPS_SRC_NAT
679+ ? NF_NAT_MANIP_DST : NF_NAT_MANIP_SRC;
680+ else
681+ maniptype = ct->status & IPS_SRC_NAT
682+ ? NF_NAT_MANIP_SRC : NF_NAT_MANIP_DST;
683+ } else if (info->nat & OVS_CT_SRC_NAT) {
684+ maniptype = NF_NAT_MANIP_SRC;
685+ } else if (info->nat & OVS_CT_DST_NAT) {
686+ maniptype = NF_NAT_MANIP_DST;
687+ } else {
688+ return NF_ACCEPT; /* Connection is not NATed. */
689+ }
690+ err = ovs_ct_nat_execute(skb, ct, ctinfo, &info->range, maniptype);
691+
692+ /* Mark NAT done if successful and update the flow key. */
693+ if (err == NF_ACCEPT)
694+ ovs_nat_update_key(key, skb, maniptype);
695+
696+ return err;
697+}
698+#else /* !CONFIG_NF_NAT_NEEDED */
699+static int ovs_ct_nat(struct net *net, struct sw_flow_key *key,
700+ const struct ovs_conntrack_info *info,
701+ struct sk_buff *skb, struct nf_conn *ct,
702+ enum ip_conntrack_info ctinfo)
703+{
704+ return NF_ACCEPT;
705+}
706+#endif
707+
708+/* Pass 'skb' through conntrack in 'net', using zone configured in 'info', if
709+ * not done already. Update key with new CT state after passing the packet
710+ * through conntrack.
711+ * Note that if the packet is deemed invalid by conntrack, skb->nfct will be
712+ * set to NULL and 0 will be returned.
713+ */
380714 static int __ovs_ct_lookup(struct net *net, struct sw_flow_key *key,
381715 const struct ovs_conntrack_info *info,
382716 struct sk_buff *skb)
@@ -386,8 +720,13 @@ static int __ovs_ct_lookup(struct net *net, struct sw_flow_key *key, · 3 unmodified lines
386720 * actually run the packet through conntrack twice unless it's for a
387721 * different zone.
388722 */
389− if (!skb_nfct_cached(net, skb, info)) {
723+ bool cached = skb_nfct_cached(net, key, info, skb);
724+ enum ip_conntrack_info ctinfo;
725+ struct nf_conn *ct;
726+
727+ if (!cached) {
390728 struct nf_conn *tmpl = info->ct;
729+ int err;
391730
392731 /* Associate skb with specified zone. */
393732 if (tmpl) {
@@ -398,17 +737,53 @@ static int __ovs_ct_lookup(struct net *net, struct sw_flow_key *key, · 4 unmodified lines
398737 skb->nfctinfo = IP_CT_NEW;
399738 }
400739
401− if (nf_conntrack_in(net, info->family, NF_INET_PRE_ROUTING,
402− skb) != NF_ACCEPT)
740+ /* Repeat if requested, see nf_iterate(). */
741+ do {
742+ err = nf_conntrack_in(net, info->family,
743+ NF_INET_PRE_ROUTING, skb);
744+ } while (err == NF_REPEAT);
745+
746+ if (err != NF_ACCEPT)
403747 return -ENOENT;
404748
405− if (ovs_ct_helper(skb, info->family) != NF_ACCEPT) {
406− WARN_ONCE(1, "helper rejected packet");
749+ /* Clear CT state NAT flags to mark that we have not yet done
750+ * NAT after the nf_conntrack_in() call. We can actually clear
751+ * the whole state, as it will be re-initialized below.
752+ */
753+ key->ct.state = 0;
754+
755+ /* Update the key, but keep the NAT flags. */
756+ ovs_ct_update_key(skb, info, key, true, true);
757+ }
758+
759+ ct = nf_ct_get(skb, &ctinfo);
760+ if (ct) {
761+ /* Packets starting a new connection must be NATted before the
762+ * helper, so that the helper knows about the NAT. We enforce
763+ * this by delaying both NAT and helper calls for unconfirmed
764+ * connections until the committing CT action. For later
765+ * packets NAT and Helper may be called in either order.
766+ *
767+ * NAT will be done only if the CT action has NAT, and only
768+ * once per packet (per zone), as guarded by the NAT bits in
769+ * the key->ct.state.
770+ */
771+ if (info->nat && !(key->ct.state & OVS_CS_F_NAT_MASK) &&
772+ (nf_ct_is_confirmed(ct) || info->commit) &&
773+ ovs_ct_nat(net, key, info, skb, ct, ctinfo) != NF_ACCEPT) {
407774 return -EINVAL;
408775 }
409− }
410776
411− ovs_ct_update_key(skb, info, key, true);
777+ /* Call the helper only if:
778+ * - nf_conntrack_in() was executed above ("!cached") for a
779+ * confirmed connection, or
780+ * - When committing an unconfirmed connection.
781+ */
782+ if ((nf_ct_is_confirmed(ct) ? !cached : info->commit) &&
783+ ovs_ct_helper(skb, info->family) != NF_ACCEPT) {
784+ return -EINVAL;
785+ }
786+ }
412787
413788 return 0;
414789 }
@@ -420,19 +795,24 @@ static int ovs_ct_lookup(struct net *net, struct sw_flow_key *key, · 5 unmodified lines
420795 {
421796 struct nf_conntrack_expect *exp;
422797
798+ /* If we pass an expected packet through nf_conntrack_in() the
799+ * expectation is typically removed, but the packet could still be
800+ * lost in upcall processing. To prevent this from happening we
801+ * perform an explicit expectation lookup. Expected connections are
802+ * always new, and will be passed through conntrack only when they are
803+ * committed, as it is OK to remove the expectation at that time.
804+ */
423805 exp = ovs_ct_expect_find(net, &info->zone, info->family, skb);
424806 if (exp) {
425807 u8 state;
426808
809+ /* NOTE: New connections are NATted and Helped only when
810+ * committed, so we are not calling into NAT here.
811+ */
427812 state = OVS_CS_F_TRACKED | OVS_CS_F_NEW | OVS_CS_F_RELATED;
428813 __ovs_ct_update_key(key, state, &info->zone, exp->master);
429− } else {
430− int err;
431−
432− err = __ovs_ct_lookup(net, key, info, skb);
433− if (err)
434− return err;
435− }
814+ } else
815+ return __ovs_ct_lookup(net, key, info, skb);
436816
437817 return 0;
438818 }
@@ -442,21 +822,12 @@ static int ovs_ct_commit(struct net *net, struct sw_flow_key *key, · 3 unmodified lines
442822 const struct ovs_conntrack_info *info,
443823 struct sk_buff *skb)
444824 {
445− u8 state;
446825 int err;
447826
448− state = key->ct.state;
449− if (key->ct.zone == info->zone.id &&
450− ((state & OVS_CS_F_TRACKED) && !(state & OVS_CS_F_NEW))) {
451− /* Previous lookup has shown that this connection is already
452− * tracked and committed. Skip committing.
453− */
454− return 0;
455− }
456−
457827 err = __ovs_ct_lookup(net, key, info, skb);
458828 if (err)
459829 return err;
830+ /* This is a no-op if the connection has already been confirmed. */
460831 if (nf_conntrack_confirm(skb) != NF_ACCEPT)
461832 return -EINVAL;
462833
@@ -541,6 +912,135 @@ static int ovs_ct_add_helper(struct ovs_conntrack_info *info, const char *name, · 78 unmodified lines
541912 return 0;
542913 }
543914
915+#ifdef CONFIG_NF_NAT_NEEDED
916+static int parse_nat(const struct nlattr *attr,
917+ struct ovs_conntrack_info *info, bool log)
918+{
919+ struct nlattr *a;
920+ int rem;
921+ bool have_ip_max = false;
922+ bool have_proto_max = false;
923+ bool ip_vers = (info->family == NFPROTO_IPV6);
924+
925+ nla_for_each_nested(a, attr, rem) {
926+ static const int ovs_nat_attr_lens[OVS_NAT_ATTR_MAX + 1][2] = {
927+ [OVS_NAT_ATTR_SRC] = {0, 0},
928+ [OVS_NAT_ATTR_DST] = {0, 0},
929+ [OVS_NAT_ATTR_IP_MIN] = {sizeof(struct in_addr),
930+ sizeof(struct in6_addr)},
931+ [OVS_NAT_ATTR_IP_MAX] = {sizeof(struct in_addr),
932+ sizeof(struct in6_addr)},
933+ [OVS_NAT_ATTR_PROTO_MIN] = {sizeof(u16), sizeof(u16)},
934+ [OVS_NAT_ATTR_PROTO_MAX] = {sizeof(u16), sizeof(u16)},
935+ [OVS_NAT_ATTR_PERSISTENT] = {0, 0},
936+ [OVS_NAT_ATTR_PROTO_HASH] = {0, 0},
937+ [OVS_NAT_ATTR_PROTO_RANDOM] = {0, 0},
938+ };
939+ int type = nla_type(a);
940+
941+ if (type > OVS_NAT_ATTR_MAX) {
942+ OVS_NLERR(log,
943+ "Unknown NAT attribute (type=%d, max=%d).\n",
944+ type, OVS_NAT_ATTR_MAX);
945+ return -EINVAL;
946+ }
947+
948+ if (nla_len(a) != ovs_nat_attr_lens[type][ip_vers]) {
949+ OVS_NLERR(log,
950+ "NAT attribute type %d has unexpected length (%d != %d).\n",
951+ type, nla_len(a),
952+ ovs_nat_attr_lens[type][ip_vers]);
953+ return -EINVAL;
954+ }
955+
956+ switch (type) {
957+ case OVS_NAT_ATTR_SRC:
958+ case OVS_NAT_ATTR_DST:
959+ if (info->nat) {
960+ OVS_NLERR(log,
961+ "Only one type of NAT may be specified.\n"
962+ );
963+ return -ERANGE;
964+ }
965+ info->nat |= OVS_CT_NAT;
966+ info->nat |= ((type == OVS_NAT_ATTR_SRC)
967+ ? OVS_CT_SRC_NAT : OVS_CT_DST_NAT);
968+ break;
969+
970+ case OVS_NAT_ATTR_IP_MIN:
971+ nla_memcpy(&info->range.min_addr, a, nla_len(a));
972+ info->range.flags |= NF_NAT_RANGE_MAP_IPS;
973+ break;
974+
975+ case OVS_NAT_ATTR_IP_MAX:
976+ have_ip_max = true;
977+ nla_memcpy(&info->range.max_addr, a,
978+ sizeof(info->range.max_addr));
979+ info->range.flags |= NF_NAT_RANGE_MAP_IPS;
980+ break;
981+
982+ case OVS_NAT_ATTR_PROTO_MIN:
983+ info->range.min_proto.all = htons(nla_get_u16(a));
984+ info->range.flags |= NF_NAT_RANGE_PROTO_SPECIFIED;
985+ break;
986+
987+ case OVS_NAT_ATTR_PROTO_MAX:
988+ have_proto_max = true;
989+ info->range.max_proto.all = htons(nla_get_u16(a));
990+ info->range.flags |= NF_NAT_RANGE_PROTO_SPECIFIED;
991+ break;
992+
993+ case OVS_NAT_ATTR_PERSISTENT:
994+ info->range.flags |= NF_NAT_RANGE_PERSISTENT;
995+ break;
996+
997+ case OVS_NAT_ATTR_PROTO_HASH:
998+ info->range.flags |= NF_NAT_RANGE_PROTO_RANDOM;
999+ break;
1000+
1001+ case OVS_NAT_ATTR_PROTO_RANDOM:
1002+ info->range.flags |= NF_NAT_RANGE_PROTO_RANDOM_FULLY;
1003+ break;
1004+
1005+ default:
1006+ OVS_NLERR(log, "Unknown nat attribute (%d).\n", type);
1007+ return -EINVAL;
1008+ }
1009+ }
1010+
1011+ if (rem > 0) {
1012+ OVS_NLERR(log, "NAT attribute has %d unknown bytes.\n", rem);
1013+ return -EINVAL;
1014+ }
1015+ if (!info->nat) {
1016+ /* Do not allow flags if no type is given. */
1017+ if (info->range.flags) {
1018+ OVS_NLERR(log,
1019+ "NAT flags may be given only when NAT range (SRC or DST) is also specified.\n"
1020+ );
1021+ return -EINVAL;
1022+ }
1023+ info->nat = OVS_CT_NAT; /* NAT existing connections. */
1024+ } else if (!info->commit) {
1025+ OVS_NLERR(log,
1026+ "NAT attributes may be specified only when CT COMMIT flag is also specified.\n"
1027+ );
1028+ return -EINVAL;
1029+ }
1030+ /* Allow missing IP_MAX. */
1031+ if (info->range.flags & NF_NAT_RANGE_MAP_IPS && !have_ip_max) {
1032+ memcpy(&info->range.max_addr, &info->range.min_addr,
1033+ sizeof(info->range.max_addr));
1034+ }
1035+ /* Allow missing PROTO_MAX. */
1036+ if (info->range.flags & NF_NAT_RANGE_PROTO_SPECIFIED &&
1037+ !have_proto_max) {
1038+ info->range.max_proto.all = info->range.min_proto.all;
1039+ }
1040+ return 0;
1041+}
1042+#endif
1043+
5441044 static const struct ovs_ct_len_tbl ovs_ct_attr_lens[OVS_CT_ATTR_MAX + 1] = {
5451045 [OVS_CT_ATTR_COMMIT] = { .minlen = 0, .maxlen = 0 },
5461046 [OVS_CT_ATTR_ZONE] = { .minlen = sizeof(u16),
@@ -550,7 +1050,11 @@ static const struct ovs_ct_len_tbl ovs_ct_attr_lens[OVS_CT_ATTR_MAX + 1] = { · 3 unmodified lines
5501050 [OVS_CT_ATTR_LABELS] = { .minlen = sizeof(struct md_labels),
5511051 .maxlen = sizeof(struct md_labels) },
5521052 [OVS_CT_ATTR_HELPER] = { .minlen = 1,
553− .maxlen = NF_CT_HELPER_NAME_LEN }
1053+ .maxlen = NF_CT_HELPER_NAME_LEN },
1054+#ifdef CONFIG_NF_NAT_NEEDED
1055+ /* NAT length is checked when parsing the nested attributes. */
1056+ [OVS_CT_ATTR_NAT] = { .minlen = 0, .maxlen = INT_MAX },
1057+#endif
5541058 };
5551059
5561060 static int parse_ct(const struct nlattr *attr, struct ovs_conntrack_info *info,
@@ -617,6 +1121,15 @@ static int parse_ct(const struct nlattr *attr, struct ovs_conntrack_info *info, · 60 unmodified lines
6171121 return -EINVAL;
6181122 }
6191123 break;
1124+#ifdef CONFIG_NF_NAT_NEEDED
1125+ case OVS_CT_ATTR_NAT: {
1126+ int err = parse_nat(a, info, log);
1127+
1128+ if (err)
1129+ return err;
1130+ break;
1131+ }
1132+#endif
6201133 default:
6211134 OVS_NLERR(log, "Unknown conntrack attr (%d)",
6221135 type);
@@ -704,6 +1217,74 @@ err_free_ct: · 81 unmodified lines
7041217 return err;
7051218 }
7061219
1220+#ifdef CONFIG_NF_NAT_NEEDED
1221+static bool ovs_ct_nat_to_attr(const struct ovs_conntrack_info *info,
1222+ struct sk_buff *skb)
1223+{
1224+ struct nlattr *start;
1225+
1226+ start = nla_nest_start(skb, OVS_CT_ATTR_NAT);
1227+ if (!start)
1228+ return false;
1229+
1230+ if (info->nat & OVS_CT_SRC_NAT) {
1231+ if (nla_put_flag(skb, OVS_NAT_ATTR_SRC))
1232+ return false;
1233+ } else if (info->nat & OVS_CT_DST_NAT) {
1234+ if (nla_put_flag(skb, OVS_NAT_ATTR_DST))
1235+ return false;
1236+ } else {
1237+ goto out;
1238+ }
1239+
1240+ if (info->range.flags & NF_NAT_RANGE_MAP_IPS) {
1241+ if (info->family == NFPROTO_IPV4) {
1242+ if (nla_put_in_addr(skb, OVS_NAT_ATTR_IP_MIN,
1243+ info->range.min_addr.ip) ||
1244+ (info->range.max_addr.ip
1245+ != info->range.min_addr.ip &&
1246+ (nla_put_in_addr(skb, OVS_NAT_ATTR_IP_MAX,
1247+ info->range.max_addr.ip))))
1248+ return false;
1249+#if IS_ENABLED(CONFIG_NF_NAT_IPV6)
1250+ } else if (info->family == NFPROTO_IPV6) {
1251+ if (nla_put_in6_addr(skb, OVS_NAT_ATTR_IP_MIN,
1252+ &info->range.min_addr.in6) ||
1253+ (memcmp(&info->range.max_addr.in6,
1254+ &info->range.min_addr.in6,
1255+ sizeof(info->range.max_addr.in6)) &&
1256+ (nla_put_in6_addr(skb, OVS_NAT_ATTR_IP_MAX,
1257+ &info->range.max_addr.in6))))
1258+ return false;
1259+#endif
1260+ } else {
1261+ return false;
1262+ }
1263+ }
1264+ if (info->range.flags & NF_NAT_RANGE_PROTO_SPECIFIED &&
1265+ (nla_put_u16(skb, OVS_NAT_ATTR_PROTO_MIN,
1266+ ntohs(info->range.min_proto.all)) ||
1267+ (info->range.max_proto.all != info->range.min_proto.all &&
1268+ nla_put_u16(skb, OVS_NAT_ATTR_PROTO_MAX,
1269+ ntohs(info->range.max_proto.all)))))
1270+ return false;
1271+
1272+ if (info->range.flags & NF_NAT_RANGE_PERSISTENT &&
1273+ nla_put_flag(skb, OVS_NAT_ATTR_PERSISTENT))
1274+ return false;
1275+ if (info->range.flags & NF_NAT_RANGE_PROTO_RANDOM &&
1276+ nla_put_flag(skb, OVS_NAT_ATTR_PROTO_HASH))
1277+ return false;
1278+ if (info->range.flags & NF_NAT_RANGE_PROTO_RANDOM_FULLY &&
1279+ nla_put_flag(skb, OVS_NAT_ATTR_PROTO_RANDOM))
1280+ return false;
1281+out:
1282+ nla_nest_end(skb, start);
1283+
1284+ return true;
1285+}
1286+#endif
1287+
7071288 int ovs_ct_action_to_attr(const struct ovs_conntrack_info *ct_info,
7081289 struct sk_buff *skb)
7091290 {
@@ -732,7 +1313,10 @@ int ovs_ct_action_to_attr(const struct ovs_conntrack_info *ct_info, · 22 unmodified lines
7321313 ct_info->helper->name))
7331314 return -EMSGSIZE;
7341315 }
735−
1316+#ifdef CONFIG_NF_NAT_NEEDED
1317+ if (ct_info->nat && !ovs_ct_nat_to_attr(ct_info, skb))
1318+ return -EMSGSIZE;
1319+#endif
7361320 nla_nest_end(skb, start);
7371321
7381322 return 0;
net/openvswitch/conntrack.h+2−1
@@ -37,7 +37,8 @@ void ovs_ct_free_action(const struct nlattr *a); · 36 unmodified lines
3737
3838 #define CT_SUPPORTED_MASK (OVS_CS_F_NEW | OVS_CS_F_ESTABLISHED | \
3939 OVS_CS_F_RELATED | OVS_CS_F_REPLY_DIR | \
40− OVS_CS_F_INVALID | OVS_CS_F_TRACKED)
40+ OVS_CS_F_INVALID | OVS_CS_F_TRACKED | \
41+ OVS_CS_F_SRC_NAT | OVS_CS_F_DST_NAT)
4142 #else
4243 #include <linux/errno.h>
4344
net/openvswitch/datapath.c+75−33
@@ -422,10 +422,6 @@ static int queue_userspace_packet(struct datapath *dp, struct sk_buff *skb, · 421 unmodified lines
422422 struct sk_buff *nskb = NULL;
423423 struct sk_buff *user_skb = NULL; /* to be queued to userspace */
424424 struct nlattr *nla;
425− struct genl_info info = {
426− .dst_sk = ovs_dp_get_net(dp)->genl_sock,
427− .snd_portid = upcall_info->portid,
428− };
429425 size_t len;
430426 unsigned int hlen;
431427 int err, dp_ifindex;
@@ -466,7 +462,7 @@ static int queue_userspace_packet(struct datapath *dp, struct sk_buff *skb, · 34 unmodified lines
466462 hlen = skb->len;
467463
468464 len = upcall_msg_size(upcall_info, hlen);
469− user_skb = genlmsg_new_unicast(len, &info, GFP_ATOMIC);
465+ user_skb = genlmsg_new(len, GFP_ATOMIC);
470466 if (!user_skb) {
471467 err = -ENOMEM;
472468 goto out;
@@ -654,7 +650,7 @@ static const struct nla_policy packet_policy[OVS_PACKET_ATTR_MAX + 1] = { · 181 unmodified lines
654650
655651 static const struct genl_ops dp_packet_genl_ops[] = {
656652 { .cmd = OVS_PACKET_CMD_EXECUTE,
657− .flags = GENL_ADMIN_PERM, /* Requires CAP_NET_ADMIN privilege. */
653+ .flags = GENL_UNS_ADMIN_PERM, /* Requires CAP_NET_ADMIN privilege. */
658654 .policy = packet_policy,
659655 .doit = ovs_packet_cmd_execute
660656 }
@@ -876,7 +872,7 @@ static struct sk_buff *ovs_flow_cmd_alloc_info(const struct sw_flow_actions *act · 215 unmodified lines
876872 return NULL;
877873
878874 len = ovs_flow_cmd_msg_size(acts, sfid, ufid_flags);
879− skb = genlmsg_new_unicast(len, info, GFP_KERNEL);
875+ skb = genlmsg_new(len, GFP_KERNEL);
880876 if (!skb)
881877 return ERR_PTR(-ENOMEM);
882878
@@ -1100,26 +1096,32 @@ static int ovs_flow_cmd_set(struct sk_buff *skb, struct genl_info *info) · 217 unmodified lines
11001096 struct sw_flow_match match;
11011097 struct sw_flow_id sfid;
11021098 u32 ufid_flags = ovs_nla_get_ufid_flags(a[OVS_FLOW_ATTR_UFID_FLAGS]);
1103− int error;
1099+ int error = 0;
11041100 bool log = !a[OVS_FLOW_ATTR_PROBE];
11051101 bool ufid_present;
11061102
1107− /* Extract key. */
1108− error = -EINVAL;
1109− if (!a[OVS_FLOW_ATTR_KEY]) {
1110− OVS_NLERR(log, "Flow key attribute not present in set flow.");
1111− goto error;
1112− }
1113−
11141103 ufid_present = ovs_nla_get_ufid(&sfid, a[OVS_FLOW_ATTR_UFID], log);
1115− ovs_match_init(&match, &key, &mask);
1116− error = ovs_nla_get_match(net, &match, a[OVS_FLOW_ATTR_KEY],
1117− a[OVS_FLOW_ATTR_MASK], log);
1104+ if (a[OVS_FLOW_ATTR_KEY]) {
1105+ ovs_match_init(&match, &key, &mask);
1106+ error = ovs_nla_get_match(net, &match, a[OVS_FLOW_ATTR_KEY],
1107+ a[OVS_FLOW_ATTR_MASK], log);
1108+ } else if (!ufid_present) {
1109+ OVS_NLERR(log,
1110+ "Flow set message rejected, Key attribute missing.");
1111+ error = -EINVAL;
1112+ }
11181113 if (error)
11191114 goto error;
11201115
11211116 /* Validate actions. */
11221117 if (a[OVS_FLOW_ATTR_ACTIONS]) {
1118+ if (!a[OVS_FLOW_ATTR_KEY]) {
1119+ OVS_NLERR(log,
1120+ "Flow key attribute not present in set flow.");
1121+ error = -EINVAL;
1122+ goto error;
1123+ }
1124+
11231125 acts = get_flow_actions(net, a[OVS_FLOW_ATTR_ACTIONS], &key,
11241126 &mask, log);
11251127 if (IS_ERR(acts)) {
@@ -1391,12 +1393,12 @@ static const struct nla_policy flow_policy[OVS_FLOW_ATTR_MAX + 1] = { · 265 unmodified lines
13911393
13921394 static const struct genl_ops dp_flow_genl_ops[] = {
13931395 { .cmd = OVS_FLOW_CMD_NEW,
1394− .flags = GENL_ADMIN_PERM, /* Requires CAP_NET_ADMIN privilege. */
1396+ .flags = GENL_UNS_ADMIN_PERM, /* Requires CAP_NET_ADMIN privilege. */
13951397 .policy = flow_policy,
13961398 .doit = ovs_flow_cmd_new
13971399 },
13981400 { .cmd = OVS_FLOW_CMD_DEL,
1399− .flags = GENL_ADMIN_PERM, /* Requires CAP_NET_ADMIN privilege. */
1401+ .flags = GENL_UNS_ADMIN_PERM, /* Requires CAP_NET_ADMIN privilege. */
14001402 .policy = flow_policy,
14011403 .doit = ovs_flow_cmd_del
14021404 },
@@ -1407,7 +1409,7 @@ static const struct genl_ops dp_flow_genl_ops[] = { · 4 unmodified lines
14071409 .dumpit = ovs_flow_cmd_dump
14081410 },
14091411 { .cmd = OVS_FLOW_CMD_SET,
1410− .flags = GENL_ADMIN_PERM, /* Requires CAP_NET_ADMIN privilege. */
1412+ .flags = GENL_UNS_ADMIN_PERM, /* Requires CAP_NET_ADMIN privilege. */
14111413 .policy = flow_policy,
14121414 .doit = ovs_flow_cmd_set,
14131415 },
@@ -1481,9 +1483,9 @@ error: · 67 unmodified lines
14811483 return -EMSGSIZE;
14821484 }
14831485
1484−static struct sk_buff *ovs_dp_cmd_alloc_info(struct genl_info *info)
1486+static struct sk_buff *ovs_dp_cmd_alloc_info(void)
14851487 {
1486− return genlmsg_new_unicast(ovs_dp_cmd_msg_size(), info, GFP_KERNEL);
1488+ return genlmsg_new(ovs_dp_cmd_msg_size(), GFP_KERNEL);
14871489 }
14881490
14891491 /* Called with rcu_read_lock or ovs_mutex. */
@@ -1536,7 +1538,7 @@ static int ovs_dp_cmd_new(struct sk_buff *skb, struct genl_info *info) · 46 unmodified lines
15361538 if (!a[OVS_DP_ATTR_NAME] || !a[OVS_DP_ATTR_UPCALL_PID])
15371539 goto err;
15381540
1539− reply = ovs_dp_cmd_alloc_info(info);
1541+ reply = ovs_dp_cmd_alloc_info();
15401542 if (!reply)
15411543 return -ENOMEM;
15421544
@@ -1657,7 +1659,7 @@ static int ovs_dp_cmd_del(struct sk_buff *skb, struct genl_info *info) · 114 unmodified lines
16571659 struct datapath *dp;
16581660 int err;
16591661
1660− reply = ovs_dp_cmd_alloc_info(info);
1662+ reply = ovs_dp_cmd_alloc_info();
16611663 if (!reply)
16621664 return -ENOMEM;
16631665
@@ -1690,7 +1692,7 @@ static int ovs_dp_cmd_set(struct sk_buff *skb, struct genl_info *info) · 26 unmodified lines
16901692 struct datapath *dp;
16911693 int err;
16921694
1693− reply = ovs_dp_cmd_alloc_info(info);
1695+ reply = ovs_dp_cmd_alloc_info();
16941696 if (!reply)
16951697 return -ENOMEM;
16961698
@@ -1723,7 +1725,7 @@ static int ovs_dp_cmd_get(struct sk_buff *skb, struct genl_info *info) · 26 unmodified lines
17231725 struct datapath *dp;
17241726 int err;
17251727
1726− reply = ovs_dp_cmd_alloc_info(info);
1728+ reply = ovs_dp_cmd_alloc_info();
17271729 if (!reply)
17281730 return -ENOMEM;
17291731
@@ -1777,12 +1779,12 @@ static const struct nla_policy datapath_policy[OVS_DP_ATTR_MAX + 1] = { · 47 unmodified lines
17771779
17781780 static const struct genl_ops dp_datapath_genl_ops[] = {
17791781 { .cmd = OVS_DP_CMD_NEW,
1780− .flags = GENL_ADMIN_PERM, /* Requires CAP_NET_ADMIN privilege. */
1782+ .flags = GENL_UNS_ADMIN_PERM, /* Requires CAP_NET_ADMIN privilege. */
17811783 .policy = datapath_policy,
17821784 .doit = ovs_dp_cmd_new
17831785 },
17841786 { .cmd = OVS_DP_CMD_DEL,
1785− .flags = GENL_ADMIN_PERM, /* Requires CAP_NET_ADMIN privilege. */
1787+ .flags = GENL_UNS_ADMIN_PERM, /* Requires CAP_NET_ADMIN privilege. */
17861788 .policy = datapath_policy,
17871789 .doit = ovs_dp_cmd_del
17881790 },
@@ -1793,7 +1795,7 @@ static const struct genl_ops dp_datapath_genl_ops[] = { · 4 unmodified lines
17931795 .dumpit = ovs_dp_cmd_dump
17941796 },
17951797 { .cmd = OVS_DP_CMD_SET,
1796− .flags = GENL_ADMIN_PERM, /* Requires CAP_NET_ADMIN privilege. */
1798+ .flags = GENL_UNS_ADMIN_PERM, /* Requires CAP_NET_ADMIN privilege. */
17971799 .policy = datapath_policy,
17981800 .doit = ovs_dp_cmd_set,
17991801 },
@@ -1912,6 +1914,29 @@ static struct vport *lookup_vport(struct net *net, · 112 unmodified lines
19121914 return ERR_PTR(-EINVAL);
19131915 }
19141916
1917+/* Called with ovs_mutex */
1918+static void update_headroom(struct datapath *dp)
1919+{
1920+ unsigned dev_headroom, max_headroom = 0;
1921+ struct net_device *dev;
1922+ struct vport *vport;
1923+ int i;
1924+
1925+ for (i = 0; i < DP_VPORT_HASH_BUCKETS; i++) {
1926+ hlist_for_each_entry_rcu(vport, &dp->ports[i], dp_hash_node) {
1927+ dev = vport->dev;
1928+ dev_headroom = netdev_get_fwd_headroom(dev);
1929+ if (dev_headroom > max_headroom)
1930+ max_headroom = dev_headroom;
1931+ }
1932+ }
1933+
1934+ dp->max_headroom = max_headroom;
1935+ for (i = 0; i < DP_VPORT_HASH_BUCKETS; i++)
1936+ hlist_for_each_entry_rcu(vport, &dp->ports[i], dp_hash_node)
1937+ netdev_set_rx_headroom(vport->dev, max_headroom);
1938+}
1939+
19151940 static int ovs_vport_cmd_new(struct sk_buff *skb, struct genl_info *info)
19161941 {
19171942 struct nlattr **a = info->attrs;
@@ -1977,6 +2002,12 @@ restart: · 59 unmodified lines
19772002
19782003 err = ovs_vport_cmd_fill_info(vport, reply, info->snd_portid,
19792004 info->snd_seq, 0, OVS_VPORT_CMD_NEW);
2005+
2006+ if (netdev_get_fwd_headroom(vport->dev) > dp->max_headroom)
2007+ update_headroom(dp);
2008+ else
2009+ netdev_set_rx_headroom(vport->dev, dp->max_headroom);
2010+
19802011 BUG_ON(err < 0);
19812012 ovs_unlock();
19822013
@@ -2043,8 +2074,10 @@ exit_unlock_free: · 60 unmodified lines
20432074
20442075 static int ovs_vport_cmd_del(struct sk_buff *skb, struct genl_info *info)
20452076 {
2077+ bool must_update_headroom = false;
20462078 struct nlattr **a = info->attrs;
20472079 struct sk_buff *reply;
2080+ struct datapath *dp;
20482081 struct vport *vport;
20492082 int err;
20502083
@@ -2066,7 +2099,16 @@ static int ovs_vport_cmd_del(struct sk_buff *skb, struct genl_info *info) · 15 unmodified lines
20662099 err = ovs_vport_cmd_fill_info(vport, reply, info->snd_portid,
20672100 info->snd_seq, 0, OVS_VPORT_CMD_DEL);
20682101 BUG_ON(err < 0);
2102+
2103+ /* the vport deletion may trigger dp headroom update */
2104+ dp = vport->dp;
2105+ if (netdev_get_fwd_headroom(vport->dev) == dp->max_headroom)
2106+ must_update_headroom = true;
2107+ netdev_reset_rx_headroom(vport->dev);
20692108 ovs_dp_detach_port(vport);
2109+
2110+ if (must_update_headroom)
2111+ update_headroom(dp);
20702112 ovs_unlock();
20712113
20722114 ovs_notify(&dp_vport_genl_family, reply, info);
@@ -2158,12 +2200,12 @@ static const struct nla_policy vport_policy[OVS_VPORT_ATTR_MAX + 1] = { · 85 unmodified lines
21582200
21592201 static const struct genl_ops dp_vport_genl_ops[] = {
21602202 { .cmd = OVS_VPORT_CMD_NEW,
2161− .flags = GENL_ADMIN_PERM, /* Requires CAP_NET_ADMIN privilege. */
2203+ .flags = GENL_UNS_ADMIN_PERM, /* Requires CAP_NET_ADMIN privilege. */
21622204 .policy = vport_policy,
21632205 .doit = ovs_vport_cmd_new
21642206 },
21652207 { .cmd = OVS_VPORT_CMD_DEL,
2166− .flags = GENL_ADMIN_PERM, /* Requires CAP_NET_ADMIN privilege. */
2208+ .flags = GENL_UNS_ADMIN_PERM, /* Requires CAP_NET_ADMIN privilege. */
21672209 .policy = vport_policy,
21682210 .doit = ovs_vport_cmd_del
21692211 },
@@ -2174,7 +2216,7 @@ static const struct genl_ops dp_vport_genl_ops[] = { · 4 unmodified lines
21742216 .dumpit = ovs_vport_cmd_dump
21752217 },
21762218 { .cmd = OVS_VPORT_CMD_SET,
2177− .flags = GENL_ADMIN_PERM, /* Requires CAP_NET_ADMIN privilege. */
2219+ .flags = GENL_UNS_ADMIN_PERM, /* Requires CAP_NET_ADMIN privilege. */
21782220 .policy = vport_policy,
21792221 .doit = ovs_vport_cmd_set,
21802222 },
net/openvswitch/datapath.h+4−0
@@ -68,6 +68,8 @@ struct dp_stats_percpu { · 67 unmodified lines
6868 * ovs_mutex and RCU.
6969 * @stats_percpu: Per-CPU datapath statistics.
7070 * @net: Reference to net namespace.
71+ * @max_headroom: the maximum headroom of all vports in this datapath; it will
72+ * be used by all the internal vports in this dp.
7173 *
7274 * Context: See the comment on locking at the top of datapath.c for additional
7375 * locking information.
@@ -89,6 +91,8 @@ struct datapath { · 15 unmodified lines
8991 possible_net_t net;
9092
9193 u32 user_features;
94+
95+ u32 max_headroom;
9296 };
9397
9498 /**
net/openvswitch/flow.h+1−1
@@ -55,7 +55,7 @@ struct ovs_tunnel_info { · 54 unmodified lines
5555 FIELD_SIZEOF(struct sw_flow_key, recirc_id))
5656
5757 struct sw_flow_key {
58− u8 tun_opts[255];
58+ u8 tun_opts[IP_TUNNEL_OPTS_MAX];
5959 u8 tun_opts_len;
6060 struct ip_tunnel_key tun_key; /* Encapsulating tunnel key. */
6161 struct {
net/openvswitch/flow_netlink.c+6−3
@@ -1959,6 +1959,12 @@ static int validate_and_copy_set_tun(const struct nlattr *attr, · 1958 unmodified lines
19591959 if (!tun_dst)
19601960 return -ENOMEM;
19611961
1962+ err = dst_cache_init(&tun_dst->u.tun_info.dst_cache, GFP_KERNEL);
1963+ if (err) {
1964+ dst_release((struct dst_entry *)tun_dst);
1965+ return err;
1966+ }
1967+
19621968 a = __add_action(sfa, OVS_KEY_ATTR_TUNNEL_INFO, NULL,
19631969 sizeof(*ovs_tun), log);
19641970 if (IS_ERR(a)) {
@@ -2038,9 +2044,6 @@ static int validate_set(const struct nlattr *a, · 73 unmodified lines
20382044 break;
20392045
20402046 case OVS_KEY_ATTR_TUNNEL:
2041− if (eth_p_mpls(eth_type))
2042− return -EINVAL;
2043−
20442047 if (masked)
20452048 return -EINVAL; /* Masked tunnel set not supported. */
20462049
net/openvswitch/vport-internal_dev.c+9−1
@@ -138,6 +138,11 @@ internal_get_stats(struct net_device *dev, struct rtnl_link_stats64 *stats) · 137 unmodified lines
138138 return stats;
139139 }
140140
141+static void internal_set_rx_headroom(struct net_device *dev, int new_hr)
142+{
143+ dev->needed_headroom = new_hr;
144+}
145+
141146 static const struct net_device_ops internal_dev_netdev_ops = {
142147 .ndo_open = internal_dev_open,
143148 .ndo_stop = internal_dev_stop,
@@ -145,6 +150,7 @@ static const struct net_device_ops internal_dev_netdev_ops = { · 1 unmodified line
145150 .ndo_set_mac_address = eth_mac_addr,
146151 .ndo_change_mtu = internal_dev_change_mtu,
147152 .ndo_get_stats64 = internal_get_stats,
153+ .ndo_set_rx_headroom = internal_set_rx_headroom,
148154 };
149155
150156 static struct rtnl_link_ops internal_dev_link_ops __read_mostly = {
@@ -158,7 +164,8 @@ static void do_setup(struct net_device *netdev) · 7 unmodified lines
158164 netdev->netdev_ops = &internal_dev_netdev_ops;
159165
160166 netdev->priv_flags &= ~IFF_TX_SKB_SHARING;
161− netdev->priv_flags |= IFF_LIVE_ADDR_CHANGE | IFF_OPENVSWITCH;
167+ netdev->priv_flags |= IFF_LIVE_ADDR_CHANGE | IFF_OPENVSWITCH |
168+ IFF_PHONY_HEADROOM;
162169 netdev->destructor = internal_dev_destructor;
163170 netdev->ethtool_ops = &internal_dev_ethtool_ops;
164171 netdev->rtnl_link_ops = &internal_dev_link_ops;
@@ -199,6 +206,7 @@ static struct vport *internal_dev_create(const struct vport_parms *parms) · 34 unmodified lines
199206 err = -ENOMEM;
200207 goto error_free_netdev;
201208 }
209+ vport->dev->needed_headroom = vport->dp->max_headroom;
202210
203211 dev_net_set(vport->dev, ovs_dp_get_net(vport->dp));
204212 internal_dev = internal_dev_priv(vport->dev);
net/openvswitch/vport-netdev.c+1−1
@@ -58,7 +58,7 @@ static void netdev_port_receive(struct sk_buff *skb) · 57 unmodified lines
5858 return;
5959
6060 skb_push(skb, ETH_HLEN);
61− ovs_skb_postpush_rcsum(skb, skb->data, ETH_HLEN);
61+ skb_postpush_rcsum(skb, skb->data, ETH_HLEN);
6262 ovs_vport_receive(vport, skb, skb_tunnel_info(skb));
6363 return;
6464 error:
net/openvswitch/vport.h+0−7
@@ -185,13 +185,6 @@ static inline struct vport *vport_from_priv(void *priv) · 184 unmodified lines
185185 int ovs_vport_receive(struct vport *, struct sk_buff *,
186186 const struct ip_tunnel_info *);
187187
188−static inline void ovs_skb_postpush_rcsum(struct sk_buff *skb,
189− const void *start, unsigned int len)
190−{
191− if (skb->ip_summed == CHECKSUM_COMPLETE)
192− skb->csum = csum_add(skb->csum, csum_partial(start, len, 0));
193−}
194−
195188 static inline const char *ovs_vport_name(struct vport *vport)
196189 {
197190 return vport->dev->name;

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t