This allows offloading virtio-net hashing to tap on Linux. Signed-off-by: Akihiko Odaki <akihiko.od...@daynix.com> --- net/tap-linux.h | 1 + net/tap_int.h | 1 + net/tap-bsd.c | 5 +++++ net/tap-linux.c | 13 +++++++++++++ net/tap-solaris.c | 5 +++++ net/tap-stub.c | 5 +++++ net/tap.c | 8 ++++++++ 7 files changed, 38 insertions(+)
diff --git a/net/tap-linux.h b/net/tap-linux.h index 5fac64c24f99..c773609c799e 100644 --- a/net/tap-linux.h +++ b/net/tap-linux.h @@ -32,6 +32,7 @@ #define TUNSETVNETLE _IOW('T', 220, int) #define TUNSETVNETBE _IOW('T', 222, int) #define TUNSETSTEERINGEBPF _IOR('T', 224, int) +#define TUNGETVNETHASHCAP _IOR('T', 228, NetVnetHash) #define TUNSETVNETHASH _IOW('T', 229, NetVnetHash) #endif diff --git a/net/tap_int.h b/net/tap_int.h index e1b53e343397..84a88841b720 100644 --- a/net/tap_int.h +++ b/net/tap_int.h @@ -36,6 +36,7 @@ ssize_t tap_read_packet(int tapfd, uint8_t *buf, int maxlen); void tap_set_sndbuf(int fd, const NetdevTapOptions *tap, Error **errp); int tap_probe_vnet_hdr(int fd, Error **errp); +bool tap_probe_vnet_hash_supported_types(int fd, uint32_t *types); int tap_probe_has_ufo(int fd); int tap_probe_has_uso(int fd); void tap_fd_set_offload(int fd, int csum, int tso4, int tso6, int ecn, int ufo, diff --git a/net/tap-bsd.c b/net/tap-bsd.c index 2eee0c0a0ec5..142e1abe0420 100644 --- a/net/tap-bsd.c +++ b/net/tap-bsd.c @@ -217,6 +217,11 @@ int tap_probe_has_uso(int fd) return 0; } +bool tap_probe_vnet_hash_supported_types(int fd, uint32_t *types) +{ + return false; +} + void tap_fd_set_vnet_hdr_len(int fd, int len) { } diff --git a/net/tap-linux.c b/net/tap-linux.c index c053828b056b..b45039ecbbb1 100644 --- a/net/tap-linux.c +++ b/net/tap-linux.c @@ -196,6 +196,19 @@ int tap_probe_has_uso(int fd) return 1; } +bool tap_probe_vnet_hash_supported_types(int fd, uint32_t *types) +{ + NetVnetHash hash; + + if (ioctl(fd, TUNGETVNETHASHCAP, &hash)) { + return false; + } + + *types = hash.types; + + return true; +} + void tap_fd_set_vnet_hdr_len(int fd, int len) { if (ioctl(fd, TUNSETVNETHDRSZ, &len) == -1) { diff --git a/net/tap-solaris.c b/net/tap-solaris.c index c65104b84e93..00d1c850680d 100644 --- a/net/tap-solaris.c +++ b/net/tap-solaris.c @@ -221,6 +221,11 @@ int tap_probe_has_uso(int fd) return 0; } +bool tap_probe_vnet_hash_supported_types(int fd, uint32_t *types) +{ + return false; +} + void tap_fd_set_vnet_hdr_len(int fd, int len) { } diff --git a/net/tap-stub.c b/net/tap-stub.c index 5bdc76216b7f..a4718654fbeb 100644 --- a/net/tap-stub.c +++ b/net/tap-stub.c @@ -52,6 +52,11 @@ int tap_probe_has_uso(int fd) return 0; } +bool tap_probe_vnet_hash_supported_types(int fd, uint32_t *types) +{ + return false; +} + void tap_fd_set_vnet_hdr_len(int fd, int len) { } diff --git a/net/tap.c b/net/tap.c index 1136018c1965..98083bcd515e 100644 --- a/net/tap.c +++ b/net/tap.c @@ -248,6 +248,13 @@ static void tap_set_vnet_hdr_len(NetClientState *nc, int len) s->using_vnet_hdr = true; } +static bool tap_get_vnet_hash_supported_types(NetClientState *nc, + uint32_t *types) +{ + TAPState *s = DO_UPCAST(TAPState, nc, nc); + return tap_probe_vnet_hash_supported_types(s->fd, types); +} + static void tap_set_vnet_hash(NetClientState *nc, const NetVnetHash *hash) { TAPState *s = DO_UPCAST(TAPState, nc, nc); @@ -350,6 +357,7 @@ static NetClientInfo net_tap_info = { .has_vnet_hdr_len = tap_has_vnet_hdr_len, .set_offload = tap_set_offload, .set_vnet_hdr_len = tap_set_vnet_hdr_len, + .get_vnet_hash_supported_types = tap_get_vnet_hash_supported_types, .set_vnet_hash = tap_set_vnet_hash, .set_vnet_le = tap_set_vnet_le, .set_vnet_be = tap_set_vnet_be, -- 2.48.1