cls_flower.c (d053cf0d771f6547cb0537759a9af63cf402908d) | cls_flower.c (0af413bd3e2de73bcf0742ed556be4af83c71964) |
---|---|
1// SPDX-License-Identifier: GPL-2.0-or-later 2/* 3 * net/sched/cls_flower.c Flower classifier 4 * 5 * Copyright (c) 2015 Jiri Pirko <jiri@resnulli.us> 6 */ 7 8#include <linux/kernel.h> --- 258 unchanged lines hidden (view full) --- 267 268 f = __fl_lookup(mask, mkey); 269 if (f) 270 return f; 271 } 272 return NULL; 273} 274 | 1// SPDX-License-Identifier: GPL-2.0-or-later 2/* 3 * net/sched/cls_flower.c Flower classifier 4 * 5 * Copyright (c) 2015 Jiri Pirko <jiri@resnulli.us> 6 */ 7 8#include <linux/kernel.h> --- 258 unchanged lines hidden (view full) --- 267 268 f = __fl_lookup(mask, mkey); 269 if (f) 270 return f; 271 } 272 return NULL; 273} 274 |
275static struct cls_fl_filter *fl_lookup(struct fl_flow_mask *mask, 276 struct fl_flow_key *mkey, 277 struct fl_flow_key *key) | 275static noinline_for_stack 276struct cls_fl_filter *fl_mask_lookup(struct fl_flow_mask *mask, struct fl_flow_key *key) |
278{ | 277{ |
278 struct fl_flow_key mkey; 279 280 fl_set_masked_key(&mkey, key, mask); |
|
279 if ((mask->flags & TCA_FLOWER_MASK_FLAGS_RANGE)) | 281 if ((mask->flags & TCA_FLOWER_MASK_FLAGS_RANGE)) |
280 return fl_lookup_range(mask, mkey, key); | 282 return fl_lookup_range(mask, &mkey, key); |
281 | 283 |
282 return __fl_lookup(mask, mkey); | 284 return __fl_lookup(mask, &mkey); |
283} 284 285static u16 fl_ct_info_to_flower_map[] = { 286 [IP_CT_ESTABLISHED] = TCA_FLOWER_KEY_CT_FLAGS_TRACKED | 287 TCA_FLOWER_KEY_CT_FLAGS_ESTABLISHED, 288 [IP_CT_RELATED] = TCA_FLOWER_KEY_CT_FLAGS_TRACKED | 289 TCA_FLOWER_KEY_CT_FLAGS_RELATED, 290 [IP_CT_ESTABLISHED_REPLY] = TCA_FLOWER_KEY_CT_FLAGS_TRACKED | 291 TCA_FLOWER_KEY_CT_FLAGS_ESTABLISHED, 292 [IP_CT_RELATED_REPLY] = TCA_FLOWER_KEY_CT_FLAGS_TRACKED | 293 TCA_FLOWER_KEY_CT_FLAGS_RELATED, 294 [IP_CT_NEW] = TCA_FLOWER_KEY_CT_FLAGS_TRACKED | 295 TCA_FLOWER_KEY_CT_FLAGS_NEW, 296}; 297 298static int fl_classify(struct sk_buff *skb, const struct tcf_proto *tp, 299 struct tcf_result *res) 300{ 301 struct cls_fl_head *head = rcu_dereference_bh(tp->root); | 285} 286 287static u16 fl_ct_info_to_flower_map[] = { 288 [IP_CT_ESTABLISHED] = TCA_FLOWER_KEY_CT_FLAGS_TRACKED | 289 TCA_FLOWER_KEY_CT_FLAGS_ESTABLISHED, 290 [IP_CT_RELATED] = TCA_FLOWER_KEY_CT_FLAGS_TRACKED | 291 TCA_FLOWER_KEY_CT_FLAGS_RELATED, 292 [IP_CT_ESTABLISHED_REPLY] = TCA_FLOWER_KEY_CT_FLAGS_TRACKED | 293 TCA_FLOWER_KEY_CT_FLAGS_ESTABLISHED, 294 [IP_CT_RELATED_REPLY] = TCA_FLOWER_KEY_CT_FLAGS_TRACKED | 295 TCA_FLOWER_KEY_CT_FLAGS_RELATED, 296 [IP_CT_NEW] = TCA_FLOWER_KEY_CT_FLAGS_TRACKED | 297 TCA_FLOWER_KEY_CT_FLAGS_NEW, 298}; 299 300static int fl_classify(struct sk_buff *skb, const struct tcf_proto *tp, 301 struct tcf_result *res) 302{ 303 struct cls_fl_head *head = rcu_dereference_bh(tp->root); |
302 struct fl_flow_key skb_mkey; | |
303 struct fl_flow_key skb_key; 304 struct fl_flow_mask *mask; 305 struct cls_fl_filter *f; 306 307 list_for_each_entry_rcu(mask, &head->masks, list) { 308 flow_dissector_init_keys(&skb_key.control, &skb_key.basic); 309 fl_clear_masked_range(&skb_key, mask); 310 311 skb_flow_dissect_meta(skb, &mask->dissector, &skb_key); 312 /* skb_flow_dissect() does not set n_proto in case an unknown 313 * protocol, so do it rather here. 314 */ 315 skb_key.basic.n_proto = skb->protocol; 316 skb_flow_dissect_tunnel_info(skb, &mask->dissector, &skb_key); 317 skb_flow_dissect_ct(skb, &mask->dissector, &skb_key, 318 fl_ct_info_to_flower_map, 319 ARRAY_SIZE(fl_ct_info_to_flower_map)); 320 skb_flow_dissect(skb, &mask->dissector, &skb_key, 0); 321 | 304 struct fl_flow_key skb_key; 305 struct fl_flow_mask *mask; 306 struct cls_fl_filter *f; 307 308 list_for_each_entry_rcu(mask, &head->masks, list) { 309 flow_dissector_init_keys(&skb_key.control, &skb_key.basic); 310 fl_clear_masked_range(&skb_key, mask); 311 312 skb_flow_dissect_meta(skb, &mask->dissector, &skb_key); 313 /* skb_flow_dissect() does not set n_proto in case an unknown 314 * protocol, so do it rather here. 315 */ 316 skb_key.basic.n_proto = skb->protocol; 317 skb_flow_dissect_tunnel_info(skb, &mask->dissector, &skb_key); 318 skb_flow_dissect_ct(skb, &mask->dissector, &skb_key, 319 fl_ct_info_to_flower_map, 320 ARRAY_SIZE(fl_ct_info_to_flower_map)); 321 skb_flow_dissect(skb, &mask->dissector, &skb_key, 0); 322 |
322 fl_set_masked_key(&skb_mkey, &skb_key, mask); 323 324 f = fl_lookup(mask, &skb_mkey, &skb_key); | 323 f = fl_mask_lookup(mask, &skb_key); |
325 if (f && !tc_skip_sw(f->flags)) { 326 *res = f->res; 327 return tcf_exts_exec(skb, &f->exts, res); 328 } 329 } 330 return -1; 331} 332 --- 330 unchanged lines hidden (view full) --- 663 [TCA_FLOWER_KEY_ARP_SHA] = { .len = ETH_ALEN }, 664 [TCA_FLOWER_KEY_ARP_SHA_MASK] = { .len = ETH_ALEN }, 665 [TCA_FLOWER_KEY_ARP_THA] = { .len = ETH_ALEN }, 666 [TCA_FLOWER_KEY_ARP_THA_MASK] = { .len = ETH_ALEN }, 667 [TCA_FLOWER_KEY_MPLS_TTL] = { .type = NLA_U8 }, 668 [TCA_FLOWER_KEY_MPLS_BOS] = { .type = NLA_U8 }, 669 [TCA_FLOWER_KEY_MPLS_TC] = { .type = NLA_U8 }, 670 [TCA_FLOWER_KEY_MPLS_LABEL] = { .type = NLA_U32 }, | 324 if (f && !tc_skip_sw(f->flags)) { 325 *res = f->res; 326 return tcf_exts_exec(skb, &f->exts, res); 327 } 328 } 329 return -1; 330} 331 --- 330 unchanged lines hidden (view full) --- 662 [TCA_FLOWER_KEY_ARP_SHA] = { .len = ETH_ALEN }, 663 [TCA_FLOWER_KEY_ARP_SHA_MASK] = { .len = ETH_ALEN }, 664 [TCA_FLOWER_KEY_ARP_THA] = { .len = ETH_ALEN }, 665 [TCA_FLOWER_KEY_ARP_THA_MASK] = { .len = ETH_ALEN }, 666 [TCA_FLOWER_KEY_MPLS_TTL] = { .type = NLA_U8 }, 667 [TCA_FLOWER_KEY_MPLS_BOS] = { .type = NLA_U8 }, 668 [TCA_FLOWER_KEY_MPLS_TC] = { .type = NLA_U8 }, 669 [TCA_FLOWER_KEY_MPLS_LABEL] = { .type = NLA_U32 }, |
670 [TCA_FLOWER_KEY_MPLS_OPTS] = { .type = NLA_NESTED }, |
|
671 [TCA_FLOWER_KEY_TCP_FLAGS] = { .type = NLA_U16 }, 672 [TCA_FLOWER_KEY_TCP_FLAGS_MASK] = { .type = NLA_U16 }, 673 [TCA_FLOWER_KEY_IP_TOS] = { .type = NLA_U8 }, 674 [TCA_FLOWER_KEY_IP_TOS_MASK] = { .type = NLA_U8 }, 675 [TCA_FLOWER_KEY_IP_TTL] = { .type = NLA_U8 }, 676 [TCA_FLOWER_KEY_IP_TTL_MASK] = { .type = NLA_U8 }, 677 [TCA_FLOWER_KEY_CVLAN_ID] = { .type = NLA_U16 }, 678 [TCA_FLOWER_KEY_CVLAN_PRIO] = { .type = NLA_U8 }, --- 42 unchanged lines hidden (view full) --- 721static const struct nla_policy 722erspan_opt_policy[TCA_FLOWER_KEY_ENC_OPT_ERSPAN_MAX + 1] = { 723 [TCA_FLOWER_KEY_ENC_OPT_ERSPAN_VER] = { .type = NLA_U8 }, 724 [TCA_FLOWER_KEY_ENC_OPT_ERSPAN_INDEX] = { .type = NLA_U32 }, 725 [TCA_FLOWER_KEY_ENC_OPT_ERSPAN_DIR] = { .type = NLA_U8 }, 726 [TCA_FLOWER_KEY_ENC_OPT_ERSPAN_HWID] = { .type = NLA_U8 }, 727}; 728 | 671 [TCA_FLOWER_KEY_TCP_FLAGS] = { .type = NLA_U16 }, 672 [TCA_FLOWER_KEY_TCP_FLAGS_MASK] = { .type = NLA_U16 }, 673 [TCA_FLOWER_KEY_IP_TOS] = { .type = NLA_U8 }, 674 [TCA_FLOWER_KEY_IP_TOS_MASK] = { .type = NLA_U8 }, 675 [TCA_FLOWER_KEY_IP_TTL] = { .type = NLA_U8 }, 676 [TCA_FLOWER_KEY_IP_TTL_MASK] = { .type = NLA_U8 }, 677 [TCA_FLOWER_KEY_CVLAN_ID] = { .type = NLA_U16 }, 678 [TCA_FLOWER_KEY_CVLAN_PRIO] = { .type = NLA_U8 }, --- 42 unchanged lines hidden (view full) --- 721static const struct nla_policy 722erspan_opt_policy[TCA_FLOWER_KEY_ENC_OPT_ERSPAN_MAX + 1] = { 723 [TCA_FLOWER_KEY_ENC_OPT_ERSPAN_VER] = { .type = NLA_U8 }, 724 [TCA_FLOWER_KEY_ENC_OPT_ERSPAN_INDEX] = { .type = NLA_U32 }, 725 [TCA_FLOWER_KEY_ENC_OPT_ERSPAN_DIR] = { .type = NLA_U8 }, 726 [TCA_FLOWER_KEY_ENC_OPT_ERSPAN_HWID] = { .type = NLA_U8 }, 727}; 728 |
729static const struct nla_policy 730mpls_opts_policy[TCA_FLOWER_KEY_MPLS_OPTS_MAX + 1] = { 731 [TCA_FLOWER_KEY_MPLS_OPTS_LSE] = { .type = NLA_NESTED }, 732}; 733 734static const struct nla_policy 735mpls_stack_entry_policy[TCA_FLOWER_KEY_MPLS_OPT_LSE_MAX + 1] = { 736 [TCA_FLOWER_KEY_MPLS_OPT_LSE_DEPTH] = { .type = NLA_U8 }, 737 [TCA_FLOWER_KEY_MPLS_OPT_LSE_TTL] = { .type = NLA_U8 }, 738 [TCA_FLOWER_KEY_MPLS_OPT_LSE_BOS] = { .type = NLA_U8 }, 739 [TCA_FLOWER_KEY_MPLS_OPT_LSE_TC] = { .type = NLA_U8 }, 740 [TCA_FLOWER_KEY_MPLS_OPT_LSE_LABEL] = { .type = NLA_U32 }, 741}; 742 |
|
729static void fl_set_key_val(struct nlattr **tb, 730 void *val, int val_type, 731 void *mask, int mask_type, int len) 732{ 733 if (!tb[val_type]) 734 return; 735 nla_memcpy(val, tb[val_type], len); 736 if (mask_type == TCA_FLOWER_UNSPEC || !tb[mask_type]) --- 34 unchanged lines hidden (view full) --- 771 tb[TCA_FLOWER_KEY_PORT_SRC_MIN], 772 "Invalid source port range (min must be strictly smaller than max)"); 773 return -EINVAL; 774 } 775 776 return 0; 777} 778 | 743static void fl_set_key_val(struct nlattr **tb, 744 void *val, int val_type, 745 void *mask, int mask_type, int len) 746{ 747 if (!tb[val_type]) 748 return; 749 nla_memcpy(val, tb[val_type], len); 750 if (mask_type == TCA_FLOWER_UNSPEC || !tb[mask_type]) --- 34 unchanged lines hidden (view full) --- 785 tb[TCA_FLOWER_KEY_PORT_SRC_MIN], 786 "Invalid source port range (min must be strictly smaller than max)"); 787 return -EINVAL; 788 } 789 790 return 0; 791} 792 |
793static int fl_set_key_mpls_lse(const struct nlattr *nla_lse, 794 struct flow_dissector_key_mpls *key_val, 795 struct flow_dissector_key_mpls *key_mask, 796 struct netlink_ext_ack *extack) 797{ 798 struct nlattr *tb[TCA_FLOWER_KEY_MPLS_OPT_LSE_MAX + 1]; 799 struct flow_dissector_mpls_lse *lse_mask; 800 struct flow_dissector_mpls_lse *lse_val; 801 u8 lse_index; 802 u8 depth; 803 int err; 804 805 err = nla_parse_nested(tb, TCA_FLOWER_KEY_MPLS_OPT_LSE_MAX, nla_lse, 806 mpls_stack_entry_policy, extack); 807 if (err < 0) 808 return err; 809 810 if (!tb[TCA_FLOWER_KEY_MPLS_OPT_LSE_DEPTH]) { 811 NL_SET_ERR_MSG(extack, "Missing MPLS option \"depth\""); 812 return -EINVAL; 813 } 814 815 depth = nla_get_u8(tb[TCA_FLOWER_KEY_MPLS_OPT_LSE_DEPTH]); 816 817 /* LSE depth starts at 1, for consistency with terminology used by 818 * RFC 3031 (section 3.9), where depth 0 refers to unlabeled packets. 819 */ 820 if (depth < 1 || depth > FLOW_DIS_MPLS_MAX) { 821 NL_SET_ERR_MSG_ATTR(extack, 822 tb[TCA_FLOWER_KEY_MPLS_OPT_LSE_DEPTH], 823 "Invalid MPLS depth"); 824 return -EINVAL; 825 } 826 lse_index = depth - 1; 827 828 dissector_set_mpls_lse(key_val, lse_index); 829 dissector_set_mpls_lse(key_mask, lse_index); 830 831 lse_val = &key_val->ls[lse_index]; 832 lse_mask = &key_mask->ls[lse_index]; 833 834 if (tb[TCA_FLOWER_KEY_MPLS_OPT_LSE_TTL]) { 835 lse_val->mpls_ttl = nla_get_u8(tb[TCA_FLOWER_KEY_MPLS_OPT_LSE_TTL]); 836 lse_mask->mpls_ttl = MPLS_TTL_MASK; 837 } 838 if (tb[TCA_FLOWER_KEY_MPLS_OPT_LSE_BOS]) { 839 u8 bos = nla_get_u8(tb[TCA_FLOWER_KEY_MPLS_OPT_LSE_BOS]); 840 841 if (bos & ~MPLS_BOS_MASK) { 842 NL_SET_ERR_MSG_ATTR(extack, 843 tb[TCA_FLOWER_KEY_MPLS_OPT_LSE_BOS], 844 "Bottom Of Stack (BOS) must be 0 or 1"); 845 return -EINVAL; 846 } 847 lse_val->mpls_bos = bos; 848 lse_mask->mpls_bos = MPLS_BOS_MASK; 849 } 850 if (tb[TCA_FLOWER_KEY_MPLS_OPT_LSE_TC]) { 851 u8 tc = nla_get_u8(tb[TCA_FLOWER_KEY_MPLS_OPT_LSE_TC]); 852 853 if (tc & ~MPLS_TC_MASK) { 854 NL_SET_ERR_MSG_ATTR(extack, 855 tb[TCA_FLOWER_KEY_MPLS_OPT_LSE_TC], 856 "Traffic Class (TC) must be between 0 and 7"); 857 return -EINVAL; 858 } 859 lse_val->mpls_tc = tc; 860 lse_mask->mpls_tc = MPLS_TC_MASK; 861 } 862 if (tb[TCA_FLOWER_KEY_MPLS_OPT_LSE_LABEL]) { 863 u32 label = nla_get_u32(tb[TCA_FLOWER_KEY_MPLS_OPT_LSE_LABEL]); 864 865 if (label & ~MPLS_LABEL_MASK) { 866 NL_SET_ERR_MSG_ATTR(extack, 867 tb[TCA_FLOWER_KEY_MPLS_OPT_LSE_LABEL], 868 "Label must be between 0 and 1048575"); 869 return -EINVAL; 870 } 871 lse_val->mpls_label = label; 872 lse_mask->mpls_label = MPLS_LABEL_MASK; 873 } 874 875 return 0; 876} 877 878static int fl_set_key_mpls_opts(const struct nlattr *nla_mpls_opts, 879 struct flow_dissector_key_mpls *key_val, 880 struct flow_dissector_key_mpls *key_mask, 881 struct netlink_ext_ack *extack) 882{ 883 struct nlattr *nla_lse; 884 int rem; 885 int err; 886 887 if (!(nla_mpls_opts->nla_type & NLA_F_NESTED)) { 888 NL_SET_ERR_MSG_ATTR(extack, nla_mpls_opts, 889 "NLA_F_NESTED is missing"); 890 return -EINVAL; 891 } 892 893 nla_for_each_nested(nla_lse, nla_mpls_opts, rem) { 894 if (nla_type(nla_lse) != TCA_FLOWER_KEY_MPLS_OPTS_LSE) { 895 NL_SET_ERR_MSG_ATTR(extack, nla_lse, 896 "Invalid MPLS option type"); 897 return -EINVAL; 898 } 899 900 err = fl_set_key_mpls_lse(nla_lse, key_val, key_mask, extack); 901 if (err < 0) 902 return err; 903 } 904 if (rem) { 905 NL_SET_ERR_MSG(extack, 906 "Bytes leftover after parsing MPLS options"); 907 return -EINVAL; 908 } 909 910 return 0; 911} 912 |
|
779static int fl_set_key_mpls(struct nlattr **tb, 780 struct flow_dissector_key_mpls *key_val, 781 struct flow_dissector_key_mpls *key_mask, 782 struct netlink_ext_ack *extack) 783{ | 913static int fl_set_key_mpls(struct nlattr **tb, 914 struct flow_dissector_key_mpls *key_val, 915 struct flow_dissector_key_mpls *key_mask, 916 struct netlink_ext_ack *extack) 917{ |
918 struct flow_dissector_mpls_lse *lse_mask; 919 struct flow_dissector_mpls_lse *lse_val; 920 921 if (tb[TCA_FLOWER_KEY_MPLS_OPTS]) { 922 if (tb[TCA_FLOWER_KEY_MPLS_TTL] || 923 tb[TCA_FLOWER_KEY_MPLS_BOS] || 924 tb[TCA_FLOWER_KEY_MPLS_TC] || 925 tb[TCA_FLOWER_KEY_MPLS_LABEL]) { 926 NL_SET_ERR_MSG_ATTR(extack, 927 tb[TCA_FLOWER_KEY_MPLS_OPTS], 928 "MPLS label, Traffic Class, Bottom Of Stack and Time To Live must be encapsulated in the MPLS options attribute"); 929 return -EBADMSG; 930 } 931 932 return fl_set_key_mpls_opts(tb[TCA_FLOWER_KEY_MPLS_OPTS], 933 key_val, key_mask, extack); 934 } 935 936 lse_val = &key_val->ls[0]; 937 lse_mask = &key_mask->ls[0]; 938 |
|
784 if (tb[TCA_FLOWER_KEY_MPLS_TTL]) { | 939 if (tb[TCA_FLOWER_KEY_MPLS_TTL]) { |
785 key_val->mpls_ttl = nla_get_u8(tb[TCA_FLOWER_KEY_MPLS_TTL]); 786 key_mask->mpls_ttl = MPLS_TTL_MASK; | 940 lse_val->mpls_ttl = nla_get_u8(tb[TCA_FLOWER_KEY_MPLS_TTL]); 941 lse_mask->mpls_ttl = MPLS_TTL_MASK; 942 dissector_set_mpls_lse(key_val, 0); 943 dissector_set_mpls_lse(key_mask, 0); |
787 } 788 if (tb[TCA_FLOWER_KEY_MPLS_BOS]) { 789 u8 bos = nla_get_u8(tb[TCA_FLOWER_KEY_MPLS_BOS]); 790 791 if (bos & ~MPLS_BOS_MASK) { 792 NL_SET_ERR_MSG_ATTR(extack, 793 tb[TCA_FLOWER_KEY_MPLS_BOS], 794 "Bottom Of Stack (BOS) must be 0 or 1"); 795 return -EINVAL; 796 } | 944 } 945 if (tb[TCA_FLOWER_KEY_MPLS_BOS]) { 946 u8 bos = nla_get_u8(tb[TCA_FLOWER_KEY_MPLS_BOS]); 947 948 if (bos & ~MPLS_BOS_MASK) { 949 NL_SET_ERR_MSG_ATTR(extack, 950 tb[TCA_FLOWER_KEY_MPLS_BOS], 951 "Bottom Of Stack (BOS) must be 0 or 1"); 952 return -EINVAL; 953 } |
797 key_val->mpls_bos = bos; 798 key_mask->mpls_bos = MPLS_BOS_MASK; | 954 lse_val->mpls_bos = bos; 955 lse_mask->mpls_bos = MPLS_BOS_MASK; 956 dissector_set_mpls_lse(key_val, 0); 957 dissector_set_mpls_lse(key_mask, 0); |
799 } 800 if (tb[TCA_FLOWER_KEY_MPLS_TC]) { 801 u8 tc = nla_get_u8(tb[TCA_FLOWER_KEY_MPLS_TC]); 802 803 if (tc & ~MPLS_TC_MASK) { 804 NL_SET_ERR_MSG_ATTR(extack, 805 tb[TCA_FLOWER_KEY_MPLS_TC], 806 "Traffic Class (TC) must be between 0 and 7"); 807 return -EINVAL; 808 } | 958 } 959 if (tb[TCA_FLOWER_KEY_MPLS_TC]) { 960 u8 tc = nla_get_u8(tb[TCA_FLOWER_KEY_MPLS_TC]); 961 962 if (tc & ~MPLS_TC_MASK) { 963 NL_SET_ERR_MSG_ATTR(extack, 964 tb[TCA_FLOWER_KEY_MPLS_TC], 965 "Traffic Class (TC) must be between 0 and 7"); 966 return -EINVAL; 967 } |
809 key_val->mpls_tc = tc; 810 key_mask->mpls_tc = MPLS_TC_MASK; | 968 lse_val->mpls_tc = tc; 969 lse_mask->mpls_tc = MPLS_TC_MASK; 970 dissector_set_mpls_lse(key_val, 0); 971 dissector_set_mpls_lse(key_mask, 0); |
811 } 812 if (tb[TCA_FLOWER_KEY_MPLS_LABEL]) { 813 u32 label = nla_get_u32(tb[TCA_FLOWER_KEY_MPLS_LABEL]); 814 815 if (label & ~MPLS_LABEL_MASK) { 816 NL_SET_ERR_MSG_ATTR(extack, 817 tb[TCA_FLOWER_KEY_MPLS_LABEL], 818 "Label must be between 0 and 1048575"); 819 return -EINVAL; 820 } | 972 } 973 if (tb[TCA_FLOWER_KEY_MPLS_LABEL]) { 974 u32 label = nla_get_u32(tb[TCA_FLOWER_KEY_MPLS_LABEL]); 975 976 if (label & ~MPLS_LABEL_MASK) { 977 NL_SET_ERR_MSG_ATTR(extack, 978 tb[TCA_FLOWER_KEY_MPLS_LABEL], 979 "Label must be between 0 and 1048575"); 980 return -EINVAL; 981 } |
821 key_val->mpls_label = label; 822 key_mask->mpls_label = MPLS_LABEL_MASK; | 982 lse_val->mpls_label = label; 983 lse_mask->mpls_label = MPLS_LABEL_MASK; 984 dissector_set_mpls_lse(key_val, 0); 985 dissector_set_mpls_lse(key_mask, 0); |
823 } 824 return 0; 825} 826 827static void fl_set_key_vlan(struct nlattr **tb, 828 __be16 ethertype, 829 int vlan_id_key, int vlan_prio_key, 830 struct flow_dissector_key_vlan *key_val, --- 1382 unchanged lines hidden (view full) --- 2213 TCA_FLOWER_KEY_PORT_SRC_MAX, 2214 &mask->tp_range.tp_max.src, TCA_FLOWER_UNSPEC, 2215 sizeof(key->tp_range.tp_max.src))) 2216 return -1; 2217 2218 return 0; 2219} 2220 | 986 } 987 return 0; 988} 989 990static void fl_set_key_vlan(struct nlattr **tb, 991 __be16 ethertype, 992 int vlan_id_key, int vlan_prio_key, 993 struct flow_dissector_key_vlan *key_val, --- 1382 unchanged lines hidden (view full) --- 2376 TCA_FLOWER_KEY_PORT_SRC_MAX, 2377 &mask->tp_range.tp_max.src, TCA_FLOWER_UNSPEC, 2378 sizeof(key->tp_range.tp_max.src))) 2379 return -1; 2380 2381 return 0; 2382} 2383 |
2384static int fl_dump_key_mpls_opt_lse(struct sk_buff *skb, 2385 struct flow_dissector_key_mpls *mpls_key, 2386 struct flow_dissector_key_mpls *mpls_mask, 2387 u8 lse_index) 2388{ 2389 struct flow_dissector_mpls_lse *lse_mask = &mpls_mask->ls[lse_index]; 2390 struct flow_dissector_mpls_lse *lse_key = &mpls_key->ls[lse_index]; 2391 int err; 2392 2393 err = nla_put_u8(skb, TCA_FLOWER_KEY_MPLS_OPT_LSE_DEPTH, 2394 lse_index + 1); 2395 if (err) 2396 return err; 2397 2398 if (lse_mask->mpls_ttl) { 2399 err = nla_put_u8(skb, TCA_FLOWER_KEY_MPLS_OPT_LSE_TTL, 2400 lse_key->mpls_ttl); 2401 if (err) 2402 return err; 2403 } 2404 if (lse_mask->mpls_bos) { 2405 err = nla_put_u8(skb, TCA_FLOWER_KEY_MPLS_OPT_LSE_BOS, 2406 lse_key->mpls_bos); 2407 if (err) 2408 return err; 2409 } 2410 if (lse_mask->mpls_tc) { 2411 err = nla_put_u8(skb, TCA_FLOWER_KEY_MPLS_OPT_LSE_TC, 2412 lse_key->mpls_tc); 2413 if (err) 2414 return err; 2415 } 2416 if (lse_mask->mpls_label) { 2417 err = nla_put_u8(skb, TCA_FLOWER_KEY_MPLS_OPT_LSE_LABEL, 2418 lse_key->mpls_label); 2419 if (err) 2420 return err; 2421 } 2422 2423 return 0; 2424} 2425 2426static int fl_dump_key_mpls_opts(struct sk_buff *skb, 2427 struct flow_dissector_key_mpls *mpls_key, 2428 struct flow_dissector_key_mpls *mpls_mask) 2429{ 2430 struct nlattr *opts; 2431 struct nlattr *lse; 2432 u8 lse_index; 2433 int err; 2434 2435 opts = nla_nest_start(skb, TCA_FLOWER_KEY_MPLS_OPTS); 2436 if (!opts) 2437 return -EMSGSIZE; 2438 2439 for (lse_index = 0; lse_index < FLOW_DIS_MPLS_MAX; lse_index++) { 2440 if (!(mpls_mask->used_lses & 1 << lse_index)) 2441 continue; 2442 2443 lse = nla_nest_start(skb, TCA_FLOWER_KEY_MPLS_OPTS_LSE); 2444 if (!lse) { 2445 err = -EMSGSIZE; 2446 goto err_opts; 2447 } 2448 2449 err = fl_dump_key_mpls_opt_lse(skb, mpls_key, mpls_mask, 2450 lse_index); 2451 if (err) 2452 goto err_opts_lse; 2453 nla_nest_end(skb, lse); 2454 } 2455 nla_nest_end(skb, opts); 2456 2457 return 0; 2458 2459err_opts_lse: 2460 nla_nest_cancel(skb, lse); 2461err_opts: 2462 nla_nest_cancel(skb, opts); 2463 2464 return err; 2465} 2466 |
|
2221static int fl_dump_key_mpls(struct sk_buff *skb, 2222 struct flow_dissector_key_mpls *mpls_key, 2223 struct flow_dissector_key_mpls *mpls_mask) 2224{ | 2467static int fl_dump_key_mpls(struct sk_buff *skb, 2468 struct flow_dissector_key_mpls *mpls_key, 2469 struct flow_dissector_key_mpls *mpls_mask) 2470{ |
2471 struct flow_dissector_mpls_lse *lse_mask; 2472 struct flow_dissector_mpls_lse *lse_key; |
|
2225 int err; 2226 | 2473 int err; 2474 |
2227 if (!memchr_inv(mpls_mask, 0, sizeof(*mpls_mask))) | 2475 if (!mpls_mask->used_lses) |
2228 return 0; | 2476 return 0; |
2229 if (mpls_mask->mpls_ttl) { | 2477 2478 lse_mask = &mpls_mask->ls[0]; 2479 lse_key = &mpls_key->ls[0]; 2480 2481 /* For backward compatibility, don't use the MPLS nested attributes if 2482 * the rule can be expressed using the old attributes. 2483 */ 2484 if (mpls_mask->used_lses & ~1 || 2485 (!lse_mask->mpls_ttl && !lse_mask->mpls_bos && 2486 !lse_mask->mpls_tc && !lse_mask->mpls_label)) 2487 return fl_dump_key_mpls_opts(skb, mpls_key, mpls_mask); 2488 2489 if (lse_mask->mpls_ttl) { |
2230 err = nla_put_u8(skb, TCA_FLOWER_KEY_MPLS_TTL, | 2490 err = nla_put_u8(skb, TCA_FLOWER_KEY_MPLS_TTL, |
2231 mpls_key->mpls_ttl); | 2491 lse_key->mpls_ttl); |
2232 if (err) 2233 return err; 2234 } | 2492 if (err) 2493 return err; 2494 } |
2235 if (mpls_mask->mpls_tc) { | 2495 if (lse_mask->mpls_tc) { |
2236 err = nla_put_u8(skb, TCA_FLOWER_KEY_MPLS_TC, | 2496 err = nla_put_u8(skb, TCA_FLOWER_KEY_MPLS_TC, |
2237 mpls_key->mpls_tc); | 2497 lse_key->mpls_tc); |
2238 if (err) 2239 return err; 2240 } | 2498 if (err) 2499 return err; 2500 } |
2241 if (mpls_mask->mpls_label) { | 2501 if (lse_mask->mpls_label) { |
2242 err = nla_put_u32(skb, TCA_FLOWER_KEY_MPLS_LABEL, | 2502 err = nla_put_u32(skb, TCA_FLOWER_KEY_MPLS_LABEL, |
2243 mpls_key->mpls_label); | 2503 lse_key->mpls_label); |
2244 if (err) 2245 return err; 2246 } | 2504 if (err) 2505 return err; 2506 } |
2247 if (mpls_mask->mpls_bos) { | 2507 if (lse_mask->mpls_bos) { |
2248 err = nla_put_u8(skb, TCA_FLOWER_KEY_MPLS_BOS, | 2508 err = nla_put_u8(skb, TCA_FLOWER_KEY_MPLS_BOS, |
2249 mpls_key->mpls_bos); | 2509 lse_key->mpls_bos); |
2250 if (err) 2251 return err; 2252 } 2253 return 0; 2254} 2255 2256static int fl_dump_key_ip(struct sk_buff *skb, bool encap, 2257 struct flow_dissector_key_ip *key, --- 505 unchanged lines hidden (view full) --- 2763 2764nla_put_failure_locked: 2765 spin_unlock(&tp->lock); 2766nla_put_failure: 2767 nla_nest_cancel(skb, nest); 2768 return -1; 2769} 2770 | 2510 if (err) 2511 return err; 2512 } 2513 return 0; 2514} 2515 2516static int fl_dump_key_ip(struct sk_buff *skb, bool encap, 2517 struct flow_dissector_key_ip *key, --- 505 unchanged lines hidden (view full) --- 3023 3024nla_put_failure_locked: 3025 spin_unlock(&tp->lock); 3026nla_put_failure: 3027 nla_nest_cancel(skb, nest); 3028 return -1; 3029} 3030 |
3031static int fl_terse_dump(struct net *net, struct tcf_proto *tp, void *fh, 3032 struct sk_buff *skb, struct tcmsg *t, bool rtnl_held) 3033{ 3034 struct cls_fl_filter *f = fh; 3035 struct nlattr *nest; 3036 bool skip_hw; 3037 3038 if (!f) 3039 return skb->len; 3040 3041 t->tcm_handle = f->handle; 3042 3043 nest = nla_nest_start_noflag(skb, TCA_OPTIONS); 3044 if (!nest) 3045 goto nla_put_failure; 3046 3047 spin_lock(&tp->lock); 3048 3049 skip_hw = tc_skip_hw(f->flags); 3050 3051 if (f->flags && nla_put_u32(skb, TCA_FLOWER_FLAGS, f->flags)) 3052 goto nla_put_failure_locked; 3053 3054 spin_unlock(&tp->lock); 3055 3056 if (!skip_hw) 3057 fl_hw_update_stats(tp, f, rtnl_held); 3058 3059 if (tcf_exts_terse_dump(skb, &f->exts)) 3060 goto nla_put_failure; 3061 3062 nla_nest_end(skb, nest); 3063 3064 return skb->len; 3065 3066nla_put_failure_locked: 3067 spin_unlock(&tp->lock); 3068nla_put_failure: 3069 nla_nest_cancel(skb, nest); 3070 return -1; 3071} 3072 |
|
2771static int fl_tmplt_dump(struct sk_buff *skb, struct net *net, void *tmplt_priv) 2772{ 2773 struct fl_flow_tmplt *tmplt = tmplt_priv; 2774 struct fl_flow_key *key, *mask; 2775 struct nlattr *nest; 2776 2777 nest = nla_nest_start_noflag(skb, TCA_OPTIONS); 2778 if (!nest) --- 48 unchanged lines hidden (view full) --- 2827 .change = fl_change, 2828 .delete = fl_delete, 2829 .delete_empty = fl_delete_empty, 2830 .walk = fl_walk, 2831 .reoffload = fl_reoffload, 2832 .hw_add = fl_hw_add, 2833 .hw_del = fl_hw_del, 2834 .dump = fl_dump, | 3073static int fl_tmplt_dump(struct sk_buff *skb, struct net *net, void *tmplt_priv) 3074{ 3075 struct fl_flow_tmplt *tmplt = tmplt_priv; 3076 struct fl_flow_key *key, *mask; 3077 struct nlattr *nest; 3078 3079 nest = nla_nest_start_noflag(skb, TCA_OPTIONS); 3080 if (!nest) --- 48 unchanged lines hidden (view full) --- 3129 .change = fl_change, 3130 .delete = fl_delete, 3131 .delete_empty = fl_delete_empty, 3132 .walk = fl_walk, 3133 .reoffload = fl_reoffload, 3134 .hw_add = fl_hw_add, 3135 .hw_del = fl_hw_del, 3136 .dump = fl_dump, |
3137 .terse_dump = fl_terse_dump, |
|
2835 .bind_class = fl_bind_class, 2836 .tmplt_create = fl_tmplt_create, 2837 .tmplt_destroy = fl_tmplt_destroy, 2838 .tmplt_dump = fl_tmplt_dump, 2839 .owner = THIS_MODULE, 2840 .flags = TCF_PROTO_OPS_DOIT_UNLOCKED, 2841}; 2842 --- 16 unchanged lines hidden --- | 3138 .bind_class = fl_bind_class, 3139 .tmplt_create = fl_tmplt_create, 3140 .tmplt_destroy = fl_tmplt_destroy, 3141 .tmplt_dump = fl_tmplt_dump, 3142 .owner = THIS_MODULE, 3143 .flags = TCF_PROTO_OPS_DOIT_UNLOCKED, 3144}; 3145 --- 16 unchanged lines hidden --- |