mirror of
https://github.com/netbirdio/netbird.git
synced 2024-11-07 16:54:16 +01:00
Rename eBPF program to reflect better to NetBird (#1063)
Rename program name and map name
This commit is contained in:
parent
e5e69b1f75
commit
cdf57275b7
@ -54,14 +54,14 @@ type bpfSpecs struct {
|
|||||||
//
|
//
|
||||||
// It can be passed ebpf.CollectionSpec.Assign.
|
// It can be passed ebpf.CollectionSpec.Assign.
|
||||||
type bpfProgramSpecs struct {
|
type bpfProgramSpecs struct {
|
||||||
XdpProgFunc *ebpf.ProgramSpec `ebpf:"xdp_prog_func"`
|
NbWgProxy *ebpf.ProgramSpec `ebpf:"nb_wg_proxy"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// bpfMapSpecs contains maps before they are loaded into the kernel.
|
// bpfMapSpecs contains maps before they are loaded into the kernel.
|
||||||
//
|
//
|
||||||
// It can be passed ebpf.CollectionSpec.Assign.
|
// It can be passed ebpf.CollectionSpec.Assign.
|
||||||
type bpfMapSpecs struct {
|
type bpfMapSpecs struct {
|
||||||
XdpPortMap *ebpf.MapSpec `ebpf:"xdp_port_map"`
|
NbWgProxySettingsMap *ebpf.MapSpec `ebpf:"nb_wg_proxy_settings_map"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// bpfObjects contains all objects after they have been loaded into the kernel.
|
// bpfObjects contains all objects after they have been loaded into the kernel.
|
||||||
@ -83,12 +83,12 @@ func (o *bpfObjects) Close() error {
|
|||||||
//
|
//
|
||||||
// It can be passed to loadBpfObjects or ebpf.CollectionSpec.LoadAndAssign.
|
// It can be passed to loadBpfObjects or ebpf.CollectionSpec.LoadAndAssign.
|
||||||
type bpfMaps struct {
|
type bpfMaps struct {
|
||||||
XdpPortMap *ebpf.Map `ebpf:"xdp_port_map"`
|
NbWgProxySettingsMap *ebpf.Map `ebpf:"nb_wg_proxy_settings_map"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *bpfMaps) Close() error {
|
func (m *bpfMaps) Close() error {
|
||||||
return _BpfClose(
|
return _BpfClose(
|
||||||
m.XdpPortMap,
|
m.NbWgProxySettingsMap,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -96,12 +96,12 @@ func (m *bpfMaps) Close() error {
|
|||||||
//
|
//
|
||||||
// It can be passed to loadBpfObjects or ebpf.CollectionSpec.LoadAndAssign.
|
// It can be passed to loadBpfObjects or ebpf.CollectionSpec.LoadAndAssign.
|
||||||
type bpfPrograms struct {
|
type bpfPrograms struct {
|
||||||
XdpProgFunc *ebpf.Program `ebpf:"xdp_prog_func"`
|
NbWgProxy *ebpf.Program `ebpf:"nb_wg_proxy"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *bpfPrograms) Close() error {
|
func (p *bpfPrograms) Close() error {
|
||||||
return _BpfClose(
|
return _BpfClose(
|
||||||
p.XdpProgFunc,
|
p.NbWgProxy,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Binary file not shown.
@ -54,14 +54,14 @@ type bpfSpecs struct {
|
|||||||
//
|
//
|
||||||
// It can be passed ebpf.CollectionSpec.Assign.
|
// It can be passed ebpf.CollectionSpec.Assign.
|
||||||
type bpfProgramSpecs struct {
|
type bpfProgramSpecs struct {
|
||||||
XdpProgFunc *ebpf.ProgramSpec `ebpf:"xdp_prog_func"`
|
NbWgProxy *ebpf.ProgramSpec `ebpf:"nb_wg_proxy"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// bpfMapSpecs contains maps before they are loaded into the kernel.
|
// bpfMapSpecs contains maps before they are loaded into the kernel.
|
||||||
//
|
//
|
||||||
// It can be passed ebpf.CollectionSpec.Assign.
|
// It can be passed ebpf.CollectionSpec.Assign.
|
||||||
type bpfMapSpecs struct {
|
type bpfMapSpecs struct {
|
||||||
XdpPortMap *ebpf.MapSpec `ebpf:"xdp_port_map"`
|
NbWgProxySettingsMap *ebpf.MapSpec `ebpf:"nb_wg_proxy_settings_map"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// bpfObjects contains all objects after they have been loaded into the kernel.
|
// bpfObjects contains all objects after they have been loaded into the kernel.
|
||||||
@ -83,12 +83,12 @@ func (o *bpfObjects) Close() error {
|
|||||||
//
|
//
|
||||||
// It can be passed to loadBpfObjects or ebpf.CollectionSpec.LoadAndAssign.
|
// It can be passed to loadBpfObjects or ebpf.CollectionSpec.LoadAndAssign.
|
||||||
type bpfMaps struct {
|
type bpfMaps struct {
|
||||||
XdpPortMap *ebpf.Map `ebpf:"xdp_port_map"`
|
NbWgProxySettingsMap *ebpf.Map `ebpf:"nb_wg_proxy_settings_map"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *bpfMaps) Close() error {
|
func (m *bpfMaps) Close() error {
|
||||||
return _BpfClose(
|
return _BpfClose(
|
||||||
m.XdpPortMap,
|
m.NbWgProxySettingsMap,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -96,12 +96,12 @@ func (m *bpfMaps) Close() error {
|
|||||||
//
|
//
|
||||||
// It can be passed to loadBpfObjects or ebpf.CollectionSpec.LoadAndAssign.
|
// It can be passed to loadBpfObjects or ebpf.CollectionSpec.LoadAndAssign.
|
||||||
type bpfPrograms struct {
|
type bpfPrograms struct {
|
||||||
XdpProgFunc *ebpf.Program `ebpf:"xdp_prog_func"`
|
NbWgProxy *ebpf.Program `ebpf:"nb_wg_proxy"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *bpfPrograms) Close() error {
|
func (p *bpfPrograms) Close() error {
|
||||||
return _BpfClose(
|
return _BpfClose(
|
||||||
p.XdpProgFunc,
|
p.NbWgProxy,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Binary file not shown.
@ -50,22 +50,22 @@ func (l *EBPF) Load(proxyPort, wgPort int) error {
|
|||||||
_ = objs.Close()
|
_ = objs.Close()
|
||||||
}()
|
}()
|
||||||
|
|
||||||
err = objs.XdpPortMap.Put(mapKeyProxyPort, uint16(proxyPort))
|
err = objs.NbWgProxySettingsMap.Put(mapKeyProxyPort, uint16(proxyPort))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
err = objs.XdpPortMap.Put(mapKeyWgPort, uint16(wgPort))
|
err = objs.NbWgProxySettingsMap.Put(mapKeyWgPort, uint16(wgPort))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
_ = objs.XdpPortMap.Close()
|
_ = objs.NbWgProxySettingsMap.Close()
|
||||||
}()
|
}()
|
||||||
|
|
||||||
l.link, err = link.AttachXDP(link.XDPOptions{
|
l.link, err = link.AttachXDP(link.XDPOptions{
|
||||||
Program: objs.XdpProgFunc,
|
Program: objs.NbWgProxy,
|
||||||
Interface: ifce.Index,
|
Interface: ifce.Index,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
const __u32 map_key_proxy_port = 0;
|
const __u32 map_key_proxy_port = 0;
|
||||||
const __u32 map_key_wg_port = 1;
|
const __u32 map_key_wg_port = 1;
|
||||||
|
|
||||||
struct bpf_map_def SEC("maps") xdp_port_map = {
|
struct bpf_map_def SEC("maps") nb_wg_proxy_settings_map = {
|
||||||
.type = BPF_MAP_TYPE_ARRAY,
|
.type = BPF_MAP_TYPE_ARRAY,
|
||||||
.key_size = sizeof(__u32),
|
.key_size = sizeof(__u32),
|
||||||
.value_size = sizeof(__u16),
|
.value_size = sizeof(__u16),
|
||||||
@ -27,14 +27,14 @@ __u16 wg_port = 0;
|
|||||||
|
|
||||||
bool read_port_settings() {
|
bool read_port_settings() {
|
||||||
__u16 *value;
|
__u16 *value;
|
||||||
value = bpf_map_lookup_elem(&xdp_port_map, &map_key_proxy_port);
|
value = bpf_map_lookup_elem(&nb_wg_proxy_settings_map, &map_key_proxy_port);
|
||||||
if(!value) {
|
if(!value) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
proxy_port = *value;
|
proxy_port = *value;
|
||||||
|
|
||||||
value = bpf_map_lookup_elem(&xdp_port_map, &map_key_wg_port);
|
value = bpf_map_lookup_elem(&nb_wg_proxy_settings_map, &map_key_wg_port);
|
||||||
if(!value) {
|
if(!value) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -44,7 +44,7 @@ bool read_port_settings() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
SEC("xdp")
|
SEC("xdp")
|
||||||
int xdp_prog_func(struct xdp_md *ctx) {
|
int nb_wg_proxy(struct xdp_md *ctx) {
|
||||||
if(proxy_port == 0 || wg_port == 0) {
|
if(proxy_port == 0 || wg_port == 0) {
|
||||||
if(!read_port_settings()){
|
if(!read_port_settings()){
|
||||||
return XDP_PASS;
|
return XDP_PASS;
|
||||||
|
Loading…
Reference in New Issue
Block a user