Skip to content

Commit d8b0360

Browse files
eBPF helper function for attribute search in the netlink message
There are few network applications relying on Netlink subsystem to get notifications for net-device attribute changes like MTU, Speed, Oper-Status, Name, slave, slave info, etc. The Netlink subsystem notifies the application on every attribute change regardless of what is needed for the application. The attribute search support in EBPF filter helps to filter the Netlink packets based on the specific set of attributes that are needed for the application. The classical BPF supports attribute search but that doesn't support MAPS. The extended BPF supports MAPS, but the attribute search is not enabled. Hence this patch enables the support for attribute search in EBPF. This patch adds the support for following helper function. FN(skb_get_nlattr), FN(skb_get_nlattr_nest) skb_get_nlattr: Find a specific attribute in a stream of attributes skb_get_nlattr_nest: Find a specific attribute in a stream of nested attributes
1 parent 6d83885 commit d8b0360

File tree

2 files changed

+71
-0
lines changed

2 files changed

+71
-0
lines changed
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
diff --git a/include/uapi/linux/bpf.h b/include/uapi/linux/bpf.h
2+
index d143e27..64e86c2 100644
3+
--- a/include/uapi/linux/bpf.h
4+
+++ b/include/uapi/linux/bpf.h
5+
@@ -2228,7 +2228,9 @@ union bpf_attr {
6+
FN(get_current_cgroup_id), \
7+
FN(get_local_storage), \
8+
FN(sk_select_reuseport), \
9+
- FN(skb_ancestor_cgroup_id),
10+
+ FN(skb_ancestor_cgroup_id), \
11+
+ FN(skb_get_nlattr), \
12+
+ FN(skb_get_nlattr_nest),
13+
14+
/* integer value in 'imm' field of BPF_CALL instruction selects which helper
15+
* function eBPF program intends to call
16+
diff --git a/net/core/filter.c b/net/core/filter.c
17+
index 40b3af0..98e3995 100644
18+
--- a/net/core/filter.c
19+
+++ b/net/core/filter.c
20+
@@ -2477,6 +2477,24 @@ static const struct bpf_func_proto bpf_set_hash_invalid_proto = {
21+
.arg1_type = ARG_PTR_TO_CTX,
22+
};
23+
24+
+static const struct bpf_func_proto bpf_skb_get_nlattr_proto = {
25+
+ .func = bpf_skb_get_nlattr,
26+
+ .gpl_only = false,
27+
+ .ret_type = RET_INTEGER,
28+
+ .arg1_type = ARG_PTR_TO_CTX,
29+
+ .arg2_type = ARG_ANYTHING,
30+
+ .arg3_type = ARG_ANYTHING,
31+
+};
32+
+
33+
+static const struct bpf_func_proto skb_get_nlattr_nest_proto = {
34+
+ .func = bpf_skb_get_nlattr_nest,
35+
+ .gpl_only = false,
36+
+ .ret_type = RET_INTEGER,
37+
+ .arg1_type = ARG_PTR_TO_CTX,
38+
+ .arg2_type = ARG_ANYTHING,
39+
+ .arg3_type = ARG_ANYTHING,
40+
+};
41+
+
42+
BPF_CALL_2(bpf_set_hash, struct sk_buff *, skb, u32, hash)
43+
{
44+
/* Set user specified hash as L4(+), so that it gets returned
45+
@@ -4976,6 +4994,10 @@ tc_cls_act_func_proto(enum bpf_func_id func_id, const struct bpf_prog *prog)
46+
return &bpf_set_hash_proto;
47+
case BPF_FUNC_perf_event_output:
48+
return &bpf_skb_event_output_proto;
49+
+ case BPF_FUNC_skb_get_nlattr:
50+
+ return &bpf_skb_get_nlattr_proto;
51+
+ case BPF_FUNC_skb_get_nlattr_nest:
52+
+ return &skb_get_nlattr_nest_proto;
53+
case BPF_FUNC_get_smp_processor_id:
54+
return &bpf_get_smp_processor_id_proto;
55+
case BPF_FUNC_skb_under_cgroup:
56+
diff --git a/tools/include/uapi/linux/bpf.h b/tools/include/uapi/linux/bpf.h
57+
index bf4cd92..b35b72d 100644
58+
--- a/tools/include/uapi/linux/bpf.h
59+
+++ b/tools/include/uapi/linux/bpf.h
60+
@@ -2226,7 +2226,9 @@ union bpf_attr {
61+
FN(get_current_cgroup_id), \
62+
FN(get_local_storage), \
63+
FN(sk_select_reuseport), \
64+
- FN(skb_ancestor_cgroup_id),
65+
+ FN(skb_ancestor_cgroup_id), \
66+
+ FN(skb_get_nlattr), \
67+
+ FN(skb_get_nlattr_nest),
68+
69+
/* integer value in 'imm' field of BPF_CALL instruction selects which helper
70+
* function eBPF program intends to call

patch/series

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ e1000-Do-not-perform-reset-in-reset_task-if-we-are-a.patch
4343
# 0042-armhf-proc-dma-kconfig.patch
4444
Support-for-fullcone-nat.patch
4545
driver-ixgbe-external-phy.patch
46+
netlink-socket-attribute-filter.patch
4647
#
4748
# This series applies on GIT commit 1451b36b2b0d62178e42f648d8a18131af18f7d8
4849
# Tkernel-sched-core-fix-cgroup-fork-race.patch

0 commit comments

Comments
 (0)