Skip to content

Commit

Permalink
net: Added SetSteeringEBPF method for NetClientState.
Browse files Browse the repository at this point in the history
For now, that method supported only by Linux TAP.
Linux TAP uses TUNSETSTEERINGEBPF ioctl.

Signed-off-by: Andrew Melnychenko <andrew@daynix.com>
Signed-off-by: Jason Wang <jasowang@redhat.com>
  • Loading branch information
AndrewAtDaynix authored and jasowang committed May 8, 2021
1 parent 33e512b commit 56ef95f
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 0 deletions.
2 changes: 2 additions & 0 deletions include/net/net.h
Expand Up @@ -61,6 +61,7 @@ typedef int (SetVnetBE)(NetClientState *, bool);
typedef struct SocketReadState SocketReadState;
typedef void (SocketReadStateFinalize)(SocketReadState *rs);
typedef void (NetAnnounce)(NetClientState *);
typedef bool (SetSteeringEBPF)(NetClientState *, int);

typedef struct NetClientInfo {
NetClientDriver type;
Expand All @@ -82,6 +83,7 @@ typedef struct NetClientInfo {
SetVnetLE *set_vnet_le;
SetVnetBE *set_vnet_be;
NetAnnounce *announce;
SetSteeringEBPF *set_steering_ebpf;
} NetClientInfo;

struct NetClientState {
Expand Down
5 changes: 5 additions & 0 deletions net/tap-bsd.c
Expand Up @@ -259,3 +259,8 @@ int tap_fd_get_ifname(int fd, char *ifname)
{
return -1;
}

int tap_fd_set_steering_ebpf(int fd, int prog_fd)
{
return -1;
}
13 changes: 13 additions & 0 deletions net/tap-linux.c
Expand Up @@ -316,3 +316,16 @@ int tap_fd_get_ifname(int fd, char *ifname)
pstrcpy(ifname, sizeof(ifr.ifr_name), ifr.ifr_name);
return 0;
}

int tap_fd_set_steering_ebpf(int fd, int prog_fd)
{
if (ioctl(fd, TUNSETSTEERINGEBPF, (void *) &prog_fd) != 0) {
error_report("Issue while setting TUNSETSTEERINGEBPF:"
" %s with fd: %d, prog_fd: %d",
strerror(errno), fd, prog_fd);

return -1;
}

return 0;
}
5 changes: 5 additions & 0 deletions net/tap-solaris.c
Expand Up @@ -255,3 +255,8 @@ int tap_fd_get_ifname(int fd, char *ifname)
{
return -1;
}

int tap_fd_set_steering_ebpf(int fd, int prog_fd)
{
return -1;
}
5 changes: 5 additions & 0 deletions net/tap-stub.c
Expand Up @@ -85,3 +85,8 @@ int tap_fd_get_ifname(int fd, char *ifname)
{
return -1;
}

int tap_fd_set_steering_ebpf(int fd, int prog_fd)
{
return -1;
}
9 changes: 9 additions & 0 deletions net/tap.c
Expand Up @@ -347,6 +347,14 @@ static void tap_poll(NetClientState *nc, bool enable)
tap_write_poll(s, enable);
}

static bool tap_set_steering_ebpf(NetClientState *nc, int prog_fd)
{
TAPState *s = DO_UPCAST(TAPState, nc, nc);
assert(nc->info->type == NET_CLIENT_DRIVER_TAP);

return tap_fd_set_steering_ebpf(s->fd, prog_fd) == 0;
}

int tap_get_fd(NetClientState *nc)
{
TAPState *s = DO_UPCAST(TAPState, nc, nc);
Expand All @@ -372,6 +380,7 @@ static NetClientInfo net_tap_info = {
.set_vnet_hdr_len = tap_set_vnet_hdr_len,
.set_vnet_le = tap_set_vnet_le,
.set_vnet_be = tap_set_vnet_be,
.set_steering_ebpf = tap_set_steering_ebpf,
};

static TAPState *net_tap_fd_init(NetClientState *peer,
Expand Down
1 change: 1 addition & 0 deletions net/tap_int.h
Expand Up @@ -44,5 +44,6 @@ int tap_fd_set_vnet_be(int fd, int vnet_is_be);
int tap_fd_enable(int fd);
int tap_fd_disable(int fd);
int tap_fd_get_ifname(int fd, char *ifname);
int tap_fd_set_steering_ebpf(int fd, int prog_fd);

#endif /* NET_TAP_INT_H */

0 comments on commit 56ef95f

Please sign in to comment.