summaryrefslogtreecommitdiff
Commit message (Collapse)AuthorAgeFilesLines
* CREDITS: add fileHEADmainStephen Hemminger2023-05-132-2/+32
| | | | | | | Record some of the historical contributors to iproute2. Take Alexey out of README. Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
* tc/prio: handle possible truncated kernel responseStephen Hemminger2023-05-131-0/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Reported by -fanalyzer. If kernel did not send full qdisc info, then uninitialized or null data could be referenced. q_prio.c: In function ‘prio_print_opt’: q_prio.c:105:57: warning: dereference of NULL ‘0’ [CWE-476] [-Wanalyzer-null-dereference] 105 | print_uint(PRINT_ANY, "bands", "bands %u ", qopt->bands); | ~~~~^~~~~~~ ‘prio_print_opt’: event 1 | | 98 | if (opt == NULL) | | ^ | | | | | (1) following ‘false’ branch (when ‘opt’ is non-NULL)... | ‘prio_print_opt’: event 2 | |../include/uapi/linux/rtnetlink.h:228:38: | 228 | #define RTA_PAYLOAD(rta) ((int)((rta)->rta_len) - RTA_LENGTH(0)) | | ~~~~~~^~~~~~~~~~ | | | | | (2) ...to here ../include/libnetlink.h:236:19: note: in expansion of macro ‘RTA_PAYLOAD’ | 236 | ({ data = RTA_PAYLOAD(rta) >= len ? RTA_DATA(rta) : NULL; \ | | ^~~~~~~~~~~ q_prio.c:101:13: note: in expansion of macro ‘parse_rtattr_nested_compat’ | 101 | if (parse_rtattr_nested_compat(tb, TCA_PRIO_MAX, opt, qopt, | | ^~~~~~~~~~~~~~~~~~~~~~~~~~ | ‘prio_print_opt’: event 3 | |../include/libnetlink.h:236:59: | 236 | ({ data = RTA_PAYLOAD(rta) >= len ? RTA_DATA(rta) : NULL; \ q_prio.c:101:13: note: in expansion of macro ‘parse_rtattr_nested_compat’ | 101 | if (parse_rtattr_nested_compat(tb, TCA_PRIO_MAX, opt, qopt, | | ^~~~~~~~~~~~~~~~~~~~~~~~~~ | ‘prio_print_opt’: events 4-5 | | 105 | print_uint(PRINT_ANY, "bands", "bands %u ", qopt->bands); | | ~~~~^~~~~~~ | | | | | (4) ...to here | | (5) dereference of NULL ‘<unknown>’ | Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
* rdma/utils: fix some analyzer warningsStephen Hemminger2023-05-131-0/+10
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Add error checks for cases where analyzer thinks it is possible to us a possibly NULL value. utils.c: In function ‘get_port_from_argv’: utils.c:76:17: warning: use of NULL where non-null expected [CWE-476] [-Wanalyzer-null-argument] 76 | slash = strchr(rd_argv(rd), '/'); | ^~~~~~~~~~~~~~~~~~~~~~~~ ‘get_port_from_argv’: events 1-2 | | 68 | static int get_port_from_argv(struct rd *rd, uint32_t *port, | | ^~~~~~~~~~~~~~~~~~ | | | | | (1) entry to ‘get_port_from_argv’ |...... | 76 | slash = strchr(rd_argv(rd), '/'); | | ~ | | | | | (2) inlined call to ‘rd_argv’ from ‘get_port_from_argv’ | +--> ‘rd_argv’: event 3 | | 18 | if (!rd_argc(rd)) | | ^ | | | | | (3) following ‘true’ branch... | <------+ | ‘get_port_from_argv’: events 4-5 | | 76 | slash = strchr(rd_argv(rd), '/'); | | ^~~~~~~~~~~~~~~~~~~~~~~~ | | | | | (4) ...to here | | (5) argument 1 (‘<unknown>’) NULL where non-null expected | In file included from rdma.h:10, from utils.c:7: /usr/include/string.h:246:14: note: argument 1 of ‘strchr’ must be non-null 246 | extern char *strchr (const char *__s, int __c) | ^~~~~~ Fixes: 40df8263a0f0 ("rdma: Add dev object") Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
* nstat: fix potential NULL derefStephen Hemminger2023-05-131-0/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Reported as: CC nstat nstat.c: In function ‘load_ugly_table’: nstat.c:205:24: warning: dereference of NULL ‘p’ [CWE-476] [-Wanalyzer-null-dereference] 205 | while (*p) { | ^~ ‘main’: events 1-14 | | 575 | int main(int argc, char *argv[]) | | ^~~~ | | | | | (1) entry to ‘main’ |...... | 635 | if (scan_interval > 0) { | | ~ | | | | | (2) following ‘true’ branch... | 636 | if (time_constant == 0) | | ~~~~~~~~~~~~~~~~~~ | | | | | (3) ...to here |...... | 640 | if ((fd = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) { | | ~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | | | | | | | (4) when ‘socket’ succeeds | | (5) following ‘false’ branch (when ‘fd >= 0’)... |...... | 644 | if (bind(fd, (struct sockaddr *)&sun, 2+1+strlen(sun.sun_path+1)) < 0) { | | ~ ~~~~~~~~~~~~~~~~~~~~~~ | | | | | | (7) following ‘false’ branch... (6) ...to here |...... | 648 | if (listen(fd, 5) < 0) { | | ~~~~~~~~~~~~~~ | | || | | |(8) ...to here | | |(9) when ‘listen’ succeeds | | (10) following ‘false’ branch... |...... | 652 | if (daemon(0, 0)) { | | ~~~~~~~~~~~~~ | | || | | |(11) ...to here | | (12) following ‘false’ branch... |...... | 656 | signal(SIGPIPE, SIG_IGN); | | ~~~~~~~~~~~~~~~~~~~~~~~~ | | | | | (13) ...to here | 657 | signal(SIGCHLD, sigchild); | 658 | server_loop(fd); | | ~~~~~~~~~~~~~~~ | | | | | (14) calling ‘server_loop’ from ‘main’ | +--> ‘server_loop’: events 15-16 | | 472 | static void server_loop(int fd) | | ^~~~~~~~~~~ | | | | | (15) entry to ‘server_loop’ |...... | 483 | load_netstat(); | | ~~~~~~~~~~~~~~ | | | | | (16) calling ‘load_netstat’ from ‘server_loop’ | +--> ‘load_netstat’: events 17-20 | | 302 | static void load_netstat(void) | | ^~~~~~~~~~~~ | | | | | (17) entry to ‘load_netstat’ |...... | 306 | if (fp) { | | ~ | | | | | (18) following ‘true’ branch (when ‘fp’ is non-NULL)... | 307 | load_ugly_table(fp); | | ~~~~~~~~~~~~~~~~~~~ | | | | | (19) ...to here | | (20) calling ‘load_ugly_table’ from ‘load_netstat’ | +--> ‘load_ugly_table’: events 21-26 | | 178 | static void load_ugly_table(FILE *fp) | | ^~~~~~~~~~~~~~~ | | | | | (21) entry to ‘load_ugly_table’ | 179 | { | 180 | char *buf = NULL; | | ~~~ | | | | | (22) ‘buf’ is NULL |...... | 186 | while ((nread = getline(&buf, &buflen, fp)) != -1) { | | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | | | | | (23) following ‘true’ branch... |...... | 192 | p = strchr(buf, ':'); | | ~~~~~~~~~~~~~~~~ | | | | | (24) ...to here | | (25) when ‘strchr’ returns non-NULL | 193 | if (!p) { | | ~ | | | | | (26) following ‘false’ branch (when ‘p’ is non-NULL)... | ‘load_ugly_table’: event 27 | |cc1: | (27): ...to here | ‘load_ugly_table’: events 28-40 | | 205 | while (*p) { | | ^~ | | | | | (28) following ‘true’ branch... | | (40) dereference of NULL ‘p’ |...... | 208 | if ((next = strchr(p, ' ')) != NULL) | | ~ ~~~~~~~~~~~~~~ | | | | | | | (29) ...to here | | | (30) when ‘strchr’ returns NULL | | (31) following ‘false’ branch (when ‘next’ is NULL)... | 209 | *next++ = 0; | 210 | else if ((next = strchr(p, '\n')) != NULL) | | ~ ~~~~~~~~~~~~~~~ | | | | | | | (32) ...to here | | | (33) when ‘strchr’ returns NULL | | (34) following ‘false’ branch (when ‘next’ is NULL)... | 211 | *next++ = 0; | 212 | if (off < sizeof(idbuf)) { | | ~~~~~~~~~~~~~~~~~~~~ | | | | | | | (35) ...to here | | (36) following ‘false’ branch... |...... | 216 | n = malloc(sizeof(*n)); | | ~~~~~~~~~~~~~~~~~~ | | | | | (37) ...to here | 217 | if (!n) { | | ~ | | | | | (38) following ‘false’ branch (when ‘n’ is non-NULL)... |...... | 221 | n->id = strdup(idbuf); | | ~~~~~~~~~~~~~ | | | | | (39) ...to here | nstat.c:254:35: warning: dereference of NULL ‘n’ [CWE-476] [-Wanalyzer-null-dereference] 254 | n = n->next; | ~~^~~~~~~~~ ‘main’: events 1-14 | | 575 | int main(int argc, char *argv[]) | | ^~~~ | | | | | (1) entry to ‘main’ |...... | 635 | if (scan_interval > 0) { | | ~ | | | | | (2) following ‘true’ branch... | 636 | if (time_constant == 0) | | ~~~~~~~~~~~~~~~~~~ | | | | | (3) ...to here |...... | 640 | if ((fd = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) { | | ~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | | | | | | | (4) when ‘socket’ succeeds | | (5) following ‘false’ branch (when ‘fd >= 0’)... |...... | 644 | if (bind(fd, (struct sockaddr *)&sun, 2+1+strlen(sun.sun_path+1)) < 0) { | | ~ ~~~~~~~~~~~~~~~~~~~~~~ | | | | | | (7) following ‘false’ branch... (6) ...to here |...... | 648 | if (listen(fd, 5) < 0) { | | ~~~~~~~~~~~~~~ | | || | | |(8) ...to here | | |(9) when ‘listen’ succeeds | | (10) following ‘false’ branch... |...... | 652 | if (daemon(0, 0)) { | | ~~~~~~~~~~~~~ | | || | | |(11) ...to here | | (12) following ‘false’ branch... |...... | 656 | signal(SIGPIPE, SIG_IGN); | | ~~~~~~~~~~~~~~~~~~~~~~~~ | | | | | (13) ...to here | 657 | signal(SIGCHLD, sigchild); | 658 | server_loop(fd); | | ~~~~~~~~~~~~~~~ | | | | | (14) calling ‘server_loop’ from ‘main’ | +--> ‘server_loop’: events 15-16 | | 472 | static void server_loop(int fd) | | ^~~~~~~~~~~ | | | | | (15) entry to ‘server_loop’ |...... | 483 | load_netstat(); | | ~~~~~~~~~~~~~~ | | | | | (16) calling ‘load_netstat’ from ‘server_loop’ | +--> ‘load_netstat’: events 17-20 | | 302 | static void load_netstat(void) | | ^~~~~~~~~~~~ | | | | | (17) entry to ‘load_netstat’ |...... | 306 | if (fp) { | | ~ | | | | | (18) following ‘true’ branch (when ‘fp’ is non-NULL)... | 307 | load_ugly_table(fp); | | ~~~~~~~~~~~~~~~~~~~ | | | | | (19) ...to here | | (20) calling ‘load_ugly_table’ from ‘load_netstat’ | +--> ‘load_ugly_table’: events 21-25 | | 178 | static void load_ugly_table(FILE *fp) | | ^~~~~~~~~~~~~~~ | | | | | (21) entry to ‘load_ugly_table’ |...... | 186 | while ((nread = getline(&buf, &buflen, fp)) != -1) { | | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | | | | | (22) following ‘true’ branch... |...... | 192 | p = strchr(buf, ':'); | | ~~~~~~~~~~~~~~~~ | | | | | (23) ...to here | | (24) when ‘strchr’ returns non-NULL | 193 | if (!p) { | | ~ | | | | | (25) following ‘false’ branch (when ‘p’ is non-NULL)... | ‘load_ugly_table’: event 26 | |cc1: | (26): ...to here | ‘load_ugly_table’: events 27-28 | | 205 | while (*p) { | | ^ | | | | | (27) following ‘false’ branch... |...... | 228 | nread = getline(&buf, &buflen, fp); | | ~ | | | | | (28) inlined call to ‘getline’ from ‘load_ugly_table’ | +--> ‘getline’: event 29 | |/usr/include/bits/stdio.h:120:10: | 120 | return __getdelim (__lineptr, __n, '\n', __stream); | | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | | | | | (29) ...to here | <------+ | ‘load_ugly_table’: events 30-36 | |nstat.c:229:20: | 229 | if (nread == -1) { | | ^ | | | | | (30) following ‘false’ branch... |...... | 234 | count2 = count_spaces(buf); | | ~~~~~~~~~~~~~~~~~ | | | | | (31) ...to here |...... | 239 | if (!p) { | | ~ | | | | | (32) following ‘false’ branch (when ‘p’ is non-NULL)... |...... | 244 | *p = 0; | | ~~~~~~ | | | | | (33) ...to here | 245 | if (sscanf(p+1, "%llu", &n->val) != 1) { | | ~ | | | | | (34) following ‘false’ branch... |...... | 251 | if (skip) | | ~ | | | | | (35) ...to here |...... | 254 | n = n->next; | | ~~~~~~~~~~~ | | | | | (36) dereference of NULL ‘n’ | Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
* netem: fix NULL deref on allocation failureStephen Hemminger2023-05-131-0/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | q_netem.c: In function ‘get_distribution’: q_netem.c:159:35: warning: dereference of possibly-NULL ‘data’ [CWE-690] [-Wanalyzer-possible-null-dereference] 159 | data[n++] = x; | ~~~~~~~~~~^~~ ‘netem_parse_opt’: events 1-24 | | 192 | static int netem_parse_opt(struct qdisc_util *qu, int argc, char **argv, | | ^~~~~~~~~~~~~~~ | | | | | (1) entry to ‘netem_parse_opt’ |...... | 212 | for ( ; argc > 0; --argc, ++argv) { | | ~~~~~~~~ | | | | | (2) following ‘true’ branch (when ‘argc > 0’)... | 213 | if (matches(*argv, "limit") == 0) { | | ~~~~~~~~~~~~~~~~~~~~~~~~ | | || | | |(3) ...to here | | (4) following ‘true’ branch... |...... | 219 | } else if (matches(*argv, "latency") == 0 || | | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | | || | | | |(5) ...to here (8) following ‘true’ branch... | | (6) following ‘true’ branch... | 220 | matches(*argv, "delay") == 0) { | | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | | | | | (7) ...to here |...... | 243 | } else if (matches(*argv, "loss") == 0 || | | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | | || | | | |(9) ...to here (12) following ‘true’ branch... | | (10) following ‘true’ branch... | 244 | matches(*argv, "drop") == 0) { | | ~~~~~~~~~~~~~~~~~~~~~~~~~~~ | | | | | (11) ...to here |...... | 366 | } else if (matches(*argv, "ecn") == 0) { | | ~~~~~~~~~~~~~~~~~~~~~~ | | || | | |(13) ...to here | | (14) following ‘true’ branch... | 367 | present[TCA_NETEM_ECN] = 1; | 368 | } else if (matches(*argv, "reorder") == 0) { | | ~~~~~~~~~~~~~~~~~~~~~~~~~~ | | || | | |(15) ...to here | | (16) following ‘true’ branch... |...... | 383 | } else if (matches(*argv, "corrupt") == 0) { | | ~~~~~~~~~~~~~~~~~~~~~~~~~~ | | || | | |(17) ...to here | | (18) following ‘true’ branch... |...... | 398 | } else if (matches(*argv, "gap") == 0) { | | ~~~~~~~~~~~~~~~~~~~~~~ | | || | | |(19) ...to here | | (20) following ‘true’ branch... |...... | 404 | } else if (matches(*argv, "duplicate") == 0) { | | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | | || | | |(21) ...to here | | (22) following ‘true’ branch... |...... | 417 | } else if (matches(*argv, "distribution") == 0) { | | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | | || | | |(23) ...to here | | (24) following ‘false’ branch... | ‘netem_parse_opt’: event 25 | |../include/utils.h:50:29: | 50 | #define NEXT_ARG() do { argv++; if (--argc <= 0) incomplete_command(); } while(0) | | ~~~~^~ | | | | | (25) ...to here q_netem.c:418:25: note: in expansion of macro ‘NEXT_ARG’ | 418 | NEXT_ARG(); | | ^~~~~~~~ | ‘netem_parse_opt’: event 26 | |../include/utils.h:50:36: | 50 | #define NEXT_ARG() do { argv++; if (--argc <= 0) incomplete_command(); } while(0) | | ^ | | | | | (26) following ‘false’ branch (when ‘argc != 0’)... q_netem.c:418:25: note: in expansion of macro ‘NEXT_ARG’ | 418 | NEXT_ARG(); | | ^~~~~~~~ | ‘netem_parse_opt’: events 27-29 | | 419 | dist_data = calloc(sizeof(dist_data[0]), MAX_DIST); | | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | | | | | (27) ...to here | | (28) this call could return NULL | 420 | dist_size = get_distribution(*argv, dist_data, MAX_DIST); | | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | | | | | (29) calling ‘get_distribution’ from ‘netem_parse_opt’ | +--> ‘get_distribution’: events 30-31 | | 124 | static int get_distribution(const char *type, __s16 *data, int maxdata) | | ^~~~~~~~~~~~~~~~ | | | | | (30) entry to ‘get_distribution’ |...... | 135 | if (f == NULL) { | | ~ | | | | | (31) following ‘false’ branch (when ‘f’ is non-NULL)... | ‘get_distribution’: event 32 | |cc1: | (32): ...to here | ‘get_distribution’: events 33-35 | | 142 | while (getline(&line, &len, f) != -1) { | | ~~~~~~~~~~~~~~~~~~~~~~~~^~~~~ | | | | | (33) following ‘true’ branch... |...... | 145 | if (*line == '\n' || *line == '#') | | ~~~~~~ | | || | | |(34) ...to here | | (35) following ‘false’ branch... | ‘get_distribution’: event 36 | |cc1: | (36): ...to here | ‘get_distribution’: events 37-41 | | 150 | if (endp == p) | | ^ | | | | | (37) following ‘false’ branch... |...... | 153 | if (n >= maxdata) { | | ~ | | | | | (38) ...to here | | (39) following ‘false’ branch (when ‘n < maxdata’)... |...... | 159 | data[n++] = x; | | ~~~~~~~~~~~~~ | | | | | | | (41) ‘data + (long unsigned int)n * 2’ could be NULL: unchecked value from (28) | | (40) ...to here | Fixes: c1b81cb5fe92 ("netem potential dist table overflow") Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
* m_action: fix warning of overwrite of const stringStephen Hemminger2023-05-131-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The function get_action_kind() searches first for the given action, then rescans on failure for "gact". In the process, it would overwrite the argument. Avoid the warning by using a const argument and not copying. The problem dates back to pre-git history. m_action.c: In function ‘get_action_kind’: m_action.c:126:17: warning: write to string literal [-Wanalyzer-write-to-string-literal] 126 | strcpy(str, "gact"); | ^~~~~~~~~~~~~~~~~~~ ‘do_action’: events 1-6 | | 853 | int do_action(int argc, char **argv) | | ^~~~~~~~~ | | | | | (1) entry to ‘do_action’ |...... | 858 | while (argc > 0) { | | ~~~~~~~~ | | | | | (2) following ‘true’ branch... | 859 | | 860 | if (matches(*argv, "add") == 0) { | | ~~~~~~~~~~~~~~~~~~~~~~ | | || | | |(3) ...to here | | (4) following ‘false’ branch... | 861 | ret = tc_action_modify(RTM_NEWACTION, | | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | | | | | (5) ...to here | | (6) calling ‘tc_action_modify’ from ‘do_action’ | 862 | NLM_F_EXCL | NLM_F_CREATE, | | ~~~~~~~~~~~~~~~~~~~~~~~~~~ | 863 | &argc, &argv); | | ~~~~~~~~~~~~~ | +--> ‘tc_action_modify’: events 7-8 | | 715 | static int tc_action_modify(int cmd, unsigned int flags, | | ^~~~~~~~~~~~~~~~ | | | | | (7) entry to ‘tc_action_modify’ |...... | 735 | if (parse_action(&argc, &argv, TCA_ACT_TAB, &req.n)) { | | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | | | | | (8) calling ‘parse_action’ from ‘tc_action_modify’ | +--> ‘parse_action’: events 9-18 | | 203 | int parse_action(int *argc_p, char ***argv_p, int tca_id, struct nlmsghdr *n) | | ^~~~~~~~~~~~ | | | | | (9) entry to ‘parse_action’ |...... | 217 | if (argc <= 0) | | ~ | | | | | (10) following ‘false’ branch... |...... | 220 | tail2 = addattr_nest(n, MAX_MSG, tca_id); | | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | | | | | (11) ...to here | 221 | | 222 | while (argc > 0) { | | ~~~~~~~~ | | | | | (12) following ‘true’ branch... | 223 | | 224 | memset(k, 0, sizeof(k)); | | ~~~~~~~~~~~~~~~~~~~~~~~ | | | | | (13) ...to here | 225 | | 226 | if (strcmp(*argv, "action") == 0) { | | ~ | | | | | (14) following ‘true’ branch (when the strings are equal)... | 227 | argc--; | | ~~~~~~ | | | | | (15) ...to here |...... | 231 | if (!gact_ld) | | ~ | | | | | (16) following ‘true’ branch... | 232 | get_action_kind("gact"); | | ~~~~~~~~~~~~~~~~~~~~~~~ | | | | | (17) ...to here | | (18) calling ‘get_action_kind’ from ‘parse_action’ | +--> ‘get_action_kind’: events 19-24 | | 86 | static struct action_util *get_action_kind(char *str) | | ^~~~~~~~~~~~~~~ | | | | | (19) entry to ‘get_action_kind’ |...... | 114 | if (a == NULL) | | ~ | | | | | (20) following ‘true’ branch (when ‘a’ is NULL)... | 115 | goto noexist; | | ~~~~ | | | | | (21) ...to here |...... | 124 | if (!looked4gact) { | | ~ | | | | | (22) following ‘true’ branch (when ‘looked4gact == 0’)... | 125 | looked4gact = 1; | 126 | strcpy(str, "gact"); | | ~~~~~~~~~~~~~~~~~~~ | | | | | (23) ...to here | | (24) write to string literal here | Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
* tc_exec: don't dereference NULL on calloc failureStephen Hemminger2023-05-131-0/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Reported as: tc_exec.c: In function ‘do_exec’: tc_exec.c:103:18: warning: dereference of NULL ‘eu’ [CWE-476] [-Wanalyzer-null-dereference] 103 | return eu->parse_eopt(eu, argc, argv); | ~~^~~~~~~~~~~~ ‘do_exec’: events 1-6 | | 81 | int do_exec(int argc, char **argv) | | ^~~~~~~ | | | | | (1) entry to ‘do_exec’ |...... | 86 | if (argc < 1) { | | ~ | | | | | (2) following ‘false’ branch (when ‘argc > 0’)... |...... | 91 | if (matches(*argv, "help") == 0) { | | ~~~~~~~~~~~~~~~~~~~~~~~ | | || | | |(3) ...to here | | (4) following ‘true’ branch... |...... | 96 | strncpy(kind, *argv, sizeof(kind) - 1); | | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | | | | | (5) ...to here | 97 | | 98 | eu = get_exec_kind(kind); | | ~~~~~~~~~~~~~~~~~~~ | | | | | (6) calling ‘get_exec_kind’ from ‘do_exec’ | +--> ‘get_exec_kind’: events 7-10 | | 40 | static struct exec_util *get_exec_kind(const char *name) | | ^~~~~~~~~~~~~ | | | | | (7) entry to ‘get_exec_kind’ |...... | 63 | if (eu == NULL) | | ~ | | | | | (8) following ‘true’ branch (when ‘eu’ is NULL)... | 64 | goto noexist; | | ~~~~ | | | | | (9) ...to here |...... | 72 | if (eu) { | | ~ | | | | | (10) following ‘false’ branch (when ‘eu’ is NULL)... | ‘get_exec_kind’: event 11 | |cc1: | (11): ...to here | <------+ | ‘do_exec’: events 12-13 | | 98 | eu = get_exec_kind(kind); | | ^~~~~~~~~~~~~~~~~~~ | | | | | (12) return of NULL to ‘do_exec’ from ‘get_exec_kind’ |...... | 103 | return eu->parse_eopt(eu, argc, argv); | | ~~~~~~~~~~~~~~ | | | | | (13) dereference of NULL ‘eu’ | Fixes: 4bd624467bc6 ("tc: built-in eBPF exec proxy") Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
* tc_util fix unitialized warningStephen Hemminger2023-05-131-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | tc_util.c: In function ‘parse_action_control_slash_spaces’: tc_util.c:488:28: warning: use of uninitialized value ‘result2’ [CWE-457] [-Wanalyzer-use-of-uninitialized-value] 488 | *result2_p = result2; | ~~~~~~~~~~~^~~~~~~~~ ‘parse_action_control_slash_spaces’: events 1-5 | | 455 | static int parse_action_control_slash_spaces(int *argc_p, char ***argv_p, | | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | | | | | (1) entry to ‘parse_action_control_slash_spaces’ |...... | 461 | int result1 = -1, result2; | | ~~~~~~~ | | | | | (2) region created on stack here | | (3) capacity: 4 bytes |...... | 467 | switch (ok) { | | ~~~~~~ | | | | | (4) following ‘case 0:’ branch... |...... | 475 | ret = parse_action_control(&argc, &argv, | | ~ | | | | | (5) inlined call to ‘parse_action_control’ from ‘parse_action_control_slash_spaces’ | +--> ‘parse_action_control’: events 6-7 | | 432 | return __parse_action_control(argc_p, argv_p, result_p, | | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | | | | | (6) ...to here | | (7) calling ‘__parse_action_control’ from ‘parse_action_control_slash_spaces’ | 433 | allow_num, false); | | ~~~~~~~~~~~~~~~~~ | ‘__parse_action_control’: events 8-11 | | 371 | static int __parse_action_control(int *argc_p, char ***argv_p, int *result_p, | | ^~~~~~~~~~~~~~~~~~~~~~ | | | | | (8) entry to ‘__parse_action_control’ |...... | 378 | if (!argc) | | ~ | | | | | (9) following ‘false’ branch (when ‘argc != 0’)... | 379 | return -1; | 380 | if (action_a2n(*argv, &result, allow_num) == -1) { | | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | | | | | (10) ...to here | | (11) calling ‘action_a2n’ from ‘__parse_action_control’ | +--> ‘action_a2n’: events 12-16 | | 335 | int action_a2n(char *arg, int *result, bool allow_num) | | ^~~~~~~~~~ | | | | | (12) entry to ‘action_a2n’ |...... | 356 | for (iter = a2n; iter->a; iter++) { | | ~~~~ | | | | | (13) following ‘true’ branch... | 357 | if (matches(arg, iter->a) != 0) | | ~~~~~~~~~~~~~~~~~~~~~ | | | | | (14) ...to here |...... | 366 | if (result) | | ~ | | | | | (15) following ‘true’ branch (when ‘result’ is non-NULL)... | 367 | *result = n; | | ~~~~~~~~~~~ | | | | | (16) ...to here | <------+ | ‘__parse_action_control’: event 17 | | 380 | if (action_a2n(*argv, &result, allow_num) == -1) { | | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | | | | | (17) returning to ‘__parse_action_control’ from ‘action_a2n’ | <------+ | ‘parse_action_control_slash_spaces’: event 18 | | 475 | ret = parse_action_control(&argc, &argv, | | ^ | | | | | (18) inlined call to ‘parse_action_control’ from ‘parse_action_control_slash_spaces’ | +--> ‘parse_action_control’: event 19 | | 432 | return __parse_action_control(argc_p, argv_p, result_p, | | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | | | | | (19) returning to ‘parse_action_control_slash_spaces’ from ‘__parse_action_control’ | 433 | allow_num, false); | | ~~~~~~~~~~~~~~~~~ | <------+ | ‘parse_action_control_slash_spaces’: events 20-24 | | 477 | if (ret) | | ^ | | | | | (20) following ‘false’ branch... | 478 | return ret; | 479 | ok++; | | ~~~~ | | | | | (21) ...to here |...... | 487 | if (ok == 2) | | ~ | | | | | (22) following ‘true’ branch (when ‘ok == 2’)... | 488 | *result2_p = result2; | | ~~~~~~~~~~~~~~~~~~~~ | | | | | (23) ...to here | | (24) use of uninitialized value ‘result2’ here | tc_util.c:488:28: warning: use of uninitialized value ‘result2’ [CWE-457] [-Wanalyzer-use-of-uninitialized-value] 488 | *result2_p = result2; | ~~~~~~~~~~~^~~~~~~~~ ‘parse_action_control_slash’: events 1-5 | | 505 | int parse_action_control_slash(int *argc_p, char ***argv_p, | | ^~~~~~~~~~~~~~~~~~~~~~~~~~ | | | | | (1) entry to ‘parse_action_control_slash’ |...... | 510 | char *p = strchr(*argv, '/'); | | ~~~~~~~~~~~~~~~~~~ | | | | | (2) when ‘strchr’ returns NULL | 511 | | 512 | if (!p) | | ~ | | | | | (3) following ‘true’ branch (when ‘p’ is NULL)... | 513 | return parse_action_control_slash_spaces(argc_p, argv_p, | | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | | | | | (4) ...to here | | (5) calling ‘parse_action_control_slash_spaces’ from ‘parse_action_control_slash’ | 514 | result1_p, result2_p, | | ~~~~~~~~~~~~~~~~~~~~~ | 515 | allow_num); | | ~~~~~~~~~~ | +--> ‘parse_action_control_slash_spaces’: events 6-10 | | 455 | static int parse_action_control_slash_spaces(int *argc_p, char ***argv_p, | | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | | | | | (6) entry to ‘parse_action_control_slash_spaces’ |...... | 461 | int result1 = -1, result2; | | ~~~~~~~ | | | | | (7) region created on stack here | | (8) capacity: 4 bytes |...... | 467 | switch (ok) { | | ~~~~~~ | | | | | (9) following ‘case 0:’ branch... |...... | 475 | ret = parse_action_control(&argc, &argv, | | ~ | | | | | (10) inlined call to ‘parse_action_control’ from ‘parse_action_control_slash_spaces’ | +--> ‘parse_action_control’: events 11-12 | | 432 | return __parse_action_control(argc_p, argv_p, result_p, | | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | | | | | (11) ...to here | | (12) calling ‘__parse_action_control’ from ‘parse_action_control_slash_spaces’ | 433 | allow_num, false); | | ~~~~~~~~~~~~~~~~~ | ‘__parse_action_control’: events 13-16 | | 371 | static int __parse_action_control(int *argc_p, char ***argv_p, int *result_p, | | ^~~~~~~~~~~~~~~~~~~~~~ | | | | | (13) entry to ‘__parse_action_control’ |...... | 378 | if (!argc) | | ~ | | | | | (14) following ‘false’ branch (when ‘argc != 0’)... | 379 | return -1; | 380 | if (action_a2n(*argv, &result, allow_num) == -1) { | | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | | | | | (15) ...to here | | (16) calling ‘action_a2n’ from ‘__parse_action_control’ | +--> ‘action_a2n’: events 17-21 | | 335 | int action_a2n(char *arg, int *result, bool allow_num) | | ^~~~~~~~~~ | | | | | (17) entry to ‘action_a2n’ |...... | 356 | for (iter = a2n; iter->a; iter++) { | | ~~~~ | | | | | (18) following ‘true’ branch... | 357 | if (matches(arg, iter->a) != 0) | | ~~~~~~~~~~~~~~~~~~~~~ | | | | | (19) ...to here |...... | 366 | if (result) | | ~ | | | | | (20) following ‘true’ branch (when ‘result’ is non-NULL)... | 367 | *result = n; | | ~~~~~~~~~~~ | | | | | (21) ...to here | <------+ | ‘__parse_action_control’: event 22 | | 380 | if (action_a2n(*argv, &result, allow_num) == -1) { | | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | | | | | (22) returning to ‘__parse_action_control’ from ‘action_a2n’ | <------+ | ‘parse_action_control_slash_spaces’: event 23 | | 475 | ret = parse_action_control(&argc, &argv, | | ^ | | | | | (23) inlined call to ‘parse_action_control’ from ‘parse_action_control_slash_spaces’ | +--> ‘parse_action_control’: event 24 | | 432 | return __parse_action_control(argc_p, argv_p, result_p, | | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | | | | | (24) returning to ‘parse_action_control_slash_spaces’ from ‘__parse_action_control’ | 433 | allow_num, false); | | ~~~~~~~~~~~~~~~~~ | <------+ | ‘parse_action_control_slash_spaces’: events 25-29 | | 477 | if (ret) | | ^ | | | | | (25) following ‘false’ branch... | 478 | return ret; | 479 | ok++; | | ~~~~ | | | | | (26) ...to here |...... | 487 | if (ok == 2) | | ~ | | | | | (27) following ‘true’ branch (when ‘ok == 2’)... | 488 | *result2_p = result2; | | ~~~~~~~~~~~~~~~~~~~~ | | | | | (28) ...to here | | (29) use of uninitialized value ‘result2’ here | Fixes: e67aba559581 ("tc: actions: add helpers to parse and print control actions") Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
* tc_filter: fix unitialized warningStephen Hemminger2023-05-131-3/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | When run with -fanalyzer. tc_filter.c: In function ‘tc_filter_list’: tc_filter.c:718:17: warning: use of uninitialized value ‘chain_index’ [CWE-457] [-Wanalyzer-use-of-uninitialized-value] 718 | addattr32(&req.n, sizeof(req), TCA_CHAIN, chain_index); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ‘do_chain’: events 1-4 | | 772 | int do_chain(int argc, char **argv) | | ^~~~~~~~ | | | | | (1) entry to ‘do_chain’ | 773 | { | 774 | if (argc < 1) | | ~ | | | | | (2) following ‘true’ branch (when ‘argc <= 0’)... | 775 | return tc_filter_list(RTM_GETCHAIN, 0, NULL); | | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | | | | | (3) ...to here | | (4) calling ‘tc_filter_list’ from ‘do_chain’ | +--> ‘tc_filter_list’: events 5-8 | | 582 | static int tc_filter_list(int cmd, int argc, char **argv) | | ^~~~~~~~~~~~~~ | | | | | (5) entry to ‘tc_filter_list’ |...... | 597 | __u32 chain_index; | | ~~~~~~~~~~~ | | | | | (6) region created on stack here | | (7) capacity: 4 bytes |...... | 601 | while (argc > 0) { | | ~~~~~~~~ | | | | | (8) following ‘false’ branch (when ‘argc <= 0’)... | ‘tc_filter_list’: event 9 | |../include/uapi/linux/pkt_sched.h:72:35: | 72 | #define TC_H_MAKE(maj,min) (((maj)&TC_H_MAJ_MASK)|((min)&TC_H_MIN_MASK)) | | ~~~~~~^~~~~~~~~~~~~~~ | | | | | (9) ...to here tc_filter.c:698:26: note: in expansion of macro ‘TC_H_MAKE’ | 698 | req.t.tcm_info = TC_H_MAKE(prio<<16, protocol); | | ^~~~~~~~~ | ‘tc_filter_list’: events 10-16 | | 702 | if (d[0]) { | | ^ | | | | | (10) following ‘false’ branch... |...... | 707 | } else if (block_index) { | | ~~~~~~~~~~~~ | | || | | |(11) ...to here | | (12) following ‘false’ branch... |...... | 717 | if (filter_chain_index_set) | | ~~~~~~~~~~~~~~~~~~~~~~~ | | || | | |(13) ...to here | | (14) following ‘true’ branch... | 718 | addattr32(&req.n, sizeof(req), TCA_CHAIN, chain_index); | | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | | | | | (15) ...to here | | (16) use of uninitialized value ‘chain_index’ here | tc_filter.c:718:17: warning: use of uninitialized value ‘chain_index’ [CWE-457] [-Wanalyzer-use-of-uninitialized-value] 718 | addattr32(&req.n, sizeof(req), TCA_CHAIN, chain_index); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ‘do_filter’: events 1-4 | | 744 | int do_filter(int argc, char **argv) | | ^~~~~~~~~ | | | | | (1) entry to ‘do_filter’ | 745 | { | 746 | if (argc < 1) | | ~ | | | | | (2) following ‘true’ branch (when ‘argc <= 0’)... | 747 | return tc_filter_list(RTM_GETTFILTER, 0, NULL); | | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | | | | | (3) ...to here | | (4) calling ‘tc_filter_list’ from ‘do_filter’ | +--> ‘tc_filter_list’: events 5-8 | | 582 | static int tc_filter_list(int cmd, int argc, char **argv) | | ^~~~~~~~~~~~~~ | | | | | (5) entry to ‘tc_filter_list’ |...... | 597 | __u32 chain_index; | | ~~~~~~~~~~~ | | | | | (6) region created on stack here | | (7) capacity: 4 bytes |...... | 601 | while (argc > 0) { | | ~~~~~~~~ | | | | | (8) following ‘false’ branch (when ‘argc <= 0’)... | ‘tc_filter_list’: event 9 | |../include/uapi/linux/pkt_sched.h:72:35: | 72 | #define TC_H_MAKE(maj,min) (((maj)&TC_H_MAJ_MASK)|((min)&TC_H_MIN_MASK)) | | ~~~~~~^~~~~~~~~~~~~~~ | | | | | (9) ...to here tc_filter.c:698:26: note: in expansion of macro ‘TC_H_MAKE’ | 698 | req.t.tcm_info = TC_H_MAKE(prio<<16, protocol); | | ^~~~~~~~~ | ‘tc_filter_list’: events 10-16 | | 702 | if (d[0]) { | | ^ | | | | | (10) following ‘false’ branch... |...... | 707 | } else if (block_index) { | | ~~~~~~~~~~~~ | | || | | |(11) ...to here | | (12) following ‘false’ branch... |...... | 717 | if (filter_chain_index_set) | | ~~~~~~~~~~~~~~~~~~~~~~~ | | || | | |(13) ...to here | | (14) following ‘true’ branch... | 718 | addattr32(&req.n, sizeof(req), TCA_CHAIN, chain_index); | | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | | | | | (15) ...to here | | (16) use of uninitialized value ‘chain_index’ here | Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
* iproute_lwtunnel: fix possible use of NULL when malloc() failsStephen Hemminger2023-05-131-5/+13
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | iproute_lwtunnel.c: In function ‘parse_srh’: iproute_lwtunnel.c:903:9: warning: use of possibly-NULL ‘srh’ where non-null expected [CWE-690] [-Wanalyzer-possible-null-argument] 903 | memset(srh, 0, srhlen); | ^~~~~~~~~~~~~~~~~~~~~~ ‘parse_srh’: events 1-2 | | 902 | srh = malloc(srhlen); | | ^~~~~~~~~~~~~~ | | | | | (1) this call could return NULL | 903 | memset(srh, 0, srhlen); | | ~~~~~~~~~~~~~~~~~~~~~~ | | | | | (2) argument 1 (‘srh’) from (1) could be NULL where non-null expected | In file included from iproute_lwtunnel.c:13: /usr/include/string.h:61:14: note: argument 1 of ‘memset’ must be non-null 61 | extern void *memset (void *__s, int __c, size_t __n) __THROW __nonnull ((1)); | ^~~~~~ iproute_lwtunnel.c: In function ‘parse_encap_seg6’: iproute_lwtunnel.c:980:9: warning: use of possibly-NULL ‘tuninfo’ where non-null expected [CWE-690] [-Wanalyzer-possible-null-argument] 980 | memset(tuninfo, 0, sizeof(*tuninfo) + srhlen); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ‘parse_encap_seg6’: events 1-2 | | 934 | static int parse_encap_seg6(struct rtattr *rta, size_t len, int *argcp, | | ^~~~~~~~~~~~~~~~ | | | | | (1) entry to ‘parse_encap_seg6’ |...... | 976 | srh = parse_srh(segbuf, hmac, encap); | | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | | | | | (2) calling ‘parse_srh’ from ‘parse_encap_seg6’ | +--> ‘parse_srh’: events 3-5 | | 882 | static struct ipv6_sr_hdr *parse_srh(char *segbuf, int hmac, bool encap) | | ^~~~~~~~~ | | | | | (3) entry to ‘parse_srh’ |...... | 922 | if (hmac) { | | ~ | | | | | (4) following ‘false’ branch (when ‘hmac == 0’)... |...... | 931 | return srh; | | ~~~ | | | | | (5) ...to here | <------+ | ‘parse_encap_seg6’: events 6-8 | | 976 | srh = parse_srh(segbuf, hmac, encap); | | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | | | | | (6) returning to ‘parse_encap_seg6’ from ‘parse_srh’ |...... | 979 | tuninfo = malloc(sizeof(*tuninfo) + srhlen); | | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | | | | | (7) this call could return NULL | 980 | memset(tuninfo, 0, sizeof(*tuninfo) + srhlen); | | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | | | | | (8) argument 1 (‘tuninfo’) from (7) could be NULL where non-null expected | /usr/include/string.h:61:14: note: argument 1 of ‘memset’ must be non-null 61 | extern void *memset (void *__s, int __c, size_t __n) __THROW __nonnull ((1)); | ^~~~~~ iproute_lwtunnel.c: In function ‘parse_rpl_srh’: iproute_lwtunnel.c:1018:21: warning: dereference of possibly-NULL ‘srh’ [CWE-690] [-Wanalyzer-possible-null-dereference] 1018 | srh->hdrlen = (srhlen >> 3) - 1; | ~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~ ‘parse_rpl_srh’: events 1-2 | | 1016 | srh = calloc(1, srhlen); | | ^~~~~~~~~~~~~~~~~ | | | | | (1) this call could return NULL | 1017 | | 1018 | srh->hdrlen = (srhlen >> 3) - 1; | | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | | | | | (2) ‘srh’ could be NULL: unchecked value from (1) | Fixes: 00e76d4da37f ("iproute: add helper functions for SRH processing") Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
* ipmaddr: fix dereference of NULL on malloc() failureStephen Hemminger2023-05-131-1/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Found by -fanalyzer. This is a bug since beginning of initial versions of ip multicast support (pre git). ipmaddr.c: In function ‘read_dev_mcast’: ipmaddr.c:105:25: warning: dereference of possibly-NULL ‘ma’ [CWE-690] [-Wanalyzer-possible-null-dereference] 105 | memcpy(ma, &m, sizeof(m)); | ^~~~~~~~~~~~~~~~~~~~~~~~~ ‘do_multiaddr’: events 1-4 | | 354 | int do_multiaddr(int argc, char **argv) | | ^~~~~~~~~~~~ | | | | | (1) entry to ‘do_multiaddr’ | 355 | { | 356 | if (argc < 1) | | ~ | | | | | (2) following ‘true’ branch (when ‘argc <= 0’)... | 357 | return multiaddr_list(0, NULL); | | ~~~~~~~~~~~~~~~~~~~~~~~ | | | | | (3) ...to here | | (4) calling ‘multiaddr_list’ from ‘do_multiaddr’ | +--> ‘multiaddr_list’: events 5-10 | | 255 | static int multiaddr_list(int argc, char **argv) | | ^~~~~~~~~~~~~~ | | | | | (5) entry to ‘multiaddr_list’ |...... | 262 | while (argc > 0) { | | ~~~~~~~~ | | | | | (6) following ‘false’ branch (when ‘argc <= 0’)... |...... | 275 | if (!filter.family || filter.family == AF_PACKET) | | ~ ~~~~~~~~~~~~~ | | | | | | | (7) ...to here | | (8) following ‘true’ branch... | 276 | read_dev_mcast(&list); | | ~~~~~~~~~~~~~~~~~~~~~ | | | | | (9) ...to here | | (10) calling ‘read_dev_mcast’ from ‘multiaddr_list’ | +--> ‘read_dev_mcast’: events 11-12 | | 82 | static void read_dev_mcast(struct ma_info **result_p) | | ^~~~~~~~~~~~~~ | | | | | (11) entry to ‘read_dev_mcast’ |...... | 87 | if (!fp) | | ~ | | | | | (12) following ‘false’ branch (when ‘fp’ is non-NULL)... | ‘read_dev_mcast’: event 13 | |cc1: | (13): ...to here | ‘read_dev_mcast’: events 14-17 | | 90 | while (fgets(buf, sizeof(buf), fp)) { | | ^~~~~ | | | | | (14) following ‘true’ branch... | 91 | char hexa[256]; | 92 | struct ma_info m = { .addr.family = AF_PACKET }; | | ~ | | | | | (15) ...to here |...... | 103 | struct ma_info *ma = malloc(sizeof(m)); | | ~~~~~~~~~~~~~~~~~ | | | | | (16) this call could return NULL | 104 | | 105 | memcpy(ma, &m, sizeof(m)); | | ~~~~~~~~~~~~~~~~~~~~~~~~~ | | | | | (17) ‘ma’ could be NULL: unchecked value from (16) | ipmaddr.c: In function ‘read_igmp’: ipmaddr.c:152:17: warning: dereference of possibly-NULL ‘ma’ [CWE-690] [-Wanalyzer-possible-null-dereference] 152 | memcpy(ma, &m, sizeof(m)); | ^~~~~~~~~~~~~~~~~~~~~~~~~ ‘do_multiaddr’: events 1-4 | | 354 | int do_multiaddr(int argc, char **argv) | | ^~~~~~~~~~~~ | | | | | (1) entry to ‘do_multiaddr’ | 355 | { | 356 | if (argc < 1) | | ~ | | | | | (2) following ‘true’ branch (when ‘argc <= 0’)... | 357 | return multiaddr_list(0, NULL); | | ~~~~~~~~~~~~~~~~~~~~~~~ | | | | | (3) ...to here | | (4) calling ‘multiaddr_list’ from ‘do_multiaddr’ | +--> ‘multiaddr_list’: events 5-10 | | 255 | static int multiaddr_list(int argc, char **argv) | | ^~~~~~~~~~~~~~ | | | | | (5) entry to ‘multiaddr_list’ |...... | 262 | while (argc > 0) { | | ~~~~~~~~ | | | | | (6) following ‘false’ branch (when ‘argc <= 0’)... |...... | 275 | if (!filter.family || filter.family == AF_PACKET) | | ~~~~~~~~~~~~~ | | | | | (7) ...to here | 276 | read_dev_mcast(&list); | 277 | if (!filter.family || filter.family == AF_INET) | | ~ | | | | | (8) following ‘true’ branch... | 278 | read_igmp(&list); | | ~~~~~~~~~~~~~~~~ | | | | | (9) ...to here | | (10) calling ‘read_igmp’ from ‘multiaddr_list’ | +--> ‘read_igmp’: events 11-14 | | 116 | static void read_igmp(struct ma_info **result_p) | | ^~~~~~~~~ | | | | | (11) entry to ‘read_igmp’ |...... | 126 | if (!fp) | | ~ | | | | | (12) following ‘false’ branch (when ‘fp’ is non-NULL)... | 127 | return; | 128 | if (!fgets(buf, sizeof(buf), fp)) { | | ~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~ | | | | | | | (13) ...to here | | (14) following ‘false’ branch... | ‘read_igmp’: event 15 | |cc1: | (15): ...to here | ‘read_igmp’: events 16-19 | | 133 | while (fgets(buf, sizeof(buf), fp)) { | | ^~~~~ | | | | | (16) following ‘true’ branch... |...... | 136 | if (buf[0] != '\t') { | | ~~~~~~ | | | | | (17) ...to here |...... | 151 | ma = malloc(sizeof(m)); | | ~~~~~~~~~~~~~~~~~ | | | | | (18) this call could return NULL | 152 | memcpy(ma, &m, sizeof(m)); | | ~~~~~~~~~~~~~~~~~~~~~~~~~ | | | | | (19) ‘ma’ could be NULL: unchecked value from (18) | ipmaddr.c: In function ‘read_igmp6’: ipmaddr.c:181:25: warning: dereference of possibly-NULL ‘ma’ [CWE-690] [-Wanalyzer-possible-null-dereference] 181 | memcpy(ma, &m, sizeof(m)); | ^~~~~~~~~~~~~~~~~~~~~~~~~ ‘do_multiaddr’: events 1-4 | | 354 | int do_multiaddr(int argc, char **argv) | | ^~~~~~~~~~~~ | | | | | (1) entry to ‘do_multiaddr’ | 355 | { | 356 | if (argc < 1) | | ~ | | | | | (2) following ‘true’ branch (when ‘argc <= 0’)... | 357 | return multiaddr_list(0, NULL); | | ~~~~~~~~~~~~~~~~~~~~~~~ | | | | | (3) ...to here | | (4) calling ‘multiaddr_list’ from ‘do_multiaddr’ | +--> ‘multiaddr_list’: events 5-10 | | 255 | static int multiaddr_list(int argc, char **argv) | | ^~~~~~~~~~~~~~ | | | | | (5) entry to ‘multiaddr_list’ |...... | 262 | while (argc > 0) { | | ~~~~~~~~ | | | | | (6) following ‘false’ branch (when ‘argc <= 0’)... |...... | 275 | if (!filter.family || filter.family == AF_PACKET) | | ~~~~~~~~~~~~~ | | | | | (7) ...to here |...... | 279 | if (!filter.family || filter.family == AF_INET6) | | ~ | | | | | (8) following ‘true’ branch... | 280 | read_igmp6(&list); | | ~~~~~~~~~~~~~~~~~ | | | | | (9) ...to here | | (10) calling ‘read_igmp6’ from ‘multiaddr_list’ | +--> ‘read_igmp6’: events 11-12 | | 159 | static void read_igmp6(struct ma_info **result_p) | | ^~~~~~~~~~ | | | | | (11) entry to ‘read_igmp6’ |...... | 164 | if (!fp) | | ~ | | | | | (12) following ‘false’ branch (when ‘fp’ is non-NULL)... | ‘read_igmp6’: event 13 | |cc1: | (13): ...to here | ‘read_igmp6’: events 14-17 | | 167 | while (fgets(buf, sizeof(buf), fp)) { | | ^~~~~ | | | | | (14) following ‘true’ branch... | 168 | char hexa[256]; | 169 | struct ma_info m = { .addr.family = AF_INET6 }; | | ~ | | | | | (15) ...to here |...... | 179 | struct ma_info *ma = malloc(sizeof(m)); | | ~~~~~~~~~~~~~~~~~ | | | | | (16) this call could return NULL | 180 | | 181 | memcpy(ma, &m, sizeof(m)); | | ~~~~~~~~~~~~~~~~~~~~~~~~~ | | | | | (17) ‘ma’ could be NULL: unchecked value from (16) | Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
* lib/fs: fix file leak in task_get_nameStephen Hemminger2023-05-131-1/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Fixes the problem identified -fanalyzer. Why did rdma choose to reimplement the same function as exiting glibc pthread_getname(). fs.c: In function ‘get_task_name’: fs.c:355:12: warning: leak of FILE ‘f’ [CWE-775] [-Wanalyzer-file-leak] 355 | if (!fgets(name, len, f)) | ^ ‘get_task_name’: events 1-9 | | 345 | if (!pid) | | ^ | | | | | (1) following ‘false’ branch (when ‘pid != 0’)... |...... | 348 | if (snprintf(path, sizeof(path), "/proc/%d/comm", pid) >= sizeof(path)) | | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | | || | | |(2) ...to here | | (3) following ‘false’ branch... |...... | 351 | f = fopen(path, "r"); | | ~~~~~~~~~~~~~~~~ | | | | | (4) ...to here | | (5) opened here | 352 | if (!f) | | ~ | | | | | (6) assuming ‘f’ is non-NULL | | (7) following ‘false’ branch (when ‘f’ is non-NULL)... |...... | 355 | if (!fgets(name, len, f)) | | ~ ~~~~~~~~~~~~~~~~~~~ | | | | | | | (8) ...to here | | (9) following ‘true’ branch... | ‘get_task_name’: event 10 | |cc1: | (10): ...to here | ‘get_task_name’: event 11 | | 355 | if (!fgets(name, len, f)) | | ^ | | | | | (11) ‘f’ leaks here; was opened at (5) | fs.c:355:12: warning: leak of ‘f’ [CWE-401] [-Wanalyzer-malloc-leak] ‘get_task_name’: events 1-9 | | 345 | if (!pid) | | ^ | | | | | (1) following ‘false’ branch (when ‘pid != 0’)... |...... | 348 | if (snprintf(path, sizeof(path), "/proc/%d/comm", pid) >= sizeof(path)) | | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | | || | | |(2) ...to here | | (3) following ‘false’ branch... |...... | 351 | f = fopen(path, "r"); | | ~~~~~~~~~~~~~~~~ | | | | | (4) ...to here | | (5) allocated here | 352 | if (!f) | | ~ | | | | | (6) assuming ‘f’ is non-NULL | | (7) following ‘false’ branch (when ‘f’ is non-NULL)... |...... | 355 | if (!fgets(name, len, f)) | | ~ ~~~~~~~~~~~~~~~~~~~ | | | | | | | (8) ...to here | | (9) following ‘true’ branch... | ‘get_task_name’: event 10 | |cc1: | (10): ...to here | ‘get_task_name’: event 11 | | 355 | if (!fgets(name, len, f)) | | ^ | | | | | (11) ‘f’ leaks here; was allocated at (5) Fixes: 81bfd01a4c9e ("lib: move get_task_name() from rdma") Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
* Add MAINTAINERS fileStephen Hemminger2023-05-121-0/+52
| | | | | | | | | | | | Record the maintainers of subsections of iproute2. The subtree maintainers are based off of most recent current patches and maintainer of kernel portion of that subsystem. Acked-by: Nikolay Aleksandrov <razor@blackwall.org> Acked-by: Petr Machata <me@pmachata.org> # For DCB Acked-by: Parav Pandit <parav@nvidia.com> Acked-by: Jiri Pirko <jiri@nvidia.com> Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
* iproute2: optimize code and fix some mem-leak riskzhaoshuang2023-05-1114-12/+34
| | | | | | Signed-off-by: zhaoshuang <izhaoshuang@163.com> Reviewed-by: Pawel Chmielewski <pawel.chmielewski@intel.com> Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
* ipnetns: fix fd leak with 'ip netns set'Nicolas Dichtel2023-05-111-10/+1
| | | | | | | | | | There is no reason to open this netns file. set_netnsid_from_name() uses netns_get_fd() for this purpose and uses the returned fd. Reported-by: Stephen Hemminger <stephen@networkplumber.org> Fixes: d182ee1307c7 ("ipnetns: allow to get and set netns ids") Signed-off-by: Nicolas Dichtel <nicolas.dichtel@6wind.com> Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
* ip-rule: more manual page grammer fixesStephen Hemminger2023-05-111-8/+8
| | | | | | Add missing articles and replace use of passive voice. Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
* remove unnecessary checks for NULL before calling free()Stephen Hemminger2023-05-106-16/+8
| | | | | | | | | The function free() handles the case wher argument is NULL by doing nothing. So the extra checks are not needed. Found by modified version of kernel coccinelle script. Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
* uapi: add capability.hStephen Hemminger2023-05-091-0/+430
| | | | | | | All kernel header files should come from local copy of sanitized headers, rather than relying on what Linux distribution ships. Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
* uapi: update kernel headers 6.4-rc1Stephen Hemminger2023-05-083-5/+7
| | | | Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
* fixed the grammar in ip-rule(8) man pageBilal Khan2023-05-021-1/+1
| | | | | | | a small grammatical error has been idenfied in the ip-rule(8) man page Signed-off-by: Bilal Khan <bilalkhanrecovered@gmail.com> Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
* Merge git://git.kernel.org/pub/scm/network/iproute2/iproute2-nextStephen Hemminger2023-04-2927-62/+874
|\
| * bridge: link: Add support for neigh_vlan_suppress optionIdo Schimmel2023-04-254-0/+45
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Add support for the per-port neigh_vlan_suppress option. Example: # bridge link set dev swp1 neigh_vlan_suppress on # bridge -d -j -p link show dev swp1 [ { "ifindex": 62, "ifname": "swp1", "flags": [ "BROADCAST","NOARP","UP","LOWER_UP" ], "mtu": 1500, "master": "br0", "state": "forwarding", "priority": 32, "cost": 100, "hairpin": false, "guard": false, "root_block": false, "fastleave": false, "learning": true, "flood": true, "mcast_flood": true, "bcast_flood": true, "mcast_router": 1, "mcast_to_unicast": false, "neigh_suppress": false, "neigh_vlan_suppress": true, "vlan_tunnel": false, "isolated": false, "locked": false, "mab": false, "mcast_n_groups": 0, "mcast_max_groups": 0 } ] # bridge -d link show dev swp1 62: swp1: <BROADCAST,NOARP,UP,LOWER_UP> mtu 1500 master br0 state forwarding priority 32 cost 100 hairpin off guard off root_block off fastleave off learning on flood on mcast_flood on bcast_flood on mcast_router 1 mcast_to_unicast off neigh_suppress off neigh_vlan_suppress on vlan_tunnel off isolated off locked off mab off mcast_n_groups 0 mcast_max_groups 0 # bridge link set dev swp1 neigh_vlan_suppress off # bridge -d -j -p link show dev swp1 [ { "ifindex": 62, "ifname": "swp1", "flags": [ "BROADCAST","NOARP","UP","LOWER_UP" ], "mtu": 1500, "master": "br0", "state": "forwarding", "priority": 32, "cost": 100, "hairpin": false, "guard": false, "root_block": false, "fastleave": false, "learning": true, "flood": true, "mcast_flood": true, "bcast_flood": true, "mcast_router": 1, "mcast_to_unicast": false, "neigh_suppress": false, "neigh_vlan_suppress": false, "vlan_tunnel": false, "isolated": false, "locked": false, "mab": false, "mcast_n_groups": 0, "mcast_max_groups": 0 } ] # bridge -d link show dev swp1 62: swp1: <BROADCAST,NOARP,UP,LOWER_UP> mtu 1500 master br0 state forwarding priority 32 cost 100 hairpin off guard off root_block off fastleave off learning on flood on mcast_flood on bcast_flood on mcast_router 1 mcast_to_unicast off neigh_suppress off neigh_vlan_suppress off vlan_tunnel off isolated off locked off mab off mcast_n_groups 0 mcast_max_groups 0 Signed-off-by: Ido Schimmel <idosch@nvidia.com> Reviewed-by: Nikolay Aleksandrov <razor@blackwall.org> Signed-off-by: David Ahern <dsahern@kernel.org>
| * bridge: vlan: Add support for neigh_suppress optionIdo Schimmel2023-04-252-1/+28
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Add support for the per-VLAN neigh_suppress option. Example: # bridge vlan set vid 10 dev swp1 neigh_suppress on # bridge -d -j -p vlan show dev swp1 vid 10 [ { "ifname": "swp1", "vlans": [ { "vlan": 10, "state": "forwarding", "mcast_router": 1, "neigh_suppress": true } ] } ] # bridge -d vlan show dev swp1 vid 10 port vlan-id swp1 10 state forwarding mcast_router 1 neigh_suppress on # bridge vlan set vid 10 dev swp1 neigh_suppress off # bridge -d -j -p vlan show dev swp1 vid 10 [ { "ifname": "swp1", "vlans": [ { "vlan": 10, "state": "forwarding", "mcast_router": 1, "neigh_suppress": false } ] } ] # bridge -d vlan show dev swp1 vid 10 port vlan-id swp1 10 state forwarding mcast_router 1 neigh_suppress off Signed-off-by: Ido Schimmel <idosch@nvidia.com> Reviewed-by: Nikolay Aleksandrov <razor@blackwall.org> Signed-off-by: David Ahern <dsahern@kernel.org>
| * Merge branch 'preemptible-traffic-classes' into nextDavid Ahern2023-04-245-27/+227
| |\ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Vladimir Oltean says: ==================== This is the iproute2 support for the tc program to make use of the kernel features added in commit f7d29571ab0a ("Merge branch 'add-kernel-tc-mqprio-and-tc-taprio-support-for-preemptible-traffic-classes'"). ==================== Signed-off-by: David Ahern <dsahern@kernel.org>
| | * tc/taprio: add support for preemptible traffic classesVladimir Oltean2023-04-242-24/+87
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Add support for the same kind of "fp" array argument as in mqprio, except here we already have some handling for per-tc entries (max-sdu). We just need to expand that logic such that we also add (and parse) the FP adminStatus property of each traffic class. Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com> Signed-off-by: David Ahern <dsahern@kernel.org>
| | * tc/mqprio: add support for preemptible traffic classesVladimir Oltean2023-04-242-3/+132
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Add support for the "fp" argument in tc-mqprio, which takes an array of letters "E" (for express) or "P" (for preemptible), one per traffic class, and transforms them into TCA_MQPRIO_TC_ENTRY_FP u32 attributes of the TCA_MQPRIO_TC_ENTRY nest. We also dump these new netlink attributes when they come from the kernel. Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com> Signed-off-by: David Ahern <dsahern@kernel.org>
| | * utils: add max() definitionVladimir Oltean2023-04-241-0/+8
| |/ | | | | | | | | | | | | There is already a min() definition, add this below it. Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com> Signed-off-by: David Ahern <dsahern@kernel.org>
| * Merge remote-tracking branch 'main/main' into nextDavid Ahern2023-04-243-30/+52
| |\ | | | | | | | | | Signed-off-by: David Ahern <dsahern@kernel.org>
| * \ Merge branch 'main' into nextDavid Ahern2023-04-2216-187/+477
| |\ \ | | | | | | | | | | | | Signed-off-by: David Ahern <dsahern@kernel.org>
| * | | Update kernel headersDavid Ahern2023-04-225-11/+88
| | | | | | | | | | | | | | | | | | | | | | | | | | | | Update kernel headers to commit: fbc1449d385d ("Merge tag 'mlx5-updates-2023-04-20' of git://git.kernel.org/pub/scm/linux/kernel/git/saeed/linux") Signed-off-by: David Ahern <dsahern@kernel.org>
| * | | tc: m_tunnel_key: support code for "nofrag" tunnelsDavide Caratti2023-04-072-11/+40
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | add control plane for setting TCA_TUNNEL_KEY_NO_FRAG flag on act_tunnel_key actions. Signed-off-by: Davide Caratti <dcaratti@redhat.com> Reviewed-by: Simon Horman <simon.horman@corigine.com> Signed-off-by: David Ahern <dsahern@kernel.org>
| * | | Update kernel headersDavid Ahern2023-04-071-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | Update kernel headers to commit: e28531143b25 ("net: ethernet: mtk_eth_soc: mtk_ppe: prefer newly added l2 flows") Signed-off-by: David Ahern <dsahern@kernel.org>
| * | | Merge branch 'ip-addr-proto' into nextDavid Ahern2023-03-305-4/+145
| |\ \ \ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Petr Machata says: ==================== IPv4 and IPv6 addresses can be assigned a protocol value that indicates the provenance of the IP address. The attribute is modeled after ip route protocols, and essentially allows the administrator or userspace stack to tag addresses in some way that makes sense to the actor in question. Support for this feature was merged with commit 47f0bd503210 ("net: Add new protocol attribute to IP addresses"), for kernel 5.18. In this patchset, add support for setting the protocol attribute at IP address addition, replacement, and listing requests. ==================== Signed-off-by: David Ahern <dsahern@kernel.org>
| | * | | man: man8: Add man page coverage for "ip address add ... proto"Petr Machata2023-03-301-2/+47
| | | | | | | | | | | | | | | | | | | | | | | | | Signed-off-by: Petr Machata <petrm@nvidia.com> Signed-off-by: David Ahern <dsahern@kernel.org>
| | * | | ip: Support IP address protocolPetr Machata2023-03-304-2/+98
| |/ / / | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | IPv4 and IPv6 addresses can be assigned a protocol value that indicates the provenance of the IP address. The attribute is modeled after ip route protocols, and essentially allows the administrator or userspace stack to tag addresses in some way that makes sense to the actor in question. Support for this feature was merged with commit 47f0bd503210 ("net: Add new protocol attribute to IP addresses"), for kernel 5.18. In this patch, add support for setting the protocol attribute at IP address addition, replacement, and listing requests. An example session with the feature in action: # ip address add dev d 192.0.2.1/28 proto 0xab # ip address show dev d 26: d: <BROADCAST,NOARP> mtu 1500 qdisc noop state DOWN group default qlen 1000 link/ether 06:29:74:fd:1f:eb brd ff:ff:ff:ff:ff:ff inet 192.0.2.1/28 scope global proto 0xab d valid_lft forever preferred_lft forever # ip address replace dev d 192.0.2.1/28 proto 0x11 # ip address show dev d 26: d: <BROADCAST,NOARP> mtu 1500 qdisc noop state DOWN group default qlen 1000 link/ether 06:29:74:fd:1f:eb brd ff:ff:ff:ff:ff:ff inet 192.0.2.1/28 scope global proto 0x11 d valid_lft forever preferred_lft forever A JSON dump. The protocol value is always provided as a string, even in numeric mode, to provide a consistent interface. # ip -j address show dev d | jq [ { "ifindex": 26, "ifname": "d", "flags": [ "BROADCAST", "NOARP" ], "mtu": 1500, "qdisc": "noop", "operstate": "DOWN", "group": "default", "txqlen": 1000, "link_type": "ether", "address": "06:29:74:fd:1f:eb", "broadcast": "ff:ff:ff:ff:ff:ff", "addr_info": [ { "family": "inet", "local": "192.0.2.1", "prefixlen": 28, "scope": "global", "protocol": "0x11", "label": "d", "valid_life_time": 4294967295, "preferred_life_time": 4294967295 } ] } ] Signed-off-by: Petr Machata <petrm@nvidia.com> Signed-off-by: David Ahern <dsahern@kernel.org>
| * | | macvlan: Add bclim parameterHerbert Xu2023-03-302-2/+42
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This patch adds support for setting the broadcast queueing threshold on macvlan devices. This controls which multicast packets will be processed in a workqueue instead of inline. Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au> ip/iplink_macvlan.c | 26 ++++++++++++++++++++++++-- man/man8/ip-link.8.in | 18 ++++++++++++++++++ 3 files changed, 43 insertions(+), 2 deletions(-) Signed-off-by: David Ahern <dsahern@kernel.org>
| * | | Update kernel headersDavid Ahern2023-03-301-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | Update kernel headers to commit: da617cd8d906 ("smsc911x: remove superfluous variable init") Signed-off-by: David Ahern <dsahern@kernel.org>
| * | | Merge branch 'bridge-mdb-vxlan-attr' into nextDavid Ahern2023-03-242-3/+212
| |\ \ \ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Ido Schimmel says: ==================== Add support for new VXLAN MDB attributes. See kernel merge commit abf36703d704 ("Merge branch 'vxlan-MDB-support'") for background and motivation. ==================== Signed-off-by: David Ahern <dsahern@kernel.org>
| | * | | bridge: mdb: Document the catchall MDB entriesIdo Schimmel2023-03-241-0/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Document the catchall MDB entries used to transmit IPv4 and IPv6 unregistered multicast packets. In deployments where inter-subnet multicast forwarding is used, not all the VTEPs in a tenant domain are members in all the broadcast domains. It is therefore advantageous to transmit BULL (broadcast, unknown unicast and link-local multicast) and unregistered IP multicast traffic on different tunnels. If the same tunnel was used, a VTEP only interested in IP multicast traffic would also pull all the BULL traffic and drop it as it is not a member in the originating broadcast domain [1]. [1] https://datatracker.ietf.org/doc/html/draft-ietf-bess-evpn-irb-mcast#section-2.6 Signed-off-by: Ido Schimmel <idosch@nvidia.com> Reviewed-by: Nikolay Aleksandrov <razor@blackwall.org>
| | * | | bridge: mdb: Add outgoing interface supportIdo Schimmel2023-03-242-3/+38
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | In a similar fashion to VXLAN FDB entries, allow user space to program and view the outgoing interface of VXLAN MDB entries. Specifically, add support for the 'MDBE_ATTR_IFINDEX' and 'MDBA_MDB_EATTR_IFINDEX' attributes in request and response messages, respectively. The outgoing interface will be forced during the underlay route lookup and is required when the underlay destination IP is multicast, as the multicast routing tables are not consulted. Example: # bridge mdb add dev vxlan0 port vxlan0 grp 239.1.1.1 permanent dst 198.51.100.1 via dummy10 $ bridge -d -s mdb show dev vxlan0 port vxlan0 grp 239.1.1.1 permanent filter_mode exclude proto static dst 198.51.100.1 via dummy10 0.00 $ bridge -d -s -j -p mdb show [ { "mdb": [ { "index": 10, "dev": "vxlan0", "port": "vxlan0", "grp": "239.1.1.1", "state": "permanent", "filter_mode": "exclude", "protocol": "static", "flags": [ ], "dst": "198.51.100.1", "via": "dummy10", "timer": " 0.00" } ], "router": {} } ] Signed-off-by: Ido Schimmel <idosch@nvidia.com> Reviewed-by: Nikolay Aleksandrov <razor@blackwall.org>
| | * | | bridge: mdb: Add source VNI supportIdo Schimmel2023-03-242-3/+25
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | In a similar fashion to VXLAN FDB entries, allow user space to program and view the source VNI of VXLAN MDB entries. Specifically, add support for the 'MDBE_ATTR_SRC_VNI' and 'MDBA_MDB_EATTR_SRC_VNI' attributes in request and response messages, respectively. The source VNI is only relevant when the VXLAN device is in external mode, where multiple VNIs can be multiplexed over a single VXLAN device. Example: # bridge mdb add dev vxlan0 port vxlan0 grp 239.1.1.1 permanent dst 198.51.100.1 src_vni 2222 $ bridge -d -s mdb show dev vxlan0 port vxlan0 grp 239.1.1.1 permanent filter_mode exclude proto static dst 198.51.100.1 src_vni 2222 0.00 $ bridge -d -s -j -p mdb show [ { "mdb": [ { "index": 16, "dev": "vxlan0", "port": "vxlan0", "grp": "239.1.1.1", "state": "permanent", "filter_mode": "exclude", "protocol": "static", "flags": [ ], "dst": "198.51.100.1", "src_vni": 2222, "timer": " 0.00" } ], "router": {} } ] Signed-off-by: Ido Schimmel <idosch@nvidia.com> Reviewed-by: Nikolay Aleksandrov <razor@blackwall.org>
| | * | | bridge: mdb: Add destination VNI supportIdo Schimmel2023-03-242-3/+41
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | In a similar fashion to VXLAN FDB entries, allow user space to program and view the destination VNI of VXLAN MDB entries. Specifically, add support for the 'MDBE_ATTR_VNI' and 'MDBA_MDB_EATTR_VNI' attributes in request and response messages, respectively. This is useful when ingress replication (IR) is used and the destination VXLAN tunnel endpoint (VTEP) is not a member of the source broadcast domain (BD). In this case, the ingress VTEP should transmit the packet using the VNI of the Supplementary Broadcast Domain (SBD) in which all the VTEPs are member of [1]. Example: # bridge mdb add dev vxlan0 port vxlan0 grp 239.1.1.1 permanent dst 198.51.100.1 vni 1111 $ bridge -d -s mdb show dev vxlan0 port vxlan0 grp 239.1.1.1 permanent filter_mode exclude proto static dst 198.51.100.1 vni 1111 0.00 $ bridge -d -s -j -p mdb show [ { "mdb": [ { "index": 15, "dev": "vxlan0", "port": "vxlan0", "grp": "239.1.1.1", "state": "permanent", "filter_mode": "exclude", "protocol": "static", "flags": [ ], "dst": "198.51.100.1", "vni": 1111, "timer": " 0.00" } ], "router": {} } ] [1] https://datatracker.ietf.org/doc/html/draft-ietf-bess-evpn-irb-mcast#section-3.2.2 Signed-off-by: Ido Schimmel <idosch@nvidia.com> Reviewed-by: Nikolay Aleksandrov <razor@blackwall.org>
| | * | | bridge: mdb: Add UDP destination port supportIdo Schimmel2023-03-242-1/+49
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | In a similar fashion to VXLAN FDB entries, allow user space to program and view the UDP destination port of VXLAN MDB entries. Specifically, add support for the 'MDBE_ATTR_DST_PORT' and 'MDBA_MDB_EATTR_DST_PORT' attributes in request and response messages, respectively. Use the keyword "dst_port" instead of "port" as the latter is already used to specify the net device associated with the MDB entry. Example: # bridge mdb add dev vxlan0 port vxlan0 grp 239.1.1.1 permanent dst 198.51.100.1 dst_port 1234 $ bridge -d -s mdb show dev vxlan0 port vxlan0 grp 239.1.1.1 permanent filter_mode exclude proto static dst 198.51.100.1 dst_port 1234 0.00 $ bridge -d -s -j -p mdb show [ { "mdb": [ { "index": 15, "dev": "vxlan0", "port": "vxlan0", "grp": "239.1.1.1", "state": "permanent", "filter_mode": "exclude", "protocol": "static", "flags": [ ], "dst": "198.51.100.1", "dst_port": 1234, "timer": " 0.00" } ], "router": {} } ] Signed-off-by: Ido Schimmel <idosch@nvidia.com> Reviewed-by: Nikolay Aleksandrov <razor@blackwall.org>
| | * | | bridge: mdb: Add underlay destination IP supportIdo Schimmel2023-03-242-3/+63
| |/ / / | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Allow user space to program and view VXLAN MDB entries. Specifically, add support for the 'MDBE_ATTR_DST' and 'MDBA_MDB_EATTR_DST' attributes in request and response messages, respectively. The attributes encode the IP address of the destination VXLAN tunnel endpoint where multicast receivers for the specified multicast flow reside. Multiple destinations can be added for each flow. Example: # bridge mdb add dev vxlan0 port vxlan0 grp 239.1.1.1 permanent dst 198.51.100.1 # bridge mdb add dev vxlan0 port vxlan0 grp 239.1.1.1 permanent dst 192.0.2.1 $ bridge -d -s mdb show dev vxlan0 port vxlan0 grp 239.1.1.1 permanent filter_mode exclude proto static dst 192.0.2.1 0.00 dev vxlan0 port vxlan0 grp 239.1.1.1 permanent filter_mode exclude proto static dst 198.51.100.1 0.00 $ bridge -d -s -j -p mdb show [ { "mdb": [ { "index": 15, "dev": "vxlan0", "port": "vxlan0", "grp": "239.1.1.1", "state": "permanent", "filter_mode": "exclude", "protocol": "static", "flags": [ ], "dst": "192.0.2.1", "timer": " 0.00" },{ "index": 15, "dev": "vxlan0", "port": "vxlan0", "grp": "239.1.1.1", "state": "permanent", "filter_mode": "exclude", "protocol": "static", "flags": [ ], "dst": "198.51.100.1", "timer": " 0.00" } ], "router": {} } ] Signed-off-by: Ido Schimmel <idosch@nvidia.com> Reviewed-by: Nikolay Aleksandrov <razor@blackwall.org>
| * | | Update kernel headersDavid Ahern2023-03-236-5/+65
| | | | | | | | | | | | | | | | | | | | | | | | | | | | Update kernel headers to commit: fcb3a4653bc5 ("net/sched: act_api: use the correct TCA_ACT attributes in dump") Signed-off-by: David Ahern <dsahern@kernel.org>
* | | | v6.3.0v6.3.0Stephen Hemminger2023-04-271-1/+1
| | | |
* | | | devlink: Fix dumps where interface map is usedIdo Schimmel2023-04-271-6/+12
| |_|/ |/| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The devlink utility stores an interface map that can be used to map an interface name to a devlink port and vice versa. The map is populated by issuing a devlink port dump via 'DEVLINK_CMD_PORT_GET' command. Cited commits started to populate the map only when it is actually needed. One such case is when a dump (e.g., shared buffer dump) only returns devlink port handles. When pretty printing is required, the utility will consult the map to translate the devlink port handles to the corresponding interface names. The above is problematic as it means that the port dump response(s) will be queued to the same receive buffer as the response(s) of the dump that triggered the port dump, resulting in a failed dump [1]. Fix by using a different netlink socket for the population of the interface map. [1] $ devlink sb tc bind show kernel answers: Device or resource busy Failed to create index map //0: sb 0 tc 4 type egress pool 4 threshold 9 kernel answers: Device or resource busy [...] $ echo $? 1 Fixes: 5cddbb274eab ("devlink: load port-ifname map on demand") Fixes: 63d84b1fc98d ("devlink: load ifname map on demand from ifname_map_rev_lookup() as well") Signed-off-by: Ido Schimmel <idosch@nvidia.com> Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
* | | tc/taprio: break up help text into multiple linesVladimir Oltean2023-04-241-4/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Currently, the output of "tc qdisc add dev lo taprio help" looks absolutely horrible, it looks better in the source code. Put new lines in the output everywhere where the text switches to a new line in the source code. Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com> Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
* | | tc/mqprio: break up synopsis into multiple linesVladimir Oltean2023-04-241-17/+24
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | tc-taprio(8) has a synopsis which is much easier to follow, because it breaks up the command line arguments on multiple lines. Do this in tc-mqprio(8) too. Also, the highlighting (bold) of the keywords is all wrong. Take the opportunity to fix that. Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com> Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
* | | tc/mqprio: use words in man page to express min_rate/max_rate dependency on ↵Vladimir Oltean2023-04-241-6/+13
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | bw_rlimit It is confusing and easy to get lost in the soup of brackets when trying to explain that min_rate and max_rate are only accepted as optional arguments when "shaper" takes the value "bw_rlimit". Before (synopsis): [ shaper dcb| [ bw_rlimit min_rate min_rate1 min_rate2 ... max_rate max_rate1 max_rate2 ... ]] After (synopsis): [ shaper dcb|bw_rlimit ] [ min_rate min_rate1 min_rate2 ... ] [ max_rate max_rate1 max_rate2 ... ] Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com> Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>