Message ID | 20240731172332.683815-8-tom@herbertland.com (mailing list archive) |
---|---|
State | Changes Requested |
Delegated to: | Netdev Maintainers |
Headers | show |
Series | flow_dissector: Dissect UDP encapsulation protocols | expand |
On Wed, Jul 31, 2024 at 10:23:27AM -0700, Tom Herbert wrote: > Parse vxlan in a UDP encapsulation > > Signed-off-by: Tom Herbert <tom@herbertland.com> > --- > net/core/flow_dissector.c | 57 +++++++++++++++++++++++++++++++++++++++ > 1 file changed, 57 insertions(+) > > diff --git a/net/core/flow_dissector.c b/net/core/flow_dissector.c ... > @@ -756,6 +758,55 @@ __skb_flow_dissect_gre(const struct sk_buff *skb, > return FLOW_DISSECT_RET_PROTO_AGAIN; > } > > +static enum flow_dissect_ret > +__skb_flow_dissect_vxlan(const struct sk_buff *skb, > + struct flow_dissector *flow_dissector, > + void *target_container, const void *data, > + __be16 *p_proto, int *p_nhoff, int hlen, > + unsigned int flags) > +{ > + struct vxlanhdr *hdr, _hdr; > + __be16 protocol; > + > + hdr = __skb_header_pointer(skb, *p_nhoff, sizeof(_hdr), data, hlen, > + &_hdr); > + if (!hdr) > + return FLOW_DISSECT_RET_OUT_BAD; > + > + /* VNI flag always required to be set */ > + if (!(hdr->vx_flags & VXLAN_HF_VNI)) > + return FLOW_DISSECT_RET_OUT_BAD; > + > + if (hdr->vx_flags & VXLAN_F_GPE) { Hi Tom, Sparse flags an byte-order miss match on the line above. I expect this would resolve it (completely untested!): if (hdr->vx_flags & cpu_to_be32(VXLAN_F_GPE)) ...
Hi Tom, kernel test robot noticed the following build warnings: [auto build test WARNING on net-next/main] [also build test WARNING on net/main linus/master v6.11-rc1 next-20240802] [cannot apply to horms-ipvs/master] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in https://git-scm.com/docs/git-format-patch#_base_tree_information] url: https://github.com/intel-lab-lkp/linux/commits/Tom-Herbert/skbuff-Unconstantify-struct-net-argument-in-flowdis-functions/20240802-084418 base: net-next/main patch link: https://lore.kernel.org/r/20240731172332.683815-8-tom%40herbertland.com patch subject: [PATCH 07/12] flow_dissector: Parse vxlan in UDP config: i386-randconfig-062-20240802 (https://download.01.org/0day-ci/archive/20240803/202408031144.ln4wxJc4-lkp@intel.com/config) compiler: gcc-12 (Debian 12.2.0-14) 12.2.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240803/202408031144.ln4wxJc4-lkp@intel.com/reproduce) If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags | Reported-by: kernel test robot <lkp@intel.com> | Closes: https://lore.kernel.org/oe-kbuild-all/202408031144.ln4wxJc4-lkp@intel.com/ sparse warnings: (new ones prefixed by >>) >> net/core/flow_dissector.c:780:16: sparse: sparse: restricted __be32 degrades to integer net/core/flow_dissector.c: note: in included file (through include/linux/if_pppox.h): include/uapi/linux/if_pppox.h:153:29: sparse: sparse: array of flexible structures vim +780 net/core/flow_dissector.c 760 761 static enum flow_dissect_ret 762 __skb_flow_dissect_vxlan(const struct sk_buff *skb, 763 struct flow_dissector *flow_dissector, 764 void *target_container, const void *data, 765 __be16 *p_proto, int *p_nhoff, int hlen, 766 unsigned int flags) 767 { 768 struct vxlanhdr *hdr, _hdr; 769 __be16 protocol; 770 771 hdr = __skb_header_pointer(skb, *p_nhoff, sizeof(_hdr), data, hlen, 772 &_hdr); 773 if (!hdr) 774 return FLOW_DISSECT_RET_OUT_BAD; 775 776 /* VNI flag always required to be set */ 777 if (!(hdr->vx_flags & VXLAN_HF_VNI)) 778 return FLOW_DISSECT_RET_OUT_BAD; 779 > 780 if (hdr->vx_flags & VXLAN_F_GPE) { 781 struct vxlanhdr_gpe *gpe = (struct vxlanhdr_gpe *)hdr; 782 783 /* Need to have Next Protocol set for interfaces in GPE mode. */ 784 if (!gpe->np_applied) 785 return FLOW_DISSECT_RET_OUT_BAD; 786 787 /* The initial version is 0 */ 788 if (gpe->version != 0) 789 return FLOW_DISSECT_RET_OUT_GOOD; 790 791 /* "When the O bit is set to 1, the packet is an OAM packet and 792 * OAM so ignore 793 */ 794 if (gpe->oam_flag) 795 return FLOW_DISSECT_RET_OUT_GOOD; 796 797 protocol = tun_p_to_eth_p(gpe->next_protocol); 798 if (!protocol) 799 return FLOW_DISSECT_RET_OUT_GOOD; 800 } else { 801 protocol = htons(ETH_P_TEB); 802 } 803 804 *p_nhoff += sizeof(struct vxlanhdr); 805 *p_proto = protocol; 806 807 return FLOW_DISSECT_RET_PROTO_AGAIN; 808 } 809
diff --git a/net/core/flow_dissector.c b/net/core/flow_dissector.c index 006db3b893d0..6ad45b09dda4 100644 --- a/net/core/flow_dissector.c +++ b/net/core/flow_dissector.c @@ -13,7 +13,9 @@ #include <net/gre.h> #include <net/pptp.h> #include <net/tipc.h> +#include <net/tun_proto.h> #include <net/udp.h> +#include <net/vxlan.h> #include <linux/igmp.h> #include <linux/icmp.h> #include <linux/sctp.h> @@ -756,6 +758,55 @@ __skb_flow_dissect_gre(const struct sk_buff *skb, return FLOW_DISSECT_RET_PROTO_AGAIN; } +static enum flow_dissect_ret +__skb_flow_dissect_vxlan(const struct sk_buff *skb, + struct flow_dissector *flow_dissector, + void *target_container, const void *data, + __be16 *p_proto, int *p_nhoff, int hlen, + unsigned int flags) +{ + struct vxlanhdr *hdr, _hdr; + __be16 protocol; + + hdr = __skb_header_pointer(skb, *p_nhoff, sizeof(_hdr), data, hlen, + &_hdr); + if (!hdr) + return FLOW_DISSECT_RET_OUT_BAD; + + /* VNI flag always required to be set */ + if (!(hdr->vx_flags & VXLAN_HF_VNI)) + return FLOW_DISSECT_RET_OUT_BAD; + + if (hdr->vx_flags & VXLAN_F_GPE) { + struct vxlanhdr_gpe *gpe = (struct vxlanhdr_gpe *)hdr; + + /* Need to have Next Protocol set for interfaces in GPE mode. */ + if (!gpe->np_applied) + return FLOW_DISSECT_RET_OUT_BAD; + + /* The initial version is 0 */ + if (gpe->version != 0) + return FLOW_DISSECT_RET_OUT_GOOD; + + /* "When the O bit is set to 1, the packet is an OAM packet and + * OAM so ignore + */ + if (gpe->oam_flag) + return FLOW_DISSECT_RET_OUT_GOOD; + + protocol = tun_p_to_eth_p(gpe->next_protocol); + if (!protocol) + return FLOW_DISSECT_RET_OUT_GOOD; + } else { + protocol = htons(ETH_P_TEB); + } + + *p_nhoff += sizeof(struct vxlanhdr); + *p_proto = protocol; + + return FLOW_DISSECT_RET_PROTO_AGAIN; +} + /** * __skb_flow_dissect_batadv() - dissect batman-adv header * @skb: sk_buff to with the batman-adv header @@ -893,6 +944,12 @@ __skb_flow_dissect_udp(const struct sk_buff *skb, struct net *net, ret = FLOW_DISSECT_RET_OUT_GOOD; switch (encap_type) { + case UDP_ENCAP_VXLAN: + case UDP_ENCAP_VXLAN_GPE: + ret = __skb_flow_dissect_vxlan(skb, flow_dissector, + target_container, data, + p_proto, &nhoff, hlen, flags); + break; default: break; }
Parse vxlan in a UDP encapsulation Signed-off-by: Tom Herbert <tom@herbertland.com> --- net/core/flow_dissector.c | 57 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+)