[<prev] [next>] [day] [month] [year] [list]
Message-ID: <202104150913.hupgUSHL-lkp@intel.com>
Date: Thu, 15 Apr 2021 09:32:19 +0800
From: kernel test robot <lkp@...el.com>
To: "Gustavo A. R. Silva" <gustavoars@...nel.org>
Cc: kbuild-all@...ts.01.org,
"Gustavo A. R. Silva" <gustavo@...eddedor.com>,
LKML <linux-kernel@...r.kernel.org>
Subject: [gustavoars-linux:testing/warray-bounds 1/10]
net/core/flow_dissector.c:835:3: warning: 'memcpy' offset [33, 48] from the
object at 'flow_keys' is out of the bounds of referenced subobject
'ipv6_src' with type '__u32[4]' {aka 'unsigned int[4]'} at offset 16
tree: https://git.kernel.org/pub/scm/linux/kernel/git/gustavoars/linux.git testing/warray-bounds
head: 4695107c157dd670a5fc1b1d3ccbfdc440caca24
commit: 06f7d86a7f517e6ce30162d18a7eef3ed192282a [1/10] Makefile: Enable -Warray-bounds
config: x86_64-randconfig-r026-20210414 (attached as .config)
compiler: gcc-9 (Debian 9.3.0-22) 9.3.0
reproduce (this is a W=1 build):
# https://git.kernel.org/pub/scm/linux/kernel/git/gustavoars/linux.git/commit/?id=06f7d86a7f517e6ce30162d18a7eef3ed192282a
git remote add gustavoars-linux https://git.kernel.org/pub/scm/linux/kernel/git/gustavoars/linux.git
git fetch --no-tags gustavoars-linux testing/warray-bounds
git checkout 06f7d86a7f517e6ce30162d18a7eef3ed192282a
# save the attached .config to linux build tree
make W=1 W=1 ARCH=x86_64
If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@...el.com>
All warnings (new ones prefixed by >>):
In function '__skb_flow_bpf_to_target',
inlined from '__skb_flow_dissect' at net/core/flow_dissector.c:1014:4:
>> net/core/flow_dissector.c:835:3: warning: 'memcpy' offset [33, 48] from the object at 'flow_keys' is out of the bounds of referenced subobject 'ipv6_src' with type '__u32[4]' {aka 'unsigned int[4]'} at offset 16 [-Warray-bounds]
835 | memcpy(&key_addrs->v6addrs, &flow_keys->ipv6_src,
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
836 | sizeof(key_addrs->v6addrs));
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~
--
net/ethtool/ioctl.c: In function 'store_link_ksettings_for_user.constprop':
>> net/ethtool/ioctl.c:492:2: warning: 'memcpy' offset [49, 84] from the object at 'link_usettings' is out of the bounds of referenced subobject 'base' with type 'struct ethtool_link_settings' at offset 0 [-Warray-bounds]
492 | memcpy(&link_usettings.base, &from->base, sizeof(link_usettings));
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
vim +835 net/core/flow_dissector.c
1eed4dfb81b193 Tom Herbert 2017-09-01 793
d58e468b1112dc Petar Penkov 2018-09-14 794 static void __skb_flow_bpf_to_target(const struct bpf_flow_keys *flow_keys,
d58e468b1112dc Petar Penkov 2018-09-14 795 struct flow_dissector *flow_dissector,
d58e468b1112dc Petar Penkov 2018-09-14 796 void *target_container)
d58e468b1112dc Petar Penkov 2018-09-14 797 {
59fb9b62fb6c92 Yoshiki Komachi 2020-01-17 798 struct flow_dissector_key_ports *key_ports = NULL;
d58e468b1112dc Petar Penkov 2018-09-14 799 struct flow_dissector_key_control *key_control;
d58e468b1112dc Petar Penkov 2018-09-14 800 struct flow_dissector_key_basic *key_basic;
d58e468b1112dc Petar Penkov 2018-09-14 801 struct flow_dissector_key_addrs *key_addrs;
71c99e32b92615 Stanislav Fomichev 2019-07-25 802 struct flow_dissector_key_tags *key_tags;
d58e468b1112dc Petar Penkov 2018-09-14 803
d58e468b1112dc Petar Penkov 2018-09-14 804 key_control = skb_flow_dissector_target(flow_dissector,
d58e468b1112dc Petar Penkov 2018-09-14 805 FLOW_DISSECTOR_KEY_CONTROL,
d58e468b1112dc Petar Penkov 2018-09-14 806 target_container);
d58e468b1112dc Petar Penkov 2018-09-14 807 key_control->thoff = flow_keys->thoff;
d58e468b1112dc Petar Penkov 2018-09-14 808 if (flow_keys->is_frag)
d58e468b1112dc Petar Penkov 2018-09-14 809 key_control->flags |= FLOW_DIS_IS_FRAGMENT;
d58e468b1112dc Petar Penkov 2018-09-14 810 if (flow_keys->is_first_frag)
d58e468b1112dc Petar Penkov 2018-09-14 811 key_control->flags |= FLOW_DIS_FIRST_FRAG;
d58e468b1112dc Petar Penkov 2018-09-14 812 if (flow_keys->is_encap)
d58e468b1112dc Petar Penkov 2018-09-14 813 key_control->flags |= FLOW_DIS_ENCAPSULATION;
d58e468b1112dc Petar Penkov 2018-09-14 814
d58e468b1112dc Petar Penkov 2018-09-14 815 key_basic = skb_flow_dissector_target(flow_dissector,
d58e468b1112dc Petar Penkov 2018-09-14 816 FLOW_DISSECTOR_KEY_BASIC,
d58e468b1112dc Petar Penkov 2018-09-14 817 target_container);
d58e468b1112dc Petar Penkov 2018-09-14 818 key_basic->n_proto = flow_keys->n_proto;
d58e468b1112dc Petar Penkov 2018-09-14 819 key_basic->ip_proto = flow_keys->ip_proto;
d58e468b1112dc Petar Penkov 2018-09-14 820
d58e468b1112dc Petar Penkov 2018-09-14 821 if (flow_keys->addr_proto == ETH_P_IP &&
d58e468b1112dc Petar Penkov 2018-09-14 822 dissector_uses_key(flow_dissector, FLOW_DISSECTOR_KEY_IPV4_ADDRS)) {
d58e468b1112dc Petar Penkov 2018-09-14 823 key_addrs = skb_flow_dissector_target(flow_dissector,
d58e468b1112dc Petar Penkov 2018-09-14 824 FLOW_DISSECTOR_KEY_IPV4_ADDRS,
d58e468b1112dc Petar Penkov 2018-09-14 825 target_container);
d58e468b1112dc Petar Penkov 2018-09-14 826 key_addrs->v4addrs.src = flow_keys->ipv4_src;
d58e468b1112dc Petar Penkov 2018-09-14 827 key_addrs->v4addrs.dst = flow_keys->ipv4_dst;
d58e468b1112dc Petar Penkov 2018-09-14 828 key_control->addr_type = FLOW_DISSECTOR_KEY_IPV4_ADDRS;
d58e468b1112dc Petar Penkov 2018-09-14 829 } else if (flow_keys->addr_proto == ETH_P_IPV6 &&
d58e468b1112dc Petar Penkov 2018-09-14 830 dissector_uses_key(flow_dissector,
d58e468b1112dc Petar Penkov 2018-09-14 831 FLOW_DISSECTOR_KEY_IPV6_ADDRS)) {
d58e468b1112dc Petar Penkov 2018-09-14 832 key_addrs = skb_flow_dissector_target(flow_dissector,
d58e468b1112dc Petar Penkov 2018-09-14 833 FLOW_DISSECTOR_KEY_IPV6_ADDRS,
d58e468b1112dc Petar Penkov 2018-09-14 834 target_container);
d58e468b1112dc Petar Penkov 2018-09-14 @835 memcpy(&key_addrs->v6addrs, &flow_keys->ipv6_src,
d58e468b1112dc Petar Penkov 2018-09-14 836 sizeof(key_addrs->v6addrs));
d58e468b1112dc Petar Penkov 2018-09-14 837 key_control->addr_type = FLOW_DISSECTOR_KEY_IPV6_ADDRS;
d58e468b1112dc Petar Penkov 2018-09-14 838 }
d58e468b1112dc Petar Penkov 2018-09-14 839
59fb9b62fb6c92 Yoshiki Komachi 2020-01-17 840 if (dissector_uses_key(flow_dissector, FLOW_DISSECTOR_KEY_PORTS))
d58e468b1112dc Petar Penkov 2018-09-14 841 key_ports = skb_flow_dissector_target(flow_dissector,
d58e468b1112dc Petar Penkov 2018-09-14 842 FLOW_DISSECTOR_KEY_PORTS,
d58e468b1112dc Petar Penkov 2018-09-14 843 target_container);
59fb9b62fb6c92 Yoshiki Komachi 2020-01-17 844 else if (dissector_uses_key(flow_dissector,
59fb9b62fb6c92 Yoshiki Komachi 2020-01-17 845 FLOW_DISSECTOR_KEY_PORTS_RANGE))
59fb9b62fb6c92 Yoshiki Komachi 2020-01-17 846 key_ports = skb_flow_dissector_target(flow_dissector,
59fb9b62fb6c92 Yoshiki Komachi 2020-01-17 847 FLOW_DISSECTOR_KEY_PORTS_RANGE,
59fb9b62fb6c92 Yoshiki Komachi 2020-01-17 848 target_container);
59fb9b62fb6c92 Yoshiki Komachi 2020-01-17 849
59fb9b62fb6c92 Yoshiki Komachi 2020-01-17 850 if (key_ports) {
d58e468b1112dc Petar Penkov 2018-09-14 851 key_ports->src = flow_keys->sport;
d58e468b1112dc Petar Penkov 2018-09-14 852 key_ports->dst = flow_keys->dport;
d58e468b1112dc Petar Penkov 2018-09-14 853 }
71c99e32b92615 Stanislav Fomichev 2019-07-25 854
71c99e32b92615 Stanislav Fomichev 2019-07-25 855 if (dissector_uses_key(flow_dissector,
71c99e32b92615 Stanislav Fomichev 2019-07-25 856 FLOW_DISSECTOR_KEY_FLOW_LABEL)) {
71c99e32b92615 Stanislav Fomichev 2019-07-25 857 key_tags = skb_flow_dissector_target(flow_dissector,
71c99e32b92615 Stanislav Fomichev 2019-07-25 858 FLOW_DISSECTOR_KEY_FLOW_LABEL,
71c99e32b92615 Stanislav Fomichev 2019-07-25 859 target_container);
71c99e32b92615 Stanislav Fomichev 2019-07-25 860 key_tags->flow_label = ntohl(flow_keys->flow_label);
71c99e32b92615 Stanislav Fomichev 2019-07-25 861 }
d58e468b1112dc Petar Penkov 2018-09-14 862 }
d58e468b1112dc Petar Penkov 2018-09-14 863
089b19a9204fc0 Stanislav Fomichev 2019-04-22 864 bool bpf_flow_dissect(struct bpf_prog *prog, struct bpf_flow_dissector *ctx,
086f95682114fd Stanislav Fomichev 2019-07-25 865 __be16 proto, int nhoff, int hlen, unsigned int flags)
089b19a9204fc0 Stanislav Fomichev 2019-04-22 866 {
089b19a9204fc0 Stanislav Fomichev 2019-04-22 867 struct bpf_flow_keys *flow_keys = ctx->flow_keys;
089b19a9204fc0 Stanislav Fomichev 2019-04-22 868 u32 result;
c8aa703822bf81 Stanislav Fomichev 2019-01-28 869
c8aa703822bf81 Stanislav Fomichev 2019-01-28 870 /* Pass parameters to the BPF program */
c8aa703822bf81 Stanislav Fomichev 2019-01-28 871 memset(flow_keys, 0, sizeof(*flow_keys));
089b19a9204fc0 Stanislav Fomichev 2019-04-22 872 flow_keys->n_proto = proto;
089b19a9204fc0 Stanislav Fomichev 2019-04-22 873 flow_keys->nhoff = nhoff;
c8aa703822bf81 Stanislav Fomichev 2019-01-28 874 flow_keys->thoff = flow_keys->nhoff;
c8aa703822bf81 Stanislav Fomichev 2019-01-28 875
086f95682114fd Stanislav Fomichev 2019-07-25 876 BUILD_BUG_ON((int)BPF_FLOW_DISSECTOR_F_PARSE_1ST_FRAG !=
086f95682114fd Stanislav Fomichev 2019-07-25 877 (int)FLOW_DISSECTOR_F_PARSE_1ST_FRAG);
086f95682114fd Stanislav Fomichev 2019-07-25 878 BUILD_BUG_ON((int)BPF_FLOW_DISSECTOR_F_STOP_AT_FLOW_LABEL !=
086f95682114fd Stanislav Fomichev 2019-07-25 879 (int)FLOW_DISSECTOR_F_STOP_AT_FLOW_LABEL);
086f95682114fd Stanislav Fomichev 2019-07-25 880 BUILD_BUG_ON((int)BPF_FLOW_DISSECTOR_F_STOP_AT_ENCAP !=
086f95682114fd Stanislav Fomichev 2019-07-25 881 (int)FLOW_DISSECTOR_F_STOP_AT_ENCAP);
086f95682114fd Stanislav Fomichev 2019-07-25 882 flow_keys->flags = flags;
086f95682114fd Stanislav Fomichev 2019-07-25 883
3d9f773cf2876c David Miller 2020-02-24 884 result = bpf_prog_run_pin_on_cpu(prog, ctx);
c8aa703822bf81 Stanislav Fomichev 2019-01-28 885
089b19a9204fc0 Stanislav Fomichev 2019-04-22 886 flow_keys->nhoff = clamp_t(u16, flow_keys->nhoff, nhoff, hlen);
c8aa703822bf81 Stanislav Fomichev 2019-01-28 887 flow_keys->thoff = clamp_t(u16, flow_keys->thoff,
089b19a9204fc0 Stanislav Fomichev 2019-04-22 888 flow_keys->nhoff, hlen);
c8aa703822bf81 Stanislav Fomichev 2019-01-28 889
c8aa703822bf81 Stanislav Fomichev 2019-01-28 890 return result == BPF_OK;
c8aa703822bf81 Stanislav Fomichev 2019-01-28 891 }
c8aa703822bf81 Stanislav Fomichev 2019-01-28 892
453a940ea725d6 WANG Cong 2014-08-25 893 /**
453a940ea725d6 WANG Cong 2014-08-25 894 * __skb_flow_dissect - extract the flow_keys struct and return it
3cbf4ffba5eeec Stanislav Fomichev 2019-04-22 895 * @net: associated network namespace, derived from @skb if NULL
453a940ea725d6 WANG Cong 2014-08-25 896 * @skb: sk_buff to extract the flow from, can be NULL if the rest are specified
06635a35d13d42 Jiri Pirko 2015-05-12 897 * @flow_dissector: list of keys to dissect
06635a35d13d42 Jiri Pirko 2015-05-12 898 * @target_container: target structure to put dissected values into
453a940ea725d6 WANG Cong 2014-08-25 899 * @data: raw buffer pointer to the packet, if NULL use skb->data
453a940ea725d6 WANG Cong 2014-08-25 900 * @proto: protocol for which to get the flow, if @data is NULL use skb->protocol
453a940ea725d6 WANG Cong 2014-08-25 901 * @nhoff: network header offset, if @data is NULL use skb_network_offset(skb)
453a940ea725d6 WANG Cong 2014-08-25 902 * @hlen: packet header length, if @data is NULL use skb_headlen(skb)
d79b3bafabc27c Bart Van Assche 2019-03-25 903 * @flags: flags that control the dissection process, e.g.
1cc26450a855aa Stanislav Fomichev 2019-05-31 904 * FLOW_DISSECTOR_F_STOP_AT_ENCAP.
453a940ea725d6 WANG Cong 2014-08-25 905 *
06635a35d13d42 Jiri Pirko 2015-05-12 906 * The function will try to retrieve individual keys into target specified
06635a35d13d42 Jiri Pirko 2015-05-12 907 * by flow_dissector from either the skbuff or a raw buffer specified by the
06635a35d13d42 Jiri Pirko 2015-05-12 908 * rest parameters.
06635a35d13d42 Jiri Pirko 2015-05-12 909 *
06635a35d13d42 Jiri Pirko 2015-05-12 910 * Caller must take care of zeroing target container memory.
453a940ea725d6 WANG Cong 2014-08-25 911 */
3cbf4ffba5eeec Stanislav Fomichev 2019-04-22 912 bool __skb_flow_dissect(const struct net *net,
3cbf4ffba5eeec Stanislav Fomichev 2019-04-22 913 const struct sk_buff *skb,
06635a35d13d42 Jiri Pirko 2015-05-12 914 struct flow_dissector *flow_dissector,
f96533cded173b Alexander Lobakin 2021-03-14 915 void *target_container, const void *data,
f96533cded173b Alexander Lobakin 2021-03-14 916 __be16 proto, int nhoff, int hlen, unsigned int flags)
0744dd00c1b1be Eric Dumazet 2011-11-28 917 {
42aecaa9bb2bd5 Tom Herbert 2015-06-04 918 struct flow_dissector_key_control *key_control;
06635a35d13d42 Jiri Pirko 2015-05-12 919 struct flow_dissector_key_basic *key_basic;
06635a35d13d42 Jiri Pirko 2015-05-12 920 struct flow_dissector_key_addrs *key_addrs;
d34af823ff401c Tom Herbert 2015-06-04 921 struct flow_dissector_key_tags *key_tags;
f6a66927692e30 Hadar Hen Zion 2016-08-17 922 struct flow_dissector_key_vlan *key_vlan;
3a1214e8b06317 Tom Herbert 2017-09-01 923 enum flow_dissect_ret fdret;
24c590e3b0f9ee Jianbo Liu 2018-07-06 924 enum flow_dissector_key_id dissector_vlan = FLOW_DISSECTOR_KEY_MAX;
58cff782cc55eb Guillaume Nault 2020-05-26 925 bool mpls_el = false;
58cff782cc55eb Guillaume Nault 2020-05-26 926 int mpls_lse = 0;
1eed4dfb81b193 Tom Herbert 2017-09-01 927 int num_hdrs = 0;
8e690ffdbcc7b5 Geert Uytterhoeven 2015-06-25 928 u8 ip_proto = 0;
34fad54c2537f7 Eric Dumazet 2016-11-09 929 bool ret;
0744dd00c1b1be Eric Dumazet 2011-11-28 930
690e36e726d00d David S. Miller 2014-08-23 931 if (!data) {
690e36e726d00d David S. Miller 2014-08-23 932 data = skb->data;
d5709f7ab77679 Hadar Hen Zion 2016-08-17 933 proto = skb_vlan_tag_present(skb) ?
d5709f7ab77679 Hadar Hen Zion 2016-08-17 934 skb->vlan_proto : skb->protocol;
453a940ea725d6 WANG Cong 2014-08-25 935 nhoff = skb_network_offset(skb);
690e36e726d00d David S. Miller 2014-08-23 936 hlen = skb_headlen(skb);
2d5716456404a1 John Crispin 2017-08-10 937 #if IS_ENABLED(CONFIG_NET_DSA)
8bef0af09a5415 Alexander Lobakin 2019-12-05 938 if (unlikely(skb->dev && netdev_uses_dsa(skb->dev) &&
8bef0af09a5415 Alexander Lobakin 2019-12-05 939 proto == htons(ETH_P_XDSA))) {
43e665287f931a John Crispin 2017-08-09 940 const struct dsa_device_ops *ops;
8bef0af09a5415 Alexander Lobakin 2019-12-05 941 int offset = 0;
43e665287f931a John Crispin 2017-08-09 942
43e665287f931a John Crispin 2017-08-09 943 ops = skb->dev->dsa_ptr->tag_ops;
54fec33582aa60 Vladimir Oltean 2020-09-26 944 /* Tail taggers don't break flow dissection */
54fec33582aa60 Vladimir Oltean 2020-09-26 945 if (!ops->tail_tag) {
54fec33582aa60 Vladimir Oltean 2020-09-26 946 if (ops->flow_dissect)
2e8cb1b3db3843 Vladimir Oltean 2020-09-26 947 ops->flow_dissect(skb, &proto, &offset);
54fec33582aa60 Vladimir Oltean 2020-09-26 948 else
54fec33582aa60 Vladimir Oltean 2020-09-26 949 dsa_tag_generic_flow_dissect(skb,
54fec33582aa60 Vladimir Oltean 2020-09-26 950 &proto,
54fec33582aa60 Vladimir Oltean 2020-09-26 951 &offset);
43e665287f931a John Crispin 2017-08-09 952 hlen -= offset;
43e665287f931a John Crispin 2017-08-09 953 nhoff += offset;
43e665287f931a John Crispin 2017-08-09 954 }
43e665287f931a John Crispin 2017-08-09 955 }
2d5716456404a1 John Crispin 2017-08-10 956 #endif
690e36e726d00d David S. Miller 2014-08-23 957 }
690e36e726d00d David S. Miller 2014-08-23 958
42aecaa9bb2bd5 Tom Herbert 2015-06-04 959 /* It is ensured by skb_flow_dissector_init() that control key will
42aecaa9bb2bd5 Tom Herbert 2015-06-04 960 * be always present.
42aecaa9bb2bd5 Tom Herbert 2015-06-04 961 */
42aecaa9bb2bd5 Tom Herbert 2015-06-04 962 key_control = skb_flow_dissector_target(flow_dissector,
42aecaa9bb2bd5 Tom Herbert 2015-06-04 963 FLOW_DISSECTOR_KEY_CONTROL,
42aecaa9bb2bd5 Tom Herbert 2015-06-04 964 target_container);
42aecaa9bb2bd5 Tom Herbert 2015-06-04 965
06635a35d13d42 Jiri Pirko 2015-05-12 966 /* It is ensured by skb_flow_dissector_init() that basic key will
06635a35d13d42 Jiri Pirko 2015-05-12 967 * be always present.
06635a35d13d42 Jiri Pirko 2015-05-12 968 */
06635a35d13d42 Jiri Pirko 2015-05-12 969 key_basic = skb_flow_dissector_target(flow_dissector,
06635a35d13d42 Jiri Pirko 2015-05-12 970 FLOW_DISSECTOR_KEY_BASIC,
06635a35d13d42 Jiri Pirko 2015-05-12 971 target_container);
0744dd00c1b1be Eric Dumazet 2011-11-28 972
d0e13a1488ad30 Willem de Bruijn 2018-09-24 973 if (skb) {
3cbf4ffba5eeec Stanislav Fomichev 2019-04-22 974 if (!net) {
d0e13a1488ad30 Willem de Bruijn 2018-09-24 975 if (skb->dev)
3cbf4ffba5eeec Stanislav Fomichev 2019-04-22 976 net = dev_net(skb->dev);
d0e13a1488ad30 Willem de Bruijn 2018-09-24 977 else if (skb->sk)
3cbf4ffba5eeec Stanislav Fomichev 2019-04-22 978 net = sock_net(skb->sk);
9b52e3f267a683 Stanislav Fomichev 2019-04-22 979 }
3cbf4ffba5eeec Stanislav Fomichev 2019-04-22 980 }
3cbf4ffba5eeec Stanislav Fomichev 2019-04-22 981
9b52e3f267a683 Stanislav Fomichev 2019-04-22 982 WARN_ON_ONCE(!net);
9b52e3f267a683 Stanislav Fomichev 2019-04-22 983 if (net) {
a3fd7ceee05431 Jakub Sitnicki 2020-05-31 984 enum netns_bpf_attach_type type = NETNS_BPF_FLOW_DISSECTOR;
695c12147a4018 Jakub Sitnicki 2020-06-25 985 struct bpf_prog_array *run_array;
a3fd7ceee05431 Jakub Sitnicki 2020-05-31 986
9b52e3f267a683 Stanislav Fomichev 2019-04-22 987 rcu_read_lock();
695c12147a4018 Jakub Sitnicki 2020-06-25 988 run_array = rcu_dereference(init_net.bpf.run_array[type]);
695c12147a4018 Jakub Sitnicki 2020-06-25 989 if (!run_array)
695c12147a4018 Jakub Sitnicki 2020-06-25 990 run_array = rcu_dereference(net->bpf.run_array[type]);
a11c397c43d5b2 Stanislav Fomichev 2019-10-07 991
695c12147a4018 Jakub Sitnicki 2020-06-25 992 if (run_array) {
9b52e3f267a683 Stanislav Fomichev 2019-04-22 993 struct bpf_flow_keys flow_keys;
9b52e3f267a683 Stanislav Fomichev 2019-04-22 994 struct bpf_flow_dissector ctx = {
9b52e3f267a683 Stanislav Fomichev 2019-04-22 995 .flow_keys = &flow_keys,
9b52e3f267a683 Stanislav Fomichev 2019-04-22 996 .data = data,
9b52e3f267a683 Stanislav Fomichev 2019-04-22 997 .data_end = data + hlen,
9b52e3f267a683 Stanislav Fomichev 2019-04-22 998 };
9b52e3f267a683 Stanislav Fomichev 2019-04-22 999 __be16 n_proto = proto;
695c12147a4018 Jakub Sitnicki 2020-06-25 1000 struct bpf_prog *prog;
9b52e3f267a683 Stanislav Fomichev 2019-04-22 1001
9b52e3f267a683 Stanislav Fomichev 2019-04-22 1002 if (skb) {
9b52e3f267a683 Stanislav Fomichev 2019-04-22 1003 ctx.skb = skb;
9b52e3f267a683 Stanislav Fomichev 2019-04-22 1004 /* we can't use 'proto' in the skb case
9b52e3f267a683 Stanislav Fomichev 2019-04-22 1005 * because it might be set to skb->vlan_proto
9b52e3f267a683 Stanislav Fomichev 2019-04-22 1006 * which has been pulled from the data
9b52e3f267a683 Stanislav Fomichev 2019-04-22 1007 */
9b52e3f267a683 Stanislav Fomichev 2019-04-22 1008 n_proto = skb->protocol;
9b52e3f267a683 Stanislav Fomichev 2019-04-22 1009 }
9b52e3f267a683 Stanislav Fomichev 2019-04-22 1010
695c12147a4018 Jakub Sitnicki 2020-06-25 1011 prog = READ_ONCE(run_array->items[0].prog);
695c12147a4018 Jakub Sitnicki 2020-06-25 1012 ret = bpf_flow_dissect(prog, &ctx, n_proto, nhoff,
086f95682114fd Stanislav Fomichev 2019-07-25 1013 hlen, flags);
d58e468b1112dc Petar Penkov 2018-09-14 @1014 __skb_flow_bpf_to_target(&flow_keys, flow_dissector,
d58e468b1112dc Petar Penkov 2018-09-14 1015 target_container);
d58e468b1112dc Petar Penkov 2018-09-14 1016 rcu_read_unlock();
c8aa703822bf81 Stanislav Fomichev 2019-01-28 1017 return ret;
d58e468b1112dc Petar Penkov 2018-09-14 1018 }
d58e468b1112dc Petar Penkov 2018-09-14 1019 rcu_read_unlock();
c8aa703822bf81 Stanislav Fomichev 2019-01-28 1020 }
d58e468b1112dc Petar Penkov 2018-09-14 1021
20a17bf6c04e3e David S. Miller 2015-09-01 1022 if (dissector_uses_key(flow_dissector,
67a900cc0436d7 Jiri Pirko 2015-05-12 1023 FLOW_DISSECTOR_KEY_ETH_ADDRS)) {
67a900cc0436d7 Jiri Pirko 2015-05-12 1024 struct ethhdr *eth = eth_hdr(skb);
67a900cc0436d7 Jiri Pirko 2015-05-12 1025 struct flow_dissector_key_eth_addrs *key_eth_addrs;
67a900cc0436d7 Jiri Pirko 2015-05-12 1026
67a900cc0436d7 Jiri Pirko 2015-05-12 1027 key_eth_addrs = skb_flow_dissector_target(flow_dissector,
67a900cc0436d7 Jiri Pirko 2015-05-12 1028 FLOW_DISSECTOR_KEY_ETH_ADDRS,
67a900cc0436d7 Jiri Pirko 2015-05-12 1029 target_container);
67a900cc0436d7 Jiri Pirko 2015-05-12 1030 memcpy(key_eth_addrs, ð->h_dest, sizeof(*key_eth_addrs));
67a900cc0436d7 Jiri Pirko 2015-05-12 1031 }
67a900cc0436d7 Jiri Pirko 2015-05-12 1032
c5ef188e931869 Jiri Pirko 2017-03-06 1033 proto_again:
3a1214e8b06317 Tom Herbert 2017-09-01 1034 fdret = FLOW_DISSECT_RET_CONTINUE;
3a1214e8b06317 Tom Herbert 2017-09-01 1035
0744dd00c1b1be Eric Dumazet 2011-11-28 1036 switch (proto) {
2b8837aeaaa0bb Joe Perches 2014-03-12 1037 case htons(ETH_P_IP): {
0744dd00c1b1be Eric Dumazet 2011-11-28 1038 const struct iphdr *iph;
0744dd00c1b1be Eric Dumazet 2011-11-28 1039 struct iphdr _iph;
3a1214e8b06317 Tom Herbert 2017-09-01 1040
690e36e726d00d David S. Miller 2014-08-23 1041 iph = __skb_header_pointer(skb, nhoff, sizeof(_iph), data, hlen, &_iph);
3a1214e8b06317 Tom Herbert 2017-09-01 1042 if (!iph || iph->ihl < 5) {
3a1214e8b06317 Tom Herbert 2017-09-01 1043 fdret = FLOW_DISSECT_RET_OUT_BAD;
3a1214e8b06317 Tom Herbert 2017-09-01 1044 break;
3a1214e8b06317 Tom Herbert 2017-09-01 1045 }
3a1214e8b06317 Tom Herbert 2017-09-01 1046
3797d3e8462efd Eric Dumazet 2013-11-07 1047 nhoff += iph->ihl * 4;
0744dd00c1b1be Eric Dumazet 2011-11-28 1048
3797d3e8462efd Eric Dumazet 2013-11-07 1049 ip_proto = iph->protocol;
3797d3e8462efd Eric Dumazet 2013-11-07 1050
918c023f29ab2d Alexander Duyck 2016-02-24 1051 if (dissector_uses_key(flow_dissector,
918c023f29ab2d Alexander Duyck 2016-02-24 1052 FLOW_DISSECTOR_KEY_IPV4_ADDRS)) {
06635a35d13d42 Jiri Pirko 2015-05-12 1053 key_addrs = skb_flow_dissector_target(flow_dissector,
918c023f29ab2d Alexander Duyck 2016-02-24 1054 FLOW_DISSECTOR_KEY_IPV4_ADDRS,
918c023f29ab2d Alexander Duyck 2016-02-24 1055 target_container);
918c023f29ab2d Alexander Duyck 2016-02-24 1056
c3f8324188fa80 Tom Herbert 2015-06-04 1057 memcpy(&key_addrs->v4addrs, &iph->saddr,
c3f8324188fa80 Tom Herbert 2015-06-04 1058 sizeof(key_addrs->v4addrs));
c3f8324188fa80 Tom Herbert 2015-06-04 1059 key_control->addr_type = FLOW_DISSECTOR_KEY_IPV4_ADDRS;
918c023f29ab2d Alexander Duyck 2016-02-24 1060 }
807e165dc44fd9 Tom Herbert 2015-09-01 1061
d2126838050ccd Davide Caratti 2021-02-12 1062 __skb_flow_dissect_ipv4(skb, flow_dissector,
d2126838050ccd Davide Caratti 2021-02-12 1063 target_container, data, iph);
d2126838050ccd Davide Caratti 2021-02-12 1064
807e165dc44fd9 Tom Herbert 2015-09-01 1065 if (ip_is_fragment(iph)) {
4b36993d3df083 David S. Miller 2015-09-01 1066 key_control->flags |= FLOW_DIS_IS_FRAGMENT;
807e165dc44fd9 Tom Herbert 2015-09-01 1067
807e165dc44fd9 Tom Herbert 2015-09-01 1068 if (iph->frag_off & htons(IP_OFFSET)) {
3a1214e8b06317 Tom Herbert 2017-09-01 1069 fdret = FLOW_DISSECT_RET_OUT_GOOD;
3a1214e8b06317 Tom Herbert 2017-09-01 1070 break;
807e165dc44fd9 Tom Herbert 2015-09-01 1071 } else {
4b36993d3df083 David S. Miller 2015-09-01 1072 key_control->flags |= FLOW_DIS_FIRST_FRAG;
3a1214e8b06317 Tom Herbert 2017-09-01 1073 if (!(flags &
3a1214e8b06317 Tom Herbert 2017-09-01 1074 FLOW_DISSECTOR_F_PARSE_1ST_FRAG)) {
3a1214e8b06317 Tom Herbert 2017-09-01 1075 fdret = FLOW_DISSECT_RET_OUT_GOOD;
3a1214e8b06317 Tom Herbert 2017-09-01 1076 break;
3a1214e8b06317 Tom Herbert 2017-09-01 1077 }
807e165dc44fd9 Tom Herbert 2015-09-01 1078 }
807e165dc44fd9 Tom Herbert 2015-09-01 1079 }
807e165dc44fd9 Tom Herbert 2015-09-01 1080
0744dd00c1b1be Eric Dumazet 2011-11-28 1081 break;
0744dd00c1b1be Eric Dumazet 2011-11-28 1082 }
2b8837aeaaa0bb Joe Perches 2014-03-12 1083 case htons(ETH_P_IPV6): {
0744dd00c1b1be Eric Dumazet 2011-11-28 1084 const struct ipv6hdr *iph;
0744dd00c1b1be Eric Dumazet 2011-11-28 1085 struct ipv6hdr _iph;
19469a873bafd4 Tom Herbert 2014-07-01 1086
690e36e726d00d David S. Miller 2014-08-23 1087 iph = __skb_header_pointer(skb, nhoff, sizeof(_iph), data, hlen, &_iph);
3a1214e8b06317 Tom Herbert 2017-09-01 1088 if (!iph) {
3a1214e8b06317 Tom Herbert 2017-09-01 1089 fdret = FLOW_DISSECT_RET_OUT_BAD;
3a1214e8b06317 Tom Herbert 2017-09-01 1090 break;
3a1214e8b06317 Tom Herbert 2017-09-01 1091 }
0744dd00c1b1be Eric Dumazet 2011-11-28 1092
0744dd00c1b1be Eric Dumazet 2011-11-28 1093 ip_proto = iph->nexthdr;
0744dd00c1b1be Eric Dumazet 2011-11-28 1094 nhoff += sizeof(struct ipv6hdr);
19469a873bafd4 Tom Herbert 2014-07-01 1095
20a17bf6c04e3e David S. Miller 2015-09-01 1096 if (dissector_uses_key(flow_dissector,
b924933cbbfbdc Jiri Pirko 2015-05-12 1097 FLOW_DISSECTOR_KEY_IPV6_ADDRS)) {
b3c3106ce3f464 Alexander Duyck 2016-02-24 1098 key_addrs = skb_flow_dissector_target(flow_dissector,
b924933cbbfbdc Jiri Pirko 2015-05-12 1099 FLOW_DISSECTOR_KEY_IPV6_ADDRS,
b924933cbbfbdc Jiri Pirko 2015-05-12 1100 target_container);
b924933cbbfbdc Jiri Pirko 2015-05-12 1101
b3c3106ce3f464 Alexander Duyck 2016-02-24 1102 memcpy(&key_addrs->v6addrs, &iph->saddr,
b3c3106ce3f464 Alexander Duyck 2016-02-24 1103 sizeof(key_addrs->v6addrs));
c3f8324188fa80 Tom Herbert 2015-06-04 1104 key_control->addr_type = FLOW_DISSECTOR_KEY_IPV6_ADDRS;
b924933cbbfbdc Jiri Pirko 2015-05-12 1105 }
87ee9e52ffeb16 Tom Herbert 2015-06-04 1106
461547f3158978 Alexander Duyck 2016-02-09 1107 if ((dissector_uses_key(flow_dissector,
461547f3158978 Alexander Duyck 2016-02-09 1108 FLOW_DISSECTOR_KEY_FLOW_LABEL) ||
461547f3158978 Alexander Duyck 2016-02-09 1109 (flags & FLOW_DISSECTOR_F_STOP_AT_FLOW_LABEL)) &&
461547f3158978 Alexander Duyck 2016-02-09 1110 ip6_flowlabel(iph)) {
461547f3158978 Alexander Duyck 2016-02-09 1111 __be32 flow_label = ip6_flowlabel(iph);
461547f3158978 Alexander Duyck 2016-02-09 1112
20a17bf6c04e3e David S. Miller 2015-09-01 1113 if (dissector_uses_key(flow_dissector,
87ee9e52ffeb16 Tom Herbert 2015-06-04 1114 FLOW_DISSECTOR_KEY_FLOW_LABEL)) {
87ee9e52ffeb16 Tom Herbert 2015-06-04 1115 key_tags = skb_flow_dissector_target(flow_dissector,
87ee9e52ffeb16 Tom Herbert 2015-06-04 1116 FLOW_DISSECTOR_KEY_FLOW_LABEL,
06635a35d13d42 Jiri Pirko 2015-05-12 1117 target_container);
87ee9e52ffeb16 Tom Herbert 2015-06-04 1118 key_tags->flow_label = ntohl(flow_label);
12c227ec89a70c Jiri Pirko 2015-05-22 1119 }
3a1214e8b06317 Tom Herbert 2017-09-01 1120 if (flags & FLOW_DISSECTOR_F_STOP_AT_FLOW_LABEL) {
3a1214e8b06317 Tom Herbert 2017-09-01 1121 fdret = FLOW_DISSECT_RET_OUT_GOOD;
3a1214e8b06317 Tom Herbert 2017-09-01 1122 break;
3a1214e8b06317 Tom Herbert 2017-09-01 1123 }
19469a873bafd4 Tom Herbert 2014-07-01 1124 }
19469a873bafd4 Tom Herbert 2014-07-01 1125
518d8a2e9bad83 Or Gerlitz 2017-06-01 1126 __skb_flow_dissect_ipv6(skb, flow_dissector,
518d8a2e9bad83 Or Gerlitz 2017-06-01 1127 target_container, data, iph);
518d8a2e9bad83 Or Gerlitz 2017-06-01 1128
0744dd00c1b1be Eric Dumazet 2011-11-28 1129 break;
0744dd00c1b1be Eric Dumazet 2011-11-28 1130 }
2b8837aeaaa0bb Joe Perches 2014-03-12 1131 case htons(ETH_P_8021AD):
2b8837aeaaa0bb Joe Perches 2014-03-12 1132 case htons(ETH_P_8021Q): {
24c590e3b0f9ee Jianbo Liu 2018-07-06 1133 const struct vlan_hdr *vlan = NULL;
bc72f3dd89e087 Arnd Bergmann 2016-10-24 1134 struct vlan_hdr _vlan;
2064c3d4c02026 Jianbo Liu 2018-07-06 1135 __be16 saved_vlan_tpid = proto;
d5709f7ab77679 Hadar Hen Zion 2016-08-17 1136
24c590e3b0f9ee Jianbo Liu 2018-07-06 1137 if (dissector_vlan == FLOW_DISSECTOR_KEY_MAX &&
24c590e3b0f9ee Jianbo Liu 2018-07-06 1138 skb && skb_vlan_tag_present(skb)) {
d5709f7ab77679 Hadar Hen Zion 2016-08-17 1139 proto = skb->protocol;
24c590e3b0f9ee Jianbo Liu 2018-07-06 1140 } else {
d5709f7ab77679 Hadar Hen Zion 2016-08-17 1141 vlan = __skb_header_pointer(skb, nhoff, sizeof(_vlan),
d5709f7ab77679 Hadar Hen Zion 2016-08-17 1142 data, hlen, &_vlan);
3a1214e8b06317 Tom Herbert 2017-09-01 1143 if (!vlan) {
3a1214e8b06317 Tom Herbert 2017-09-01 1144 fdret = FLOW_DISSECT_RET_OUT_BAD;
3a1214e8b06317 Tom Herbert 2017-09-01 1145 break;
3a1214e8b06317 Tom Herbert 2017-09-01 1146 }
3a1214e8b06317 Tom Herbert 2017-09-01 1147
d5709f7ab77679 Hadar Hen Zion 2016-08-17 1148 proto = vlan->h_vlan_encapsulated_proto;
d5709f7ab77679 Hadar Hen Zion 2016-08-17 1149 nhoff += sizeof(*vlan);
24c590e3b0f9ee Jianbo Liu 2018-07-06 1150 }
24c590e3b0f9ee Jianbo Liu 2018-07-06 1151
24c590e3b0f9ee Jianbo Liu 2018-07-06 1152 if (dissector_vlan == FLOW_DISSECTOR_KEY_MAX) {
24c590e3b0f9ee Jianbo Liu 2018-07-06 1153 dissector_vlan = FLOW_DISSECTOR_KEY_VLAN;
24c590e3b0f9ee Jianbo Liu 2018-07-06 1154 } else if (dissector_vlan == FLOW_DISSECTOR_KEY_VLAN) {
24c590e3b0f9ee Jianbo Liu 2018-07-06 1155 dissector_vlan = FLOW_DISSECTOR_KEY_CVLAN;
24c590e3b0f9ee Jianbo Liu 2018-07-06 1156 } else {
3a1214e8b06317 Tom Herbert 2017-09-01 1157 fdret = FLOW_DISSECT_RET_PROTO_AGAIN;
3a1214e8b06317 Tom Herbert 2017-09-01 1158 break;
3a1214e8b06317 Tom Herbert 2017-09-01 1159 }
0744dd00c1b1be Eric Dumazet 2011-11-28 1160
24c590e3b0f9ee Jianbo Liu 2018-07-06 1161 if (dissector_uses_key(flow_dissector, dissector_vlan)) {
f6a66927692e30 Hadar Hen Zion 2016-08-17 1162 key_vlan = skb_flow_dissector_target(flow_dissector,
24c590e3b0f9ee Jianbo Liu 2018-07-06 1163 dissector_vlan,
d34af823ff401c Tom Herbert 2015-06-04 1164 target_container);
d34af823ff401c Tom Herbert 2015-06-04 1165
24c590e3b0f9ee Jianbo Liu 2018-07-06 1166 if (!vlan) {
f6a66927692e30 Hadar Hen Zion 2016-08-17 1167 key_vlan->vlan_id = skb_vlan_tag_get_id(skb);
9b319148cb34ec Michał Mirosław 2018-11-07 1168 key_vlan->vlan_priority = skb_vlan_tag_get_prio(skb);
f6a66927692e30 Hadar Hen Zion 2016-08-17 1169 } else {
f6a66927692e30 Hadar Hen Zion 2016-08-17 1170 key_vlan->vlan_id = ntohs(vlan->h_vlan_TCI) &
d5709f7ab77679 Hadar Hen Zion 2016-08-17 1171 VLAN_VID_MASK;
f6a66927692e30 Hadar Hen Zion 2016-08-17 1172 key_vlan->vlan_priority =
f6a66927692e30 Hadar Hen Zion 2016-08-17 1173 (ntohs(vlan->h_vlan_TCI) &
f6a66927692e30 Hadar Hen Zion 2016-08-17 1174 VLAN_PRIO_MASK) >> VLAN_PRIO_SHIFT;
f6a66927692e30 Hadar Hen Zion 2016-08-17 1175 }
2064c3d4c02026 Jianbo Liu 2018-07-06 1176 key_vlan->vlan_tpid = saved_vlan_tpid;
d34af823ff401c Tom Herbert 2015-06-04 1177 }
d34af823ff401c Tom Herbert 2015-06-04 1178
3a1214e8b06317 Tom Herbert 2017-09-01 1179 fdret = FLOW_DISSECT_RET_PROTO_AGAIN;
3a1214e8b06317 Tom Herbert 2017-09-01 1180 break;
0744dd00c1b1be Eric Dumazet 2011-11-28 1181 }
2b8837aeaaa0bb Joe Perches 2014-03-12 1182 case htons(ETH_P_PPP_SES): {
0744dd00c1b1be Eric Dumazet 2011-11-28 1183 struct {
0744dd00c1b1be Eric Dumazet 2011-11-28 1184 struct pppoe_hdr hdr;
0744dd00c1b1be Eric Dumazet 2011-11-28 1185 __be16 proto;
0744dd00c1b1be Eric Dumazet 2011-11-28 1186 } *hdr, _hdr;
690e36e726d00d David S. Miller 2014-08-23 1187 hdr = __skb_header_pointer(skb, nhoff, sizeof(_hdr), data, hlen, &_hdr);
3a1214e8b06317 Tom Herbert 2017-09-01 1188 if (!hdr) {
3a1214e8b06317 Tom Herbert 2017-09-01 1189 fdret = FLOW_DISSECT_RET_OUT_BAD;
3a1214e8b06317 Tom Herbert 2017-09-01 1190 break;
3a1214e8b06317 Tom Herbert 2017-09-01 1191 }
3a1214e8b06317 Tom Herbert 2017-09-01 1192
0744dd00c1b1be Eric Dumazet 2011-11-28 1193 proto = hdr->proto;
0744dd00c1b1be Eric Dumazet 2011-11-28 1194 nhoff += PPPOE_SES_HLEN;
0744dd00c1b1be Eric Dumazet 2011-11-28 1195 switch (proto) {
2b8837aeaaa0bb Joe Perches 2014-03-12 1196 case htons(PPP_IP):
3a1214e8b06317 Tom Herbert 2017-09-01 1197 proto = htons(ETH_P_IP);
3a1214e8b06317 Tom Herbert 2017-09-01 1198 fdret = FLOW_DISSECT_RET_PROTO_AGAIN;
3a1214e8b06317 Tom Herbert 2017-09-01 1199 break;
2b8837aeaaa0bb Joe Perches 2014-03-12 1200 case htons(PPP_IPV6):
3a1214e8b06317 Tom Herbert 2017-09-01 1201 proto = htons(ETH_P_IPV6);
3a1214e8b06317 Tom Herbert 2017-09-01 1202 fdret = FLOW_DISSECT_RET_PROTO_AGAIN;
3a1214e8b06317 Tom Herbert 2017-09-01 1203 break;
0744dd00c1b1be Eric Dumazet 2011-11-28 1204 default:
3a1214e8b06317 Tom Herbert 2017-09-01 1205 fdret = FLOW_DISSECT_RET_OUT_BAD;
3a1214e8b06317 Tom Herbert 2017-09-01 1206 break;
0744dd00c1b1be Eric Dumazet 2011-11-28 1207 }
3a1214e8b06317 Tom Herbert 2017-09-01 1208 break;
0744dd00c1b1be Eric Dumazet 2011-11-28 1209 }
08bfc9cb76e26d Erik Hugne 2015-01-22 1210 case htons(ETH_P_TIPC): {
8d6e79d3ce13e3 Jon Maloy 2017-11-08 1211 struct tipc_basic_hdr *hdr, _hdr;
8d6e79d3ce13e3 Jon Maloy 2017-11-08 1212
8d6e79d3ce13e3 Jon Maloy 2017-11-08 1213 hdr = __skb_header_pointer(skb, nhoff, sizeof(_hdr),
8d6e79d3ce13e3 Jon Maloy 2017-11-08 1214 data, hlen, &_hdr);
3a1214e8b06317 Tom Herbert 2017-09-01 1215 if (!hdr) {
3a1214e8b06317 Tom Herbert 2017-09-01 1216 fdret = FLOW_DISSECT_RET_OUT_BAD;
3a1214e8b06317 Tom Herbert 2017-09-01 1217 break;
3a1214e8b06317 Tom Herbert 2017-09-01 1218 }
06635a35d13d42 Jiri Pirko 2015-05-12 1219
20a17bf6c04e3e David S. Miller 2015-09-01 1220 if (dissector_uses_key(flow_dissector,
8d6e79d3ce13e3 Jon Maloy 2017-11-08 1221 FLOW_DISSECTOR_KEY_TIPC)) {
06635a35d13d42 Jiri Pirko 2015-05-12 1222 key_addrs = skb_flow_dissector_target(flow_dissector,
8d6e79d3ce13e3 Jon Maloy 2017-11-08 1223 FLOW_DISSECTOR_KEY_TIPC,
06635a35d13d42 Jiri Pirko 2015-05-12 1224 target_container);
8d6e79d3ce13e3 Jon Maloy 2017-11-08 1225 key_addrs->tipckey.key = tipc_hdr_rps_key(hdr);
8d6e79d3ce13e3 Jon Maloy 2017-11-08 1226 key_control->addr_type = FLOW_DISSECTOR_KEY_TIPC;
06635a35d13d42 Jiri Pirko 2015-05-12 1227 }
3a1214e8b06317 Tom Herbert 2017-09-01 1228 fdret = FLOW_DISSECT_RET_OUT_GOOD;
3a1214e8b06317 Tom Herbert 2017-09-01 1229 break;
08bfc9cb76e26d Erik Hugne 2015-01-22 1230 }
b3baa0fbd02a1a Tom Herbert 2015-06-04 1231
b3baa0fbd02a1a Tom Herbert 2015-06-04 1232 case htons(ETH_P_MPLS_UC):
4a5d6c8b14b81e Jiri Pirko 2017-03-06 1233 case htons(ETH_P_MPLS_MC):
3a1214e8b06317 Tom Herbert 2017-09-01 1234 fdret = __skb_flow_dissect_mpls(skb, flow_dissector,
4a5d6c8b14b81e Jiri Pirko 2017-03-06 1235 target_container, data,
58cff782cc55eb Guillaume Nault 2020-05-26 1236 nhoff, hlen, mpls_lse,
58cff782cc55eb Guillaume Nault 2020-05-26 1237 &mpls_el);
58cff782cc55eb Guillaume Nault 2020-05-26 1238 nhoff += sizeof(struct mpls_label);
58cff782cc55eb Guillaume Nault 2020-05-26 1239 mpls_lse++;
3a1214e8b06317 Tom Herbert 2017-09-01 1240 break;
56193d1bce2b27 Alexander Duyck 2014-09-05 1241 case htons(ETH_P_FCOE):
3a1214e8b06317 Tom Herbert 2017-09-01 1242 if ((hlen - nhoff) < FCOE_HEADER_LEN) {
3a1214e8b06317 Tom Herbert 2017-09-01 1243 fdret = FLOW_DISSECT_RET_OUT_BAD;
3a1214e8b06317 Tom Herbert 2017-09-01 1244 break;
3a1214e8b06317 Tom Herbert 2017-09-01 1245 }
224516b3a798a0 Alexander Duyck 2016-02-24 1246
224516b3a798a0 Alexander Duyck 2016-02-24 1247 nhoff += FCOE_HEADER_LEN;
3a1214e8b06317 Tom Herbert 2017-09-01 1248 fdret = FLOW_DISSECT_RET_OUT_GOOD;
3a1214e8b06317 Tom Herbert 2017-09-01 1249 break;
55733350e5e8b7 Simon Horman 2017-01-11 1250
55733350e5e8b7 Simon Horman 2017-01-11 1251 case htons(ETH_P_ARP):
9bf881ffc5c0e6 Jiri Pirko 2017-03-06 1252 case htons(ETH_P_RARP):
3a1214e8b06317 Tom Herbert 2017-09-01 1253 fdret = __skb_flow_dissect_arp(skb, flow_dissector,
9bf881ffc5c0e6 Jiri Pirko 2017-03-06 1254 target_container, data,
3a1214e8b06317 Tom Herbert 2017-09-01 1255 nhoff, hlen);
3a1214e8b06317 Tom Herbert 2017-09-01 1256 break;
3a1214e8b06317 Tom Herbert 2017-09-01 1257
5b0890a9720462 Sven Eckelmann 2017-12-21 1258 case htons(ETH_P_BATMAN):
5b0890a9720462 Sven Eckelmann 2017-12-21 1259 fdret = __skb_flow_dissect_batadv(skb, key_control, data,
5b0890a9720462 Sven Eckelmann 2017-12-21 1260 &proto, &nhoff, hlen, flags);
5b0890a9720462 Sven Eckelmann 2017-12-21 1261 break;
5b0890a9720462 Sven Eckelmann 2017-12-21 1262
4f1cc51f34886d Eran Ben Elisha 2021-01-12 1263 case htons(ETH_P_1588): {
4f1cc51f34886d Eran Ben Elisha 2021-01-12 1264 struct ptp_header *hdr, _hdr;
4f1cc51f34886d Eran Ben Elisha 2021-01-12 1265
4f1cc51f34886d Eran Ben Elisha 2021-01-12 1266 hdr = __skb_header_pointer(skb, nhoff, sizeof(_hdr), data,
4f1cc51f34886d Eran Ben Elisha 2021-01-12 1267 hlen, &_hdr);
4f1cc51f34886d Eran Ben Elisha 2021-01-12 1268 if (!hdr) {
4f1cc51f34886d Eran Ben Elisha 2021-01-12 1269 fdret = FLOW_DISSECT_RET_OUT_BAD;
4f1cc51f34886d Eran Ben Elisha 2021-01-12 1270 break;
4f1cc51f34886d Eran Ben Elisha 2021-01-12 1271 }
4f1cc51f34886d Eran Ben Elisha 2021-01-12 1272
4f1cc51f34886d Eran Ben Elisha 2021-01-12 1273 nhoff += ntohs(hdr->message_length);
4f1cc51f34886d Eran Ben Elisha 2021-01-12 1274 fdret = FLOW_DISSECT_RET_OUT_GOOD;
4f1cc51f34886d Eran Ben Elisha 2021-01-12 1275 break;
4f1cc51f34886d Eran Ben Elisha 2021-01-12 1276 }
4f1cc51f34886d Eran Ben Elisha 2021-01-12 1277
3a1214e8b06317 Tom Herbert 2017-09-01 1278 default:
3a1214e8b06317 Tom Herbert 2017-09-01 1279 fdret = FLOW_DISSECT_RET_OUT_BAD;
3a1214e8b06317 Tom Herbert 2017-09-01 1280 break;
3a1214e8b06317 Tom Herbert 2017-09-01 1281 }
3a1214e8b06317 Tom Herbert 2017-09-01 1282
3a1214e8b06317 Tom Herbert 2017-09-01 1283 /* Process result of proto processing */
3a1214e8b06317 Tom Herbert 2017-09-01 1284 switch (fdret) {
9bf881ffc5c0e6 Jiri Pirko 2017-03-06 1285 case FLOW_DISSECT_RET_OUT_GOOD:
55733350e5e8b7 Simon Horman 2017-01-11 1286 goto out_good;
3a1214e8b06317 Tom Herbert 2017-09-01 1287 case FLOW_DISSECT_RET_PROTO_AGAIN:
1eed4dfb81b193 Tom Herbert 2017-09-01 1288 if (skb_flow_dissect_allowed(&num_hdrs))
3a1214e8b06317 Tom Herbert 2017-09-01 1289 goto proto_again;
1eed4dfb81b193 Tom Herbert 2017-09-01 1290 goto out_good;
3a1214e8b06317 Tom Herbert 2017-09-01 1291 case FLOW_DISSECT_RET_CONTINUE:
3a1214e8b06317 Tom Herbert 2017-09-01 1292 case FLOW_DISSECT_RET_IPPROTO_AGAIN:
3a1214e8b06317 Tom Herbert 2017-09-01 1293 break;
9bf881ffc5c0e6 Jiri Pirko 2017-03-06 1294 case FLOW_DISSECT_RET_OUT_BAD:
7c92de8eaabfff Jiri Pirko 2017-03-06 1295 default:
9bf881ffc5c0e6 Jiri Pirko 2017-03-06 1296 goto out_bad;
55733350e5e8b7 Simon Horman 2017-01-11 1297 }
0744dd00c1b1be Eric Dumazet 2011-11-28 1298
6a74fcf426f51a Tom Herbert 2015-06-12 1299 ip_proto_again:
3a1214e8b06317 Tom Herbert 2017-09-01 1300 fdret = FLOW_DISSECT_RET_CONTINUE;
3a1214e8b06317 Tom Herbert 2017-09-01 1301
0744dd00c1b1be Eric Dumazet 2011-11-28 1302 switch (ip_proto) {
7c92de8eaabfff Jiri Pirko 2017-03-06 1303 case IPPROTO_GRE:
3a1214e8b06317 Tom Herbert 2017-09-01 1304 fdret = __skb_flow_dissect_gre(skb, key_control, flow_dissector,
7c92de8eaabfff Jiri Pirko 2017-03-06 1305 target_container, data,
3a1214e8b06317 Tom Herbert 2017-09-01 1306 &proto, &nhoff, &hlen, flags);
3a1214e8b06317 Tom Herbert 2017-09-01 1307 break;
3a1214e8b06317 Tom Herbert 2017-09-01 1308
6a74fcf426f51a Tom Herbert 2015-06-12 1309 case NEXTHDR_HOP:
6a74fcf426f51a Tom Herbert 2015-06-12 1310 case NEXTHDR_ROUTING:
6a74fcf426f51a Tom Herbert 2015-06-12 1311 case NEXTHDR_DEST: {
6a74fcf426f51a Tom Herbert 2015-06-12 1312 u8 _opthdr[2], *opthdr;
6a74fcf426f51a Tom Herbert 2015-06-12 1313
6a74fcf426f51a Tom Herbert 2015-06-12 1314 if (proto != htons(ETH_P_IPV6))
6a74fcf426f51a Tom Herbert 2015-06-12 1315 break;
6a74fcf426f51a Tom Herbert 2015-06-12 1316
6a74fcf426f51a Tom Herbert 2015-06-12 1317 opthdr = __skb_header_pointer(skb, nhoff, sizeof(_opthdr),
6a74fcf426f51a Tom Herbert 2015-06-12 1318 data, hlen, &_opthdr);
3a1214e8b06317 Tom Herbert 2017-09-01 1319 if (!opthdr) {
3a1214e8b06317 Tom Herbert 2017-09-01 1320 fdret = FLOW_DISSECT_RET_OUT_BAD;
3a1214e8b06317 Tom Herbert 2017-09-01 1321 break;
3a1214e8b06317 Tom Herbert 2017-09-01 1322 }
6a74fcf426f51a Tom Herbert 2015-06-12 1323
1e98a0f08abddd Eric Dumazet 2015-06-12 1324 ip_proto = opthdr[0];
1e98a0f08abddd Eric Dumazet 2015-06-12 1325 nhoff += (opthdr[1] + 1) << 3;
6a74fcf426f51a Tom Herbert 2015-06-12 1326
3a1214e8b06317 Tom Herbert 2017-09-01 1327 fdret = FLOW_DISSECT_RET_IPPROTO_AGAIN;
3a1214e8b06317 Tom Herbert 2017-09-01 1328 break;
6a74fcf426f51a Tom Herbert 2015-06-12 1329 }
b840f28b908da0 Tom Herbert 2015-09-01 1330 case NEXTHDR_FRAGMENT: {
b840f28b908da0 Tom Herbert 2015-09-01 1331 struct frag_hdr _fh, *fh;
b840f28b908da0 Tom Herbert 2015-09-01 1332
b840f28b908da0 Tom Herbert 2015-09-01 1333 if (proto != htons(ETH_P_IPV6))
b840f28b908da0 Tom Herbert 2015-09-01 1334 break;
b840f28b908da0 Tom Herbert 2015-09-01 1335
b840f28b908da0 Tom Herbert 2015-09-01 1336 fh = __skb_header_pointer(skb, nhoff, sizeof(_fh),
b840f28b908da0 Tom Herbert 2015-09-01 1337 data, hlen, &_fh);
b840f28b908da0 Tom Herbert 2015-09-01 1338
3a1214e8b06317 Tom Herbert 2017-09-01 1339 if (!fh) {
3a1214e8b06317 Tom Herbert 2017-09-01 1340 fdret = FLOW_DISSECT_RET_OUT_BAD;
3a1214e8b06317 Tom Herbert 2017-09-01 1341 break;
3a1214e8b06317 Tom Herbert 2017-09-01 1342 }
b840f28b908da0 Tom Herbert 2015-09-01 1343
4b36993d3df083 David S. Miller 2015-09-01 1344 key_control->flags |= FLOW_DIS_IS_FRAGMENT;
b840f28b908da0 Tom Herbert 2015-09-01 1345
b840f28b908da0 Tom Herbert 2015-09-01 1346 nhoff += sizeof(_fh);
43d2ccb3c122a4 Alexander Duyck 2016-02-24 1347 ip_proto = fh->nexthdr;
b840f28b908da0 Tom Herbert 2015-09-01 1348
b840f28b908da0 Tom Herbert 2015-09-01 1349 if (!(fh->frag_off & htons(IP6_OFFSET))) {
4b36993d3df083 David S. Miller 2015-09-01 1350 key_control->flags |= FLOW_DIS_FIRST_FRAG;
3a1214e8b06317 Tom Herbert 2017-09-01 1351 if (flags & FLOW_DISSECTOR_F_PARSE_1ST_FRAG) {
3a1214e8b06317 Tom Herbert 2017-09-01 1352 fdret = FLOW_DISSECT_RET_IPPROTO_AGAIN;
3a1214e8b06317 Tom Herbert 2017-09-01 1353 break;
b840f28b908da0 Tom Herbert 2015-09-01 1354 }
3a1214e8b06317 Tom Herbert 2017-09-01 1355 }
3a1214e8b06317 Tom Herbert 2017-09-01 1356
3a1214e8b06317 Tom Herbert 2017-09-01 1357 fdret = FLOW_DISSECT_RET_OUT_GOOD;
3a1214e8b06317 Tom Herbert 2017-09-01 1358 break;
b840f28b908da0 Tom Herbert 2015-09-01 1359 }
0744dd00c1b1be Eric Dumazet 2011-11-28 1360 case IPPROTO_IPIP:
fca418955148e4 Tom Herbert 2013-07-29 1361 proto = htons(ETH_P_IP);
823b96939578ea Tom Herbert 2015-09-01 1362
4b36993d3df083 David S. Miller 2015-09-01 1363 key_control->flags |= FLOW_DIS_ENCAPSULATION;
3a1214e8b06317 Tom Herbert 2017-09-01 1364 if (flags & FLOW_DISSECTOR_F_STOP_AT_ENCAP) {
3a1214e8b06317 Tom Herbert 2017-09-01 1365 fdret = FLOW_DISSECT_RET_OUT_GOOD;
3a1214e8b06317 Tom Herbert 2017-09-01 1366 break;
3a1214e8b06317 Tom Herbert 2017-09-01 1367 }
3a1214e8b06317 Tom Herbert 2017-09-01 1368
3a1214e8b06317 Tom Herbert 2017-09-01 1369 fdret = FLOW_DISSECT_RET_PROTO_AGAIN;
3a1214e8b06317 Tom Herbert 2017-09-01 1370 break;
823b96939578ea Tom Herbert 2015-09-01 1371
b438f940d3541f Tom Herbert 2013-07-29 1372 case IPPROTO_IPV6:
b438f940d3541f Tom Herbert 2013-07-29 1373 proto = htons(ETH_P_IPV6);
823b96939578ea Tom Herbert 2015-09-01 1374
4b36993d3df083 David S. Miller 2015-09-01 1375 key_control->flags |= FLOW_DIS_ENCAPSULATION;
3a1214e8b06317 Tom Herbert 2017-09-01 1376 if (flags & FLOW_DISSECTOR_F_STOP_AT_ENCAP) {
3a1214e8b06317 Tom Herbert 2017-09-01 1377 fdret = FLOW_DISSECT_RET_OUT_GOOD;
3a1214e8b06317 Tom Herbert 2017-09-01 1378 break;
3a1214e8b06317 Tom Herbert 2017-09-01 1379 }
3a1214e8b06317 Tom Herbert 2017-09-01 1380
3a1214e8b06317 Tom Herbert 2017-09-01 1381 fdret = FLOW_DISSECT_RET_PROTO_AGAIN;
3a1214e8b06317 Tom Herbert 2017-09-01 1382 break;
3a1214e8b06317 Tom Herbert 2017-09-01 1383
823b96939578ea Tom Herbert 2015-09-01 1384
b3baa0fbd02a1a Tom Herbert 2015-06-04 1385 case IPPROTO_MPLS:
b3baa0fbd02a1a Tom Herbert 2015-06-04 1386 proto = htons(ETH_P_MPLS_UC);
3a1214e8b06317 Tom Herbert 2017-09-01 1387 fdret = FLOW_DISSECT_RET_PROTO_AGAIN;
3a1214e8b06317 Tom Herbert 2017-09-01 1388 break;
3a1214e8b06317 Tom Herbert 2017-09-01 1389
ac4bb5de27010e Jiri Pirko 2017-05-23 1390 case IPPROTO_TCP:
ac4bb5de27010e Jiri Pirko 2017-05-23 1391 __skb_flow_dissect_tcp(skb, flow_dissector, target_container,
ac4bb5de27010e Jiri Pirko 2017-05-23 1392 data, nhoff, hlen);
ac4bb5de27010e Jiri Pirko 2017-05-23 1393 break;
3a1214e8b06317 Tom Herbert 2017-09-01 1394
3b336d6f4ec690 Matteo Croce 2019-10-29 1395 case IPPROTO_ICMP:
3b336d6f4ec690 Matteo Croce 2019-10-29 1396 case IPPROTO_ICMPV6:
3b336d6f4ec690 Matteo Croce 2019-10-29 1397 __skb_flow_dissect_icmp(skb, flow_dissector, target_container,
3b336d6f4ec690 Matteo Croce 2019-10-29 1398 data, nhoff, hlen);
3b336d6f4ec690 Matteo Croce 2019-10-29 1399 break;
3b336d6f4ec690 Matteo Croce 2019-10-29 1400
0744dd00c1b1be Eric Dumazet 2011-11-28 1401 default:
0744dd00c1b1be Eric Dumazet 2011-11-28 1402 break;
0744dd00c1b1be Eric Dumazet 2011-11-28 1403 }
0744dd00c1b1be Eric Dumazet 2011-11-28 1404
8ffb055beae585 Yoshiki Komachi 2019-12-03 1405 if (!(key_control->flags & FLOW_DIS_IS_FRAGMENT))
8ffb055beae585 Yoshiki Komachi 2019-12-03 1406 __skb_flow_dissect_ports(skb, flow_dissector, target_container,
8ffb055beae585 Yoshiki Komachi 2019-12-03 1407 data, nhoff, ip_proto, hlen);
5af7fb6e3e92c2 Alexander Duyck 2014-10-10 1408
3a1214e8b06317 Tom Herbert 2017-09-01 1409 /* Process result of IP proto processing */
3a1214e8b06317 Tom Herbert 2017-09-01 1410 switch (fdret) {
3a1214e8b06317 Tom Herbert 2017-09-01 1411 case FLOW_DISSECT_RET_PROTO_AGAIN:
1eed4dfb81b193 Tom Herbert 2017-09-01 1412 if (skb_flow_dissect_allowed(&num_hdrs))
3a1214e8b06317 Tom Herbert 2017-09-01 1413 goto proto_again;
1eed4dfb81b193 Tom Herbert 2017-09-01 1414 break;
3a1214e8b06317 Tom Herbert 2017-09-01 1415 case FLOW_DISSECT_RET_IPPROTO_AGAIN:
1eed4dfb81b193 Tom Herbert 2017-09-01 1416 if (skb_flow_dissect_allowed(&num_hdrs))
3a1214e8b06317 Tom Herbert 2017-09-01 1417 goto ip_proto_again;
1eed4dfb81b193 Tom Herbert 2017-09-01 1418 break;
3a1214e8b06317 Tom Herbert 2017-09-01 1419 case FLOW_DISSECT_RET_OUT_GOOD:
3a1214e8b06317 Tom Herbert 2017-09-01 1420 case FLOW_DISSECT_RET_CONTINUE:
3a1214e8b06317 Tom Herbert 2017-09-01 1421 break;
3a1214e8b06317 Tom Herbert 2017-09-01 1422 case FLOW_DISSECT_RET_OUT_BAD:
3a1214e8b06317 Tom Herbert 2017-09-01 1423 default:
3a1214e8b06317 Tom Herbert 2017-09-01 1424 goto out_bad;
3a1214e8b06317 Tom Herbert 2017-09-01 1425 }
3a1214e8b06317 Tom Herbert 2017-09-01 1426
a6e544b0a88b53 Tom Herbert 2015-09-01 1427 out_good:
a6e544b0a88b53 Tom Herbert 2015-09-01 1428 ret = true;
a6e544b0a88b53 Tom Herbert 2015-09-01 1429
34fad54c2537f7 Eric Dumazet 2016-11-09 1430 out:
d0c081b49137cd Eric Dumazet 2018-01-17 1431 key_control->thoff = min_t(u16, nhoff, skb ? skb->len : hlen);
a6e544b0a88b53 Tom Herbert 2015-09-01 1432 key_basic->n_proto = proto;
a6e544b0a88b53 Tom Herbert 2015-09-01 1433 key_basic->ip_proto = ip_proto;
a6e544b0a88b53 Tom Herbert 2015-09-01 1434
a6e544b0a88b53 Tom Herbert 2015-09-01 1435 return ret;
34fad54c2537f7 Eric Dumazet 2016-11-09 1436
34fad54c2537f7 Eric Dumazet 2016-11-09 1437 out_bad:
34fad54c2537f7 Eric Dumazet 2016-11-09 1438 ret = false;
34fad54c2537f7 Eric Dumazet 2016-11-09 1439 goto out;
0744dd00c1b1be Eric Dumazet 2011-11-28 1440 }
690e36e726d00d David S. Miller 2014-08-23 1441 EXPORT_SYMBOL(__skb_flow_dissect);
441d9d327f1e77 Cong Wang 2013-01-21 1442
:::::: The code at line 835 was first introduced by commit
:::::: d58e468b1112dcd1d5193c0a89ff9f98b5a3e8b9 flow_dissector: implements flow dissector BPF hook
:::::: TO: Petar Penkov <ppenkov@...gle.com>
:::::: CC: Alexei Starovoitov <ast@...nel.org>
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org
Download attachment ".config.gz" of type "application/gzip" (32597 bytes)
Powered by blists - more mailing lists