-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
net: Introduce netns_bpf for BPF programs attached to netns
In order to: (1) attach more than one BPF program type to netns, or (2) support attaching BPF programs to netns with bpf_link, or (3) support multi-prog attach points for netns we will need to keep more state per netns than a single pointer like we have now for BPF flow dissector program. Prepare for the above by extracting netns_bpf that is part of struct net, for storing all state related to BPF programs attached to netns. Turn flow dissector callbacks for querying/attaching/detaching a program into generic ones that operate on netns_bpf. Next patch will move the generic callbacks into their own module. This is similar to how it is organized for cgroup with cgroup_bpf. Signed-off-by: Jakub Sitnicki <jakub@cloudflare.com> Signed-off-by: Alexei Starovoitov <ast@kernel.org> Cc: Stanislav Fomichev <sdf@google.com> Link: https://lore.kernel.org/bpf/20200531082846.2117903-3-jakub@cloudflare.com
- Loading branch information
Jakub Sitnicki
authored and
Alexei Starovoitov
committed
Jun 1, 2020
1 parent
171526f
commit a3fd7ce
Showing
6 changed files
with
149 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* SPDX-License-Identifier: GPL-2.0 */ | ||
#ifndef _BPF_NETNS_H | ||
#define _BPF_NETNS_H | ||
|
||
#include <linux/mutex.h> | ||
#include <uapi/linux/bpf.h> | ||
|
||
enum netns_bpf_attach_type { | ||
NETNS_BPF_INVALID = -1, | ||
NETNS_BPF_FLOW_DISSECTOR = 0, | ||
MAX_NETNS_BPF_ATTACH_TYPE | ||
}; | ||
|
||
static inline enum netns_bpf_attach_type | ||
to_netns_bpf_attach_type(enum bpf_attach_type attach_type) | ||
{ | ||
switch (attach_type) { | ||
case BPF_FLOW_DISSECTOR: | ||
return NETNS_BPF_FLOW_DISSECTOR; | ||
default: | ||
return NETNS_BPF_INVALID; | ||
} | ||
} | ||
|
||
/* Protects updates to netns_bpf */ | ||
extern struct mutex netns_bpf_mutex; | ||
|
||
union bpf_attr; | ||
struct bpf_prog; | ||
|
||
#ifdef CONFIG_NET | ||
int netns_bpf_prog_query(const union bpf_attr *attr, | ||
union bpf_attr __user *uattr); | ||
int netns_bpf_prog_attach(const union bpf_attr *attr, | ||
struct bpf_prog *prog); | ||
int netns_bpf_prog_detach(const union bpf_attr *attr); | ||
#else | ||
static inline int netns_bpf_prog_query(const union bpf_attr *attr, | ||
union bpf_attr __user *uattr) | ||
{ | ||
return -EOPNOTSUPP; | ||
} | ||
|
||
static inline int netns_bpf_prog_attach(const union bpf_attr *attr, | ||
struct bpf_prog *prog) | ||
{ | ||
return -EOPNOTSUPP; | ||
} | ||
|
||
static inline int netns_bpf_prog_detach(const union bpf_attr *attr) | ||
{ | ||
return -EOPNOTSUPP; | ||
} | ||
#endif | ||
|
||
#endif /* _BPF_NETNS_H */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/* SPDX-License-Identifier: GPL-2.0 */ | ||
/* | ||
* BPF programs attached to network namespace | ||
*/ | ||
|
||
#ifndef __NETNS_BPF_H__ | ||
#define __NETNS_BPF_H__ | ||
|
||
#include <linux/bpf-netns.h> | ||
|
||
struct bpf_prog; | ||
|
||
struct netns_bpf { | ||
struct bpf_prog __rcu *progs[MAX_NETNS_BPF_ATTACH_TYPE]; | ||
}; | ||
|
||
#endif /* __NETNS_BPF_H__ */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters