Commit 67584e3a authored by Nicolas Dichtel's avatar Nicolas Dichtel Committed by Stephen Hemminger

tc: fix compilation with old gcc (< 4.6) (bis)

Commit 8f80d450 ("tc: fix compilation with old gcc (< 4.6)") was reverted
to ease the merge of the net-next branch.

Here is the new version.
Signed-off-by: default avatarNicolas Dichtel <nicolas.dichtel@6wind.com>
Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
parent a9390c92
...@@ -49,6 +49,10 @@ ...@@ -49,6 +49,10 @@
#include "tc_util.h" #include "tc_util.h"
#include "tc_bpf.h" #include "tc_bpf.h"
#ifndef AF_ALG
#define AF_ALG 38
#endif
#ifdef HAVE_ELF #ifdef HAVE_ELF
static int bpf_obj_open(const char *path, enum bpf_prog_type type, static int bpf_obj_open(const char *path, enum bpf_prog_type type,
const char *sec, bool verbose); const char *sec, bool verbose);
...@@ -81,12 +85,13 @@ static int bpf(int cmd, union bpf_attr *attr, unsigned int size) ...@@ -81,12 +85,13 @@ static int bpf(int cmd, union bpf_attr *attr, unsigned int size)
static int bpf_map_update(int fd, const void *key, const void *value, static int bpf_map_update(int fd, const void *key, const void *value,
uint64_t flags) uint64_t flags)
{ {
union bpf_attr attr = { union bpf_attr attr;
.map_fd = fd,
.key = bpf_ptr_to_u64(key), memset(&attr, 0, sizeof(attr));
.value = bpf_ptr_to_u64(value), attr.map_fd = fd;
.flags = flags, attr.key = bpf_ptr_to_u64(key);
}; attr.value = bpf_ptr_to_u64(value);
attr.flags = flags;
return bpf(BPF_MAP_UPDATE_ELEM, &attr, sizeof(attr)); return bpf(BPF_MAP_UPDATE_ELEM, &attr, sizeof(attr));
} }
...@@ -745,12 +750,13 @@ static __check_format_string(1, 2) void bpf_dump_error(const char *format, ...) ...@@ -745,12 +750,13 @@ static __check_format_string(1, 2) void bpf_dump_error(const char *format, ...)
static int bpf_map_create(enum bpf_map_type type, unsigned int size_key, static int bpf_map_create(enum bpf_map_type type, unsigned int size_key,
unsigned int size_value, unsigned int max_elem) unsigned int size_value, unsigned int max_elem)
{ {
union bpf_attr attr = { union bpf_attr attr;
.map_type = type,
.key_size = size_key, memset(&attr, 0, sizeof(attr));
.value_size = size_value, attr.map_type = type;
.max_entries = max_elem, attr.key_size = size_key;
}; attr.value_size = size_value;
attr.max_entries = max_elem;
return bpf(BPF_MAP_CREATE, &attr, sizeof(attr)); return bpf(BPF_MAP_CREATE, &attr, sizeof(attr));
} }
...@@ -758,15 +764,16 @@ static int bpf_map_create(enum bpf_map_type type, unsigned int size_key, ...@@ -758,15 +764,16 @@ static int bpf_map_create(enum bpf_map_type type, unsigned int size_key,
static int bpf_prog_load(enum bpf_prog_type type, const struct bpf_insn *insns, static int bpf_prog_load(enum bpf_prog_type type, const struct bpf_insn *insns,
size_t size, const char *license) size_t size, const char *license)
{ {
union bpf_attr attr = { union bpf_attr attr;
.prog_type = type,
.insns = bpf_ptr_to_u64(insns), memset(&attr, 0, sizeof(attr));
.insn_cnt = size / sizeof(struct bpf_insn), attr.prog_type = type;
.license = bpf_ptr_to_u64(license), attr.insns = bpf_ptr_to_u64(insns);
.log_buf = bpf_ptr_to_u64(bpf_log_buf), attr.insn_cnt = size / sizeof(struct bpf_insn);
.log_size = sizeof(bpf_log_buf), attr.license = bpf_ptr_to_u64(license);
.log_level = 1, attr.log_buf = bpf_ptr_to_u64(bpf_log_buf);
}; attr.log_size = sizeof(bpf_log_buf);
attr.log_level = 1;
if (getenv(BPF_ENV_NOLOG)) { if (getenv(BPF_ENV_NOLOG)) {
attr.log_buf = 0; attr.log_buf = 0;
...@@ -779,10 +786,11 @@ static int bpf_prog_load(enum bpf_prog_type type, const struct bpf_insn *insns, ...@@ -779,10 +786,11 @@ static int bpf_prog_load(enum bpf_prog_type type, const struct bpf_insn *insns,
static int bpf_obj_pin(int fd, const char *pathname) static int bpf_obj_pin(int fd, const char *pathname)
{ {
union bpf_attr attr = { union bpf_attr attr;
.pathname = bpf_ptr_to_u64(pathname),
.bpf_fd = fd, memset(&attr, 0, sizeof(attr));
}; attr.pathname = bpf_ptr_to_u64(pathname);
attr.bpf_fd = fd;
return bpf(BPF_OBJ_PIN, &attr, sizeof(attr)); return bpf(BPF_OBJ_PIN, &attr, sizeof(attr));
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment