23
23
#include <net/ip.h>
24
24
#include <net/flow_dissector.h>
25
25
26
+ #include <net/dst.h>
27
+ #include <net/dst_metadata.h>
28
+
26
29
struct fl_flow_key {
27
30
int indev_ifindex ;
28
31
struct flow_dissector_key_control control ;
32
+ struct flow_dissector_key_control enc_control ;
29
33
struct flow_dissector_key_basic basic ;
30
34
struct flow_dissector_key_eth_addrs eth ;
31
35
struct flow_dissector_key_vlan vlan ;
@@ -35,6 +39,11 @@ struct fl_flow_key {
35
39
struct flow_dissector_key_ipv6_addrs ipv6 ;
36
40
};
37
41
struct flow_dissector_key_ports tp ;
42
+ struct flow_dissector_key_keyid enc_key_id ;
43
+ union {
44
+ struct flow_dissector_key_ipv4_addrs enc_ipv4 ;
45
+ struct flow_dissector_key_ipv6_addrs enc_ipv6 ;
46
+ };
38
47
} __aligned (BITS_PER_LONG / 8 ); /* Ensure that we can do comparisons as longs. */
39
48
40
49
struct fl_flow_mask_range {
@@ -124,11 +133,31 @@ static int fl_classify(struct sk_buff *skb, const struct tcf_proto *tp,
124
133
struct cls_fl_filter * f ;
125
134
struct fl_flow_key skb_key ;
126
135
struct fl_flow_key skb_mkey ;
136
+ struct ip_tunnel_info * info ;
127
137
128
138
if (!atomic_read (& head -> ht .nelems ))
129
139
return -1 ;
130
140
131
141
fl_clear_masked_range (& skb_key , & head -> mask );
142
+
143
+ info = skb_tunnel_info (skb );
144
+ if (info ) {
145
+ struct ip_tunnel_key * key = & info -> key ;
146
+
147
+ switch (ip_tunnel_info_af (info )) {
148
+ case AF_INET :
149
+ skb_key .enc_ipv4 .src = key -> u .ipv4 .src ;
150
+ skb_key .enc_ipv4 .dst = key -> u .ipv4 .dst ;
151
+ break ;
152
+ case AF_INET6 :
153
+ skb_key .enc_ipv6 .src = key -> u .ipv6 .src ;
154
+ skb_key .enc_ipv6 .dst = key -> u .ipv6 .dst ;
155
+ break ;
156
+ }
157
+
158
+ skb_key .enc_key_id .keyid = tunnel_id_to_key32 (key -> tun_id );
159
+ }
160
+
132
161
skb_key .indev_ifindex = skb -> skb_iif ;
133
162
/* skb_flow_dissect() does not set n_proto in case an unknown protocol,
134
163
* so do it rather here.
@@ -297,7 +326,15 @@ static const struct nla_policy fl_policy[TCA_FLOWER_MAX + 1] = {
297
326
[TCA_FLOWER_KEY_VLAN_ID ] = { .type = NLA_U16 },
298
327
[TCA_FLOWER_KEY_VLAN_PRIO ] = { .type = NLA_U8 },
299
328
[TCA_FLOWER_KEY_VLAN_ETH_TYPE ] = { .type = NLA_U16 },
300
-
329
+ [TCA_FLOWER_KEY_ENC_KEY_ID ] = { .type = NLA_U32 },
330
+ [TCA_FLOWER_KEY_ENC_IPV4_SRC ] = { .type = NLA_U32 },
331
+ [TCA_FLOWER_KEY_ENC_IPV4_SRC_MASK ] = { .type = NLA_U32 },
332
+ [TCA_FLOWER_KEY_ENC_IPV4_DST ] = { .type = NLA_U32 },
333
+ [TCA_FLOWER_KEY_ENC_IPV4_DST_MASK ] = { .type = NLA_U32 },
334
+ [TCA_FLOWER_KEY_ENC_IPV6_SRC ] = { .len = sizeof (struct in6_addr ) },
335
+ [TCA_FLOWER_KEY_ENC_IPV6_SRC_MASK ] = { .len = sizeof (struct in6_addr ) },
336
+ [TCA_FLOWER_KEY_ENC_IPV6_DST ] = { .len = sizeof (struct in6_addr ) },
337
+ [TCA_FLOWER_KEY_ENC_IPV6_DST_MASK ] = { .len = sizeof (struct in6_addr ) },
301
338
};
302
339
303
340
static void fl_set_key_val (struct nlattr * * tb ,
@@ -409,6 +446,40 @@ static int fl_set_key(struct net *net, struct nlattr **tb,
409
446
sizeof (key -> tp .dst ));
410
447
}
411
448
449
+ if (tb [TCA_FLOWER_KEY_ENC_IPV4_SRC ] ||
450
+ tb [TCA_FLOWER_KEY_ENC_IPV4_DST ]) {
451
+ key -> enc_control .addr_type = FLOW_DISSECTOR_KEY_IPV4_ADDRS ;
452
+ fl_set_key_val (tb , & key -> enc_ipv4 .src ,
453
+ TCA_FLOWER_KEY_ENC_IPV4_SRC ,
454
+ & mask -> enc_ipv4 .src ,
455
+ TCA_FLOWER_KEY_ENC_IPV4_SRC_MASK ,
456
+ sizeof (key -> enc_ipv4 .src ));
457
+ fl_set_key_val (tb , & key -> enc_ipv4 .dst ,
458
+ TCA_FLOWER_KEY_ENC_IPV4_DST ,
459
+ & mask -> enc_ipv4 .dst ,
460
+ TCA_FLOWER_KEY_ENC_IPV4_DST_MASK ,
461
+ sizeof (key -> enc_ipv4 .dst ));
462
+ }
463
+
464
+ if (tb [TCA_FLOWER_KEY_ENC_IPV6_SRC ] ||
465
+ tb [TCA_FLOWER_KEY_ENC_IPV6_DST ]) {
466
+ key -> enc_control .addr_type = FLOW_DISSECTOR_KEY_IPV6_ADDRS ;
467
+ fl_set_key_val (tb , & key -> enc_ipv6 .src ,
468
+ TCA_FLOWER_KEY_ENC_IPV6_SRC ,
469
+ & mask -> enc_ipv6 .src ,
470
+ TCA_FLOWER_KEY_ENC_IPV6_SRC_MASK ,
471
+ sizeof (key -> enc_ipv6 .src ));
472
+ fl_set_key_val (tb , & key -> enc_ipv6 .dst ,
473
+ TCA_FLOWER_KEY_ENC_IPV6_DST ,
474
+ & mask -> enc_ipv6 .dst ,
475
+ TCA_FLOWER_KEY_ENC_IPV6_DST_MASK ,
476
+ sizeof (key -> enc_ipv6 .dst ));
477
+ }
478
+
479
+ fl_set_key_val (tb , & key -> enc_key_id .keyid , TCA_FLOWER_KEY_ENC_KEY_ID ,
480
+ & mask -> enc_key_id .keyid , TCA_FLOWER_KEY_ENC_KEY_ID ,
481
+ sizeof (key -> enc_key_id .keyid ));
482
+
412
483
return 0 ;
413
484
}
414
485
@@ -821,6 +892,33 @@ static int fl_dump(struct net *net, struct tcf_proto *tp, unsigned long fh,
821
892
sizeof (key -> tp .dst ))))
822
893
goto nla_put_failure ;
823
894
895
+ if (key -> enc_control .addr_type == FLOW_DISSECTOR_KEY_IPV4_ADDRS &&
896
+ (fl_dump_key_val (skb , & key -> enc_ipv4 .src ,
897
+ TCA_FLOWER_KEY_ENC_IPV4_SRC , & mask -> enc_ipv4 .src ,
898
+ TCA_FLOWER_KEY_ENC_IPV4_SRC_MASK ,
899
+ sizeof (key -> enc_ipv4 .src )) ||
900
+ fl_dump_key_val (skb , & key -> enc_ipv4 .dst ,
901
+ TCA_FLOWER_KEY_ENC_IPV4_DST , & mask -> enc_ipv4 .dst ,
902
+ TCA_FLOWER_KEY_ENC_IPV4_DST_MASK ,
903
+ sizeof (key -> enc_ipv4 .dst ))))
904
+ goto nla_put_failure ;
905
+ else if (key -> enc_control .addr_type == FLOW_DISSECTOR_KEY_IPV6_ADDRS &&
906
+ (fl_dump_key_val (skb , & key -> enc_ipv6 .src ,
907
+ TCA_FLOWER_KEY_ENC_IPV6_SRC , & mask -> enc_ipv6 .src ,
908
+ TCA_FLOWER_KEY_ENC_IPV6_SRC_MASK ,
909
+ sizeof (key -> enc_ipv6 .src )) ||
910
+ fl_dump_key_val (skb , & key -> enc_ipv6 .dst ,
911
+ TCA_FLOWER_KEY_ENC_IPV6_DST ,
912
+ & mask -> enc_ipv6 .dst ,
913
+ TCA_FLOWER_KEY_ENC_IPV6_DST_MASK ,
914
+ sizeof (key -> enc_ipv6 .dst ))))
915
+ goto nla_put_failure ;
916
+
917
+ if (fl_dump_key_val (skb , & key -> enc_key_id , TCA_FLOWER_KEY_ENC_KEY_ID ,
918
+ & mask -> enc_key_id , TCA_FLOWER_KEY_ENC_KEY_ID ,
919
+ sizeof (key -> enc_key_id )))
920
+ goto nla_put_failure ;
921
+
824
922
nla_put_u32 (skb , TCA_FLOWER_FLAGS , f -> flags );
825
923
826
924
if (tcf_exts_dump (skb , & f -> exts ))
0 commit comments