History

net: plumb network namespace into __skb_flow_dissect

This new argument will be used in the next patches for the eth_get_headlen use case. eth_get_headlen calls flow dissector with only data (without skb) so there is currently no way to pull attached BPF flow dissector program. With this new argument, we can amend the callers to explicitly pass network namespace so we can use attached BPF program.

Stanislav Fomichev committed 7 years ago

Commit 3cbf4ff1 parent 7b8a1303 files · +31 −20Browse files

Unified · Split

3 files
  1. include/linux/skbuff.h +11 −8
  2. net/core/flow_dissector.c +17 −10
  3. net/ethernet/eth.c +3 −2
include/linux/skbuff.h+11−8
@@ -1284,7 +1284,8 @@ bool __skb_flow_bpf_dissect(struct bpf_prog *prog, · 1283 unmodified lines
1284 const struct sk_buff *skb,1284 const struct sk_buff *skb,
1285 struct flow_dissector *flow_dissector,1285 struct flow_dissector *flow_dissector,
1286 struct bpf_flow_keys *flow_keys);1286 struct bpf_flow_keys *flow_keys);
1287bool __skb_flow_dissect(const struct sk_buff *skb,1287bool __skb_flow_dissect(const struct net *net,
1288 const struct sk_buff *skb,
1288 struct flow_dissector *flow_dissector,1289 struct flow_dissector *flow_dissector,
1289 void *target_container,1290 void *target_container,
1290 void *data, __be16 proto, int nhoff, int hlen,1291 void *data, __be16 proto, int nhoff, int hlen,
@@ -1294,8 +1295,8 @@ static inline bool skb_flow_dissect(const struct sk_buff *skb, · 3 unmodified lines
1294 struct flow_dissector *flow_dissector,1295 struct flow_dissector *flow_dissector,
1295 void *target_container, unsigned int flags)1296 void *target_container, unsigned int flags)
1296{1297{
1297 return __skb_flow_dissect(skb, flow_dissector, target_container,1298 return __skb_flow_dissect(NULL, skb, flow_dissector,
1298 NULL, 0, 0, 0, flags);1299 target_container, NULL, 0, 0, 0, flags);
1299}1300}
1300 1301
1301static inline bool skb_flow_dissect_flow_keys(const struct sk_buff *skb,1302static inline bool skb_flow_dissect_flow_keys(const struct sk_buff *skb,
@@ -1303,18 +1304,19 @@ static inline bool skb_flow_dissect_flow_keys(const struct sk_buff *skb, · 1 unmodified line
1303 unsigned int flags)1304 unsigned int flags)
1304{1305{
1305 memset(flow, 0, sizeof(*flow));1306 memset(flow, 0, sizeof(*flow));
1306 return __skb_flow_dissect(skb, &flow_keys_dissector, flow,1307 return __skb_flow_dissect(NULL, skb, &flow_keys_dissector,
1307 NULL, 0, 0, 0, flags);1308 flow, NULL, 0, 0, 0, flags);
1308}1309}
1309 1310
1310static inline bool1311static inline bool
1311skb_flow_dissect_flow_keys_basic(const struct sk_buff *skb,1312skb_flow_dissect_flow_keys_basic(const struct net *net,
1313 const struct sk_buff *skb,
1312 struct flow_keys_basic *flow, void *data,1314 struct flow_keys_basic *flow, void *data,
1313 __be16 proto, int nhoff, int hlen,1315 __be16 proto, int nhoff, int hlen,
1314 unsigned int flags)1316 unsigned int flags)
1315{1317{
1316 memset(flow, 0, sizeof(*flow));1318 memset(flow, 0, sizeof(*flow));
1317 return __skb_flow_dissect(skb, &flow_keys_basic_dissector, flow,1319 return __skb_flow_dissect(net, skb, &flow_keys_basic_dissector, flow,
1318 data, proto, nhoff, hlen, flags);1320 data, proto, nhoff, hlen, flags);
1319}1321}
1320 1322
@@ -2492,7 +2494,8 @@ static inline void skb_probe_transport_header(struct sk_buff *skb) · 1171 unmodified lines
2492 if (skb_transport_header_was_set(skb))2494 if (skb_transport_header_was_set(skb))
2493 return;2495 return;
2494 2496
2495 if (skb_flow_dissect_flow_keys_basic(skb, &keys, NULL, 0, 0, 0, 0))2497 if (skb_flow_dissect_flow_keys_basic(NULL, skb, &keys,
2498 NULL, 0, 0, 0, 0))
2496 skb_set_transport_header(skb, keys.control.thoff);2499 skb_set_transport_header(skb, keys.control.thoff);
2497}2500}
2498 2501
net/core/flow_dissector.c+17−10
@@ -722,6 +722,7 @@ bool bpf_flow_dissect(struct bpf_prog *prog, struct bpf_flow_dissector *ctx, · 721 unmodified lines
722 722
723/**723/**
724 * __skb_flow_dissect - extract the flow_keys struct and return it724 * __skb_flow_dissect - extract the flow_keys struct and return it
725 * @net: associated network namespace, derived from @skb if NULL
725 * @skb: sk_buff to extract the flow from, can be NULL if the rest are specified726 * @skb: sk_buff to extract the flow from, can be NULL if the rest are specified
726 * @flow_dissector: list of keys to dissect727 * @flow_dissector: list of keys to dissect
727 * @target_container: target structure to put dissected values into728 * @target_container: target structure to put dissected values into
@@ -738,7 +739,8 @@ bool bpf_flow_dissect(struct bpf_prog *prog, struct bpf_flow_dissector *ctx, · 10 unmodified lines
738 *739 *
739 * Caller must take care of zeroing target container memory.740 * Caller must take care of zeroing target container memory.
740 */741 */
741bool __skb_flow_dissect(const struct sk_buff *skb,742bool __skb_flow_dissect(const struct net *net,
743 const struct sk_buff *skb,
742 struct flow_dissector *flow_dissector,744 struct flow_dissector *flow_dissector,
743 void *target_container,745 void *target_container,
744 void *data, __be16 proto, int nhoff, int hlen,746 void *data, __be16 proto, int nhoff, int hlen,
@@ -797,13 +799,17 @@ bool __skb_flow_dissect(const struct sk_buff *skb, · 52 unmodified lines
797 struct bpf_prog *attached = NULL;799 struct bpf_prog *attached = NULL;
798 800
799 rcu_read_lock();801 rcu_read_lock();
802 if (!net) {
803 if (skb->dev)
804 net = dev_net(skb->dev);
805 else if (skb->sk)
806 net = sock_net(skb->sk);
807 else
808 WARN_ON_ONCE(1);
809 }
800 810
801 if (skb->dev)811 if (net)
802 attached = rcu_dereference(dev_net(skb->dev)->flow_dissector_prog);812 attached = rcu_dereference(net->flow_dissector_prog);
803 else if (skb->sk)
804 attached = rcu_dereference(sock_net(skb->sk)->flow_dissector_prog);
805 else
806 WARN_ON_ONCE(1);
807 813
808 if (attached) {814 if (attached) {
809 ret = __skb_flow_bpf_dissect(attached, skb,815 ret = __skb_flow_bpf_dissect(attached, skb,
@@ -1405,8 +1411,8 @@ u32 __skb_get_hash_symmetric(const struct sk_buff *skb) · 595 unmodified lines
1405 __flow_hash_secret_init();1411 __flow_hash_secret_init();
1406 1412
1407 memset(&keys, 0, sizeof(keys));1413 memset(&keys, 0, sizeof(keys));
1408 __skb_flow_dissect(skb, &flow_keys_dissector_symmetric, &keys,1414 __skb_flow_dissect(NULL, skb, &flow_keys_dissector_symmetric,
1409 NULL, 0, 0, 0,1415 &keys, NULL, 0, 0, 0,
1410 FLOW_DISSECTOR_F_STOP_AT_FLOW_LABEL);1416 FLOW_DISSECTOR_F_STOP_AT_FLOW_LABEL);
1411 1417
1412 return __flow_hash_from_keys(&keys, hashrnd);1418 return __flow_hash_from_keys(&keys, hashrnd);
@@ -1507,7 +1513,8 @@ u32 skb_get_poff(const struct sk_buff *skb) · 94 unmodified lines
1507{1513{
1508 struct flow_keys_basic keys;1514 struct flow_keys_basic keys;
1509 1515
1510 if (!skb_flow_dissect_flow_keys_basic(skb, &keys, NULL, 0, 0, 0, 0))1516 if (!skb_flow_dissect_flow_keys_basic(NULL, skb, &keys,
1517 NULL, 0, 0, 0, 0))
1511 return 0;1518 return 0;
1512 1519
1513 return __skb_get_poff(skb, skb->data, &keys, skb_headlen(skb));1520 return __skb_get_poff(skb, skb->data, &keys, skb_headlen(skb));
net/ethernet/eth.c+3−2
@@ -136,8 +136,9 @@ u32 eth_get_headlen(void *data, unsigned int len) · 135 unmodified lines
136 return len;136 return len;
137 137
138 /* parse any remaining L2/L3 headers, check for L4 */138 /* parse any remaining L2/L3 headers, check for L4 */
139 if (!skb_flow_dissect_flow_keys_basic(NULL, &keys, data, eth->h_proto,139 if (!skb_flow_dissect_flow_keys_basic(NULL, NULL, &keys, data,
140 sizeof(*eth), len, flags))140 eth->h_proto, sizeof(*eth),
141 len, flags))
141 return max_t(u32, keys.control.thoff, sizeof(*eth));142 return max_t(u32, keys.control.thoff, sizeof(*eth));
142 143
143 /* parse for any L4 headers */144 /* parse for any L4 headers */

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