]>
Commit | Line | Data |
---|---|---|
aba5acdf SH |
1 | /* |
2 | * iprule.c "ip rule". | |
3 | * | |
4 | * This program is free software; you can redistribute it and/or | |
5 | * modify it under the terms of the GNU General Public License | |
6 | * as published by the Free Software Foundation; either version | |
7 | * 2 of the License, or (at your option) any later version. | |
8 | * | |
9 | * Authors: Alexey Kuznetsov, <kuznet@ms2.inr.ac.ru> | |
10 | * | |
aba5acdf SH |
11 | */ |
12 | ||
13 | #include <stdio.h> | |
14 | #include <stdlib.h> | |
15 | #include <unistd.h> | |
aba5acdf SH |
16 | #include <fcntl.h> |
17 | #include <sys/socket.h> | |
18 | #include <netinet/in.h> | |
19 | #include <netinet/ip.h> | |
20 | #include <arpa/inet.h> | |
21 | #include <string.h> | |
ca89c521 | 22 | #include <linux/if.h> |
3123a0cc | 23 | #include <linux/fib_rules.h> |
2f4e171f | 24 | #include <errno.h> |
aba5acdf SH |
25 | |
26 | #include "rt_names.h" | |
27 | #include "utils.h" | |
34e95647 | 28 | #include "ip_common.h" |
0dd4ccc5 | 29 | #include "json_print.h" |
aba5acdf | 30 | |
cb294a1d HL |
31 | enum list_action { |
32 | IPRULE_LIST, | |
33 | IPRULE_FLUSH, | |
34 | IPRULE_SAVE, | |
35 | }; | |
36 | ||
351efcde SH |
37 | extern struct rtnl_handle rth; |
38 | ||
aba5acdf SH |
39 | static void usage(void) __attribute__((noreturn)); |
40 | ||
41 | static void usage(void) | |
42 | { | |
e147161b SH |
43 | fprintf(stderr, |
44 | "Usage: ip rule { add | del } SELECTOR ACTION\n" | |
45 | " ip rule { flush | save | restore }\n" | |
46 | " ip rule [ list [ SELECTOR ]]\n" | |
47 | "SELECTOR := [ not ] [ from PREFIX ] [ to PREFIX ] [ tos TOS ] [ fwmark FWMARK[/MASK] ]\n" | |
48 | " [ iif STRING ] [ oif STRING ] [ pref NUMBER ] [ l3mdev ]\n" | |
82252cdc | 49 | " [ uidrange NUMBER-NUMBER ]\n" |
f686f764 RP |
50 | " [ ipproto PROTOCOL ]\n" |
51 | " [ sport [ NUMBER | NUMBER-NUMBER ]\n" | |
52 | " [ dport [ NUMBER | NUMBER-NUMBER ] ]\n" | |
e147161b | 53 | "ACTION := [ table TABLE_ID ]\n" |
7c083da7 | 54 | " [ protocol PROTO ]\n" |
e147161b SH |
55 | " [ nat ADDRESS ]\n" |
56 | " [ realms [SRCREALM/]DSTREALM ]\n" | |
57 | " [ goto NUMBER ]\n" | |
58 | " SUPPRESSOR\n" | |
59 | "SUPPRESSOR := [ suppress_prefixlength NUMBER ]\n" | |
60 | " [ suppress_ifgroup DEVGROUP ]\n" | |
61 | "TABLE_ID := [ local | main | default | NUMBER ]\n"); | |
aba5acdf SH |
62 | exit(-1); |
63 | } | |
64 | ||
ca89c521 HL |
65 | static struct |
66 | { | |
67 | int not; | |
68 | int l3mdev; | |
82252cdc | 69 | int iifmask, oifmask, uidrange; |
ca89c521 HL |
70 | unsigned int tb; |
71 | unsigned int tos, tosmask; | |
72 | unsigned int pref, prefmask; | |
73 | unsigned int fwmark, fwmask; | |
74 | char iif[IFNAMSIZ]; | |
75 | char oif[IFNAMSIZ]; | |
82252cdc | 76 | struct fib_rule_uid_range range; |
ca89c521 HL |
77 | inet_prefix src; |
78 | inet_prefix dst; | |
7c083da7 DS |
79 | int protocol; |
80 | int protocolmask; | |
ca89c521 HL |
81 | } filter; |
82 | ||
5baaf07c DS |
83 | static inline int frh_get_table(struct fib_rule_hdr *frh, struct rtattr **tb) |
84 | { | |
85 | __u32 table = frh->table; | |
86 | if (tb[RTA_TABLE]) | |
87 | table = rta_getattr_u32(tb[RTA_TABLE]); | |
88 | return table; | |
89 | } | |
90 | ||
ca89c521 HL |
91 | static bool filter_nlmsg(struct nlmsghdr *n, struct rtattr **tb, int host_len) |
92 | { | |
5baaf07c | 93 | struct fib_rule_hdr *frh = NLMSG_DATA(n); |
ca89c521 HL |
94 | __u32 table; |
95 | ||
5baaf07c | 96 | if (preferred_family != AF_UNSPEC && frh->family != preferred_family) |
ca89c521 HL |
97 | return false; |
98 | ||
99 | if (filter.prefmask && | |
100 | filter.pref ^ (tb[FRA_PRIORITY] ? rta_getattr_u32(tb[FRA_PRIORITY]) : 0)) | |
101 | return false; | |
5baaf07c | 102 | if (filter.not && !(frh->flags & FIB_RULE_INVERT)) |
ca89c521 HL |
103 | return false; |
104 | ||
105 | if (filter.src.family) { | |
746035b4 SP |
106 | inet_prefix *f_src = &filter.src; |
107 | ||
5baaf07c DS |
108 | if (f_src->family != frh->family || |
109 | f_src->bitlen > frh->src_len) | |
746035b4 SP |
110 | return false; |
111 | ||
112 | if (inet_addr_match_rta(f_src, tb[FRA_SRC])) | |
ca89c521 HL |
113 | return false; |
114 | } | |
115 | ||
116 | if (filter.dst.family) { | |
746035b4 SP |
117 | inet_prefix *f_dst = &filter.dst; |
118 | ||
5baaf07c DS |
119 | if (f_dst->family != frh->family || |
120 | f_dst->bitlen > frh->dst_len) | |
746035b4 SP |
121 | return false; |
122 | ||
123 | if (inet_addr_match_rta(f_dst, tb[FRA_DST])) | |
ca89c521 HL |
124 | return false; |
125 | } | |
126 | ||
5baaf07c | 127 | if (filter.tosmask && filter.tos ^ frh->tos) |
ca89c521 HL |
128 | return false; |
129 | ||
130 | if (filter.fwmark) { | |
131 | __u32 mark = 0; | |
e147161b | 132 | |
ca89c521 HL |
133 | if (tb[FRA_FWMARK]) |
134 | mark = rta_getattr_u32(tb[FRA_FWMARK]); | |
135 | if (filter.fwmark ^ mark) | |
136 | return false; | |
137 | } | |
138 | if (filter.fwmask) { | |
139 | __u32 mask = 0; | |
e147161b | 140 | |
ca89c521 HL |
141 | if (tb[FRA_FWMASK]) |
142 | mask = rta_getattr_u32(tb[FRA_FWMASK]); | |
143 | if (filter.fwmask ^ mask) | |
144 | return false; | |
145 | } | |
146 | ||
147 | if (filter.iifmask) { | |
148 | if (tb[FRA_IFNAME]) { | |
149 | if (strcmp(filter.iif, rta_getattr_str(tb[FRA_IFNAME])) != 0) | |
150 | return false; | |
151 | } else { | |
152 | return false; | |
153 | } | |
154 | } | |
155 | ||
156 | if (filter.oifmask) { | |
157 | if (tb[FRA_OIFNAME]) { | |
158 | if (strcmp(filter.oif, rta_getattr_str(tb[FRA_OIFNAME])) != 0) | |
159 | return false; | |
160 | } else { | |
161 | return false; | |
162 | } | |
163 | } | |
164 | ||
165 | if (filter.l3mdev && !(tb[FRA_L3MDEV] && rta_getattr_u8(tb[FRA_L3MDEV]))) | |
166 | return false; | |
167 | ||
82252cdc LC |
168 | if (filter.uidrange) { |
169 | struct fib_rule_uid_range *r = RTA_DATA(tb[FRA_UID_RANGE]); | |
170 | ||
171 | if (!tb[FRA_UID_RANGE] || | |
172 | r->start != filter.range.start || | |
173 | r->end != filter.range.end) | |
174 | return false; | |
175 | } | |
176 | ||
5baaf07c | 177 | table = frh_get_table(frh, tb); |
ca89c521 HL |
178 | if (filter.tb > 0 && filter.tb ^ table) |
179 | return false; | |
180 | ||
181 | return true; | |
182 | } | |
183 | ||
cd554f2c | 184 | int print_rule(struct nlmsghdr *n, void *arg) |
aba5acdf | 185 | { |
0dd4ccc5 | 186 | FILE *fp = arg; |
5baaf07c | 187 | struct fib_rule_hdr *frh = NLMSG_DATA(n); |
aba5acdf SH |
188 | int len = n->nlmsg_len; |
189 | int host_len = -1; | |
0dd4ccc5 | 190 | __u32 table, prio = 0; |
56f5daac | 191 | struct rtattr *tb[FRA_MAX+1]; |
aba5acdf SH |
192 | SPRINT_BUF(b1); |
193 | ||
98bde989 | 194 | if (n->nlmsg_type != RTM_NEWRULE && n->nlmsg_type != RTM_DELRULE) |
aba5acdf SH |
195 | return 0; |
196 | ||
5baaf07c | 197 | len -= NLMSG_LENGTH(sizeof(*frh)); |
aba5acdf SH |
198 | if (len < 0) |
199 | return -1; | |
200 | ||
5baaf07c | 201 | parse_rtattr(tb, FRA_MAX, RTM_RTA(frh), len); |
aba5acdf | 202 | |
5baaf07c | 203 | host_len = af_bit_len(frh->family); |
aba5acdf | 204 | |
e147161b | 205 | if (!filter_nlmsg(n, tb, host_len)) |
ca89c521 HL |
206 | return 0; |
207 | ||
0dd4ccc5 | 208 | open_json_object(NULL); |
98bde989 | 209 | if (n->nlmsg_type == RTM_DELRULE) |
0dd4ccc5 | 210 | print_bool(PRINT_ANY, "deleted", "Deleted ", true); |
98bde989 | 211 | |
ad1a12db | 212 | if (tb[FRA_PRIORITY]) |
0dd4ccc5 SH |
213 | prio = rta_getattr_u32(tb[FRA_PRIORITY]); |
214 | ||
215 | print_uint(PRINT_ANY, "priority", "%u:\t", prio); | |
aba5acdf | 216 | |
5baaf07c | 217 | if (frh->flags & FIB_RULE_INVERT) |
0dd4ccc5 | 218 | print_null(PRINT_ANY, "not", "not ", NULL); |
3123a0cc | 219 | |
ad1a12db | 220 | if (tb[FRA_SRC]) { |
0dd4ccc5 SH |
221 | const char *src = rt_addr_n2a_rta(frh->family, tb[FRA_SRC]); |
222 | ||
223 | print_string(PRINT_FP, NULL, "from ", NULL); | |
224 | print_color_string(PRINT_ANY, ifa_family_color(frh->family), | |
225 | "src", "%s", src); | |
226 | if (frh->src_len != host_len) | |
227 | print_uint(PRINT_ANY, "srclen", "/%u ", frh->src_len); | |
228 | else | |
229 | print_string(PRINT_FP, NULL, " ", NULL); | |
5baaf07c | 230 | } else if (frh->src_len) { |
0dd4ccc5 SH |
231 | print_string(PRINT_ANY, "src", "from %s", "0"); |
232 | print_uint(PRINT_ANY, "srclen", "/%u ", frh->src_len); | |
aba5acdf | 233 | } else { |
0dd4ccc5 | 234 | print_string(PRINT_ANY, "src", "from %s ", "all"); |
aba5acdf SH |
235 | } |
236 | ||
ad1a12db | 237 | if (tb[FRA_DST]) { |
0dd4ccc5 SH |
238 | const char *dst = rt_addr_n2a_rta(frh->family, tb[FRA_DST]); |
239 | ||
240 | print_string(PRINT_FP, NULL, "to ", NULL); | |
241 | print_color_string(PRINT_ANY, ifa_family_color(frh->family), | |
1a75322c | 242 | "dst", "%s", dst); |
0dd4ccc5 SH |
243 | if (frh->dst_len != host_len) |
244 | print_uint(PRINT_ANY, "dstlen", "/%u ", frh->dst_len); | |
245 | else | |
246 | print_string(PRINT_FP, NULL, " ", NULL); | |
5baaf07c | 247 | } else if (frh->dst_len) { |
0dd4ccc5 SH |
248 | print_string(PRINT_ANY, "dst", "to %s", "0"); |
249 | print_uint(PRINT_ANY, "dstlen", "/%u ", frh->dst_len); | |
aba5acdf SH |
250 | } |
251 | ||
5baaf07c | 252 | if (frh->tos) { |
0dd4ccc5 SH |
253 | print_string(PRINT_ANY, "tos", |
254 | "tos %s ", | |
255 | rtnl_dsfield_n2a(frh->tos, b1, sizeof(b1))); | |
aba5acdf | 256 | } |
ad1a12db | 257 | |
4806867a | 258 | if (tb[FRA_FWMARK] || tb[FRA_FWMASK]) { |
be7f286e PM |
259 | __u32 mark = 0, mask = 0; |
260 | ||
ad1a12db | 261 | if (tb[FRA_FWMARK]) |
ff24746c | 262 | mark = rta_getattr_u32(tb[FRA_FWMARK]); |
be7f286e | 263 | |
ad1a12db | 264 | if (tb[FRA_FWMASK] && |
0dd4ccc5 SH |
265 | (mask = rta_getattr_u32(tb[FRA_FWMASK])) != 0xFFFFFFFF) { |
266 | print_0xhex(PRINT_ANY, "fwmark", "fwmark 0x%x", mark); | |
267 | print_0xhex(PRINT_ANY, "fwmask", "/0x%x ", mask); | |
268 | } else { | |
269 | print_0xhex(PRINT_ANY, "fwmark", "fwmark 0x%x ", mark); | |
270 | } | |
aba5acdf SH |
271 | } |
272 | ||
ad1a12db | 273 | if (tb[FRA_IFNAME]) { |
0dd4ccc5 SH |
274 | if (!is_json_context()) |
275 | fprintf(fp, "iif "); | |
276 | print_color_string(PRINT_ANY, COLOR_IFNAME, | |
277 | "iif", "%s ", | |
278 | rta_getattr_str(tb[FRA_IFNAME])); | |
279 | ||
5baaf07c | 280 | if (frh->flags & FIB_RULE_IIF_DETACHED) |
0dd4ccc5 SH |
281 | print_null(PRINT_ANY, "iif_detached", "[detached] ", |
282 | NULL); | |
85eae222 PM |
283 | } |
284 | ||
285 | if (tb[FRA_OIFNAME]) { | |
0dd4ccc5 SH |
286 | if (!is_json_context()) |
287 | fprintf(fp, "oif "); | |
288 | ||
289 | print_color_string(PRINT_ANY, COLOR_IFNAME, "oif", "%s ", | |
290 | rta_getattr_str(tb[FRA_OIFNAME])); | |
291 | ||
5baaf07c | 292 | if (frh->flags & FIB_RULE_OIF_DETACHED) |
0dd4ccc5 SH |
293 | print_null(PRINT_ANY, "oif_detached", "[detached] ", |
294 | NULL); | |
aba5acdf SH |
295 | } |
296 | ||
8c92e122 | 297 | if (tb[FRA_L3MDEV]) { |
0dd4ccc5 SH |
298 | __u8 mdev = rta_getattr_u8(tb[FRA_L3MDEV]); |
299 | ||
300 | if (mdev) | |
301 | print_null(PRINT_ANY, "l3mdev", | |
302 | "lookup [l3mdev-table] ", NULL); | |
8c92e122 DA |
303 | } |
304 | ||
82252cdc LC |
305 | if (tb[FRA_UID_RANGE]) { |
306 | struct fib_rule_uid_range *r = RTA_DATA(tb[FRA_UID_RANGE]); | |
307 | ||
0dd4ccc5 SH |
308 | print_uint(PRINT_ANY, "uid_start", "uidrange %u", r->start); |
309 | print_uint(PRINT_ANY, "uid_end", "-%u ", r->end); | |
82252cdc LC |
310 | } |
311 | ||
f686f764 RP |
312 | if (tb[FRA_IP_PROTO]) { |
313 | SPRINT_BUF(pbuf); | |
314 | print_string(PRINT_ANY, "ipproto", "ipproto %s ", | |
315 | inet_proto_n2a(rta_getattr_u8(tb[FRA_IP_PROTO]), | |
316 | pbuf, sizeof(pbuf))); | |
317 | } | |
318 | ||
319 | if (tb[FRA_SPORT_RANGE]) { | |
320 | struct fib_rule_port_range *r = RTA_DATA(tb[FRA_SPORT_RANGE]); | |
321 | ||
322 | if (r->start == r->end) { | |
323 | print_uint(PRINT_ANY, "sport", "sport %u ", r->start); | |
324 | } else { | |
325 | print_uint(PRINT_ANY, "sport_start", "sport %u", | |
326 | r->start); | |
327 | print_uint(PRINT_ANY, "sport_end", "-%u ", r->end); | |
328 | } | |
329 | } | |
330 | ||
331 | if (tb[FRA_DPORT_RANGE]) { | |
332 | struct fib_rule_port_range *r = RTA_DATA(tb[FRA_DPORT_RANGE]); | |
333 | ||
334 | if (r->start == r->end) { | |
335 | print_uint(PRINT_ANY, "dport", "dport %u ", r->start); | |
336 | } else { | |
337 | print_uint(PRINT_ANY, "dport_start", "dport %u", | |
338 | r->start); | |
339 | print_uint(PRINT_ANY, "dport_end", "-%u ", r->end); | |
340 | } | |
341 | } | |
342 | ||
5baaf07c | 343 | table = frh_get_table(frh, tb); |
b1d0525f | 344 | if (table) { |
0dd4ccc5 SH |
345 | print_string(PRINT_ANY, "table", |
346 | "lookup %s ", | |
347 | rtnl_rttable_n2a(table, b1, sizeof(b1))); | |
aba5acdf | 348 | |
b1d0525f ST |
349 | if (tb[FRA_SUPPRESS_PREFIXLEN]) { |
350 | int pl = rta_getattr_u32(tb[FRA_SUPPRESS_PREFIXLEN]); | |
56f5daac | 351 | |
d831cc7c | 352 | if (pl != -1) |
0dd4ccc5 SH |
353 | print_int(PRINT_ANY, "suppress_prefixlen", |
354 | "suppress_prefixlength %d ", pl); | |
b1d0525f | 355 | } |
0dd4ccc5 | 356 | |
b1d0525f ST |
357 | if (tb[FRA_SUPPRESS_IFGROUP]) { |
358 | int group = rta_getattr_u32(tb[FRA_SUPPRESS_IFGROUP]); | |
56f5daac | 359 | |
b1d0525f | 360 | if (group != -1) { |
0dd4ccc5 SH |
361 | const char *grname |
362 | = rtnl_group_n2a(group, b1, sizeof(b1)); | |
363 | ||
364 | print_string(PRINT_ANY, "suppress_ifgroup", | |
365 | "suppress_ifgroup %s ", grname); | |
b1d0525f ST |
366 | } |
367 | } | |
368 | } | |
369 | ||
ad1a12db | 370 | if (tb[FRA_FLOW]) { |
ff24746c | 371 | __u32 to = rta_getattr_u32(tb[FRA_FLOW]); |
aba5acdf | 372 | __u32 from = to>>16; |
56f5daac | 373 | |
aba5acdf | 374 | to &= 0xFFFF; |
0dd4ccc5 SH |
375 | if (from) |
376 | print_string(PRINT_ANY, | |
377 | "flow_from", "realms %s/", | |
378 | rtnl_rtrealm_n2a(from, b1, sizeof(b1))); | |
379 | ||
380 | print_string(PRINT_ANY, "flow_to", "%s ", | |
381 | rtnl_rtrealm_n2a(to, b1, sizeof(b1))); | |
aba5acdf SH |
382 | } |
383 | ||
5baaf07c | 384 | if (frh->action == RTN_NAT) { |
aba5acdf | 385 | if (tb[RTA_GATEWAY]) { |
0dd4ccc5 SH |
386 | const char *gateway; |
387 | ||
388 | gateway = format_host_rta(frh->family, tb[RTA_GATEWAY]); | |
389 | ||
390 | print_string(PRINT_ANY, "nat_gateway", | |
391 | "map-to %s ", gateway); | |
392 | } else { | |
393 | print_null(PRINT_ANY, "masquerade", "masquerade", NULL); | |
394 | } | |
5baaf07c | 395 | } else if (frh->action == FR_ACT_GOTO) { |
6b469cae | 396 | if (tb[FRA_GOTO]) |
0dd4ccc5 SH |
397 | print_uint(PRINT_ANY, "goto", "goto %u", |
398 | rta_getattr_u32(tb[FRA_GOTO])); | |
6b469cae | 399 | else |
0dd4ccc5 SH |
400 | print_string(PRINT_ANY, "goto", "goto %s", "none"); |
401 | ||
5baaf07c | 402 | if (frh->flags & FIB_RULE_UNRESOLVED) |
0dd4ccc5 SH |
403 | print_null(PRINT_ANY, "unresolved", "unresolved", NULL); |
404 | } else if (frh->action == FR_ACT_NOP) { | |
405 | print_null(PRINT_ANY, "nop", "nop", NULL); | |
406 | } else if (frh->action != FR_ACT_TO_TBL) { | |
407 | print_string(PRINT_ANY, "to_tbl", "%s", | |
408 | rtnl_rtntype_n2a(frh->action, b1, sizeof(b1))); | |
409 | } | |
aba5acdf | 410 | |
7c083da7 DS |
411 | if (tb[FRA_PROTOCOL]) { |
412 | __u8 protocol = rta_getattr_u8(tb[FRA_PROTOCOL]); | |
413 | ||
0dd4ccc5 SH |
414 | if ((protocol && protocol != RTPROT_KERNEL) || show_details > 0) { |
415 | print_string(PRINT_ANY, "protocol", " proto %s ", | |
416 | rtnl_rtprot_n2a(protocol, b1, sizeof(b1))); | |
7c083da7 DS |
417 | } |
418 | } | |
0dd4ccc5 SH |
419 | print_string(PRINT_FP, NULL, "\n", ""); |
420 | close_json_object(); | |
aba5acdf SH |
421 | fflush(fp); |
422 | return 0; | |
423 | } | |
424 | ||
2f4e171f KT |
425 | static __u32 rule_dump_magic = 0x71706986; |
426 | ||
427 | static int save_rule_prep(void) | |
428 | { | |
429 | int ret; | |
430 | ||
431 | if (isatty(STDOUT_FILENO)) { | |
432 | fprintf(stderr, "Not sending a binary stream to stdout\n"); | |
433 | return -1; | |
434 | } | |
435 | ||
436 | ret = write(STDOUT_FILENO, &rule_dump_magic, sizeof(rule_dump_magic)); | |
437 | if (ret != sizeof(rule_dump_magic)) { | |
438 | fprintf(stderr, "Can't write magic to dump file\n"); | |
439 | return -1; | |
440 | } | |
441 | ||
442 | return 0; | |
443 | } | |
444 | ||
cd554f2c | 445 | static int save_rule(struct nlmsghdr *n, void *arg) |
aba5acdf | 446 | { |
2f4e171f KT |
447 | int ret; |
448 | ||
449 | ret = write(STDOUT_FILENO, n, n->nlmsg_len); | |
450 | if ((ret > 0) && (ret != n->nlmsg_len)) { | |
451 | fprintf(stderr, "Short write while saving nlmsg\n"); | |
452 | ret = -EIO; | |
453 | } | |
454 | ||
455 | return ret == n->nlmsg_len ? 0 : ret; | |
456 | } | |
457 | ||
cd554f2c | 458 | static int flush_rule(struct nlmsghdr *n, void *arg) |
cb294a1d HL |
459 | { |
460 | struct rtnl_handle rth2; | |
5baaf07c | 461 | struct fib_rule_hdr *frh = NLMSG_DATA(n); |
cb294a1d HL |
462 | int len = n->nlmsg_len; |
463 | struct rtattr *tb[FRA_MAX+1]; | |
464 | ||
5baaf07c | 465 | len -= NLMSG_LENGTH(sizeof(*frh)); |
cb294a1d HL |
466 | if (len < 0) |
467 | return -1; | |
468 | ||
5baaf07c | 469 | parse_rtattr(tb, FRA_MAX, RTM_RTA(frh), len); |
cb294a1d | 470 | |
7c083da7 DS |
471 | if (tb[FRA_PROTOCOL]) { |
472 | __u8 protocol = rta_getattr_u8(tb[FRA_PROTOCOL]); | |
473 | ||
474 | if ((filter.protocol ^ protocol) & filter.protocolmask) | |
475 | return 0; | |
476 | } | |
477 | ||
cb294a1d HL |
478 | if (tb[FRA_PRIORITY]) { |
479 | n->nlmsg_type = RTM_DELRULE; | |
480 | n->nlmsg_flags = NLM_F_REQUEST; | |
481 | ||
482 | if (rtnl_open(&rth2, 0) < 0) | |
483 | return -1; | |
484 | ||
86bf43c7 | 485 | if (rtnl_talk(&rth2, n, NULL) < 0) |
cb294a1d HL |
486 | return -2; |
487 | ||
488 | rtnl_close(&rth2); | |
489 | } | |
490 | ||
491 | return 0; | |
492 | } | |
493 | ||
494 | static int iprule_list_flush_or_save(int argc, char **argv, int action) | |
2f4e171f | 495 | { |
cb294a1d | 496 | rtnl_filter_t filter_fn; |
aba5acdf SH |
497 | int af = preferred_family; |
498 | ||
499 | if (af == AF_UNSPEC) | |
500 | af = AF_INET; | |
501 | ||
7c083da7 DS |
502 | if (action == IPRULE_SAVE && argc > 0) { |
503 | fprintf(stderr, "\"ip rule save\" does not take any arguments.\n"); | |
aba5acdf SH |
504 | return -1; |
505 | } | |
506 | ||
cb294a1d HL |
507 | switch (action) { |
508 | case IPRULE_SAVE: | |
2f4e171f KT |
509 | if (save_rule_prep()) |
510 | return -1; | |
cb294a1d HL |
511 | filter_fn = save_rule; |
512 | break; | |
513 | case IPRULE_FLUSH: | |
514 | filter_fn = flush_rule; | |
515 | break; | |
516 | default: | |
517 | filter_fn = print_rule; | |
2f4e171f KT |
518 | } |
519 | ||
ca89c521 HL |
520 | memset(&filter, 0, sizeof(filter)); |
521 | ||
522 | while (argc > 0) { | |
523 | if (matches(*argv, "preference") == 0 || | |
524 | matches(*argv, "order") == 0 || | |
525 | matches(*argv, "priority") == 0) { | |
526 | __u32 pref; | |
e147161b | 527 | |
ca89c521 HL |
528 | NEXT_ARG(); |
529 | if (get_u32(&pref, *argv, 0)) | |
530 | invarg("preference value is invalid\n", *argv); | |
531 | filter.pref = pref; | |
532 | filter.prefmask = 1; | |
533 | } else if (strcmp(*argv, "not") == 0) { | |
534 | filter.not = 1; | |
535 | } else if (strcmp(*argv, "tos") == 0) { | |
536 | __u32 tos; | |
e147161b | 537 | |
ca89c521 HL |
538 | NEXT_ARG(); |
539 | if (rtnl_dsfield_a2n(&tos, *argv)) | |
540 | invarg("TOS value is invalid\n", *argv); | |
541 | filter.tos = tos; | |
542 | filter.tosmask = 1; | |
543 | } else if (strcmp(*argv, "fwmark") == 0) { | |
544 | char *slash; | |
545 | __u32 fwmark, fwmask; | |
e147161b | 546 | |
ca89c521 HL |
547 | NEXT_ARG(); |
548 | slash = strchr(*argv, '/'); | |
549 | if (slash != NULL) | |
550 | *slash = '\0'; | |
551 | if (get_u32(&fwmark, *argv, 0)) | |
552 | invarg("fwmark value is invalid\n", *argv); | |
553 | filter.fwmark = fwmark; | |
554 | if (slash) { | |
555 | if (get_u32(&fwmask, slash+1, 0)) | |
556 | invarg("fwmask value is invalid\n", | |
557 | slash+1); | |
558 | filter.fwmask = fwmask; | |
559 | } | |
560 | } else if (strcmp(*argv, "dev") == 0 || | |
561 | strcmp(*argv, "iif") == 0) { | |
562 | NEXT_ARG(); | |
625df645 PS |
563 | if (get_ifname(filter.iif, *argv)) |
564 | invarg("\"iif\"/\"dev\" not a valid ifname", *argv); | |
ca89c521 HL |
565 | filter.iifmask = 1; |
566 | } else if (strcmp(*argv, "oif") == 0) { | |
567 | NEXT_ARG(); | |
625df645 PS |
568 | if (get_ifname(filter.oif, *argv)) |
569 | invarg("\"oif\" not a valid ifname", *argv); | |
ca89c521 HL |
570 | filter.oifmask = 1; |
571 | } else if (strcmp(*argv, "l3mdev") == 0) { | |
572 | filter.l3mdev = 1; | |
82252cdc LC |
573 | } else if (strcmp(*argv, "uidrange") == 0) { |
574 | NEXT_ARG(); | |
575 | filter.uidrange = 1; | |
576 | if (sscanf(*argv, "%u-%u", | |
577 | &filter.range.start, | |
578 | &filter.range.end) != 2) | |
579 | invarg("invalid UID range\n", *argv); | |
580 | ||
ca89c521 | 581 | } else if (matches(*argv, "lookup") == 0 || |
e147161b | 582 | matches(*argv, "table") == 0) { |
ca89c521 | 583 | __u32 tid; |
e147161b | 584 | |
ca89c521 HL |
585 | NEXT_ARG(); |
586 | if (rtnl_rttable_a2n(&tid, *argv)) | |
587 | invarg("table id value is invalid\n", *argv); | |
588 | filter.tb = tid; | |
589 | } else if (matches(*argv, "from") == 0 || | |
590 | matches(*argv, "src") == 0) { | |
591 | NEXT_ARG(); | |
746035b4 SP |
592 | if (get_prefix(&filter.src, *argv, af)) |
593 | invarg("from value is invalid\n", *argv); | |
7c083da7 DS |
594 | } else if (matches(*argv, "protocol") == 0) { |
595 | __u32 prot; | |
596 | NEXT_ARG(); | |
597 | filter.protocolmask = -1; | |
598 | if (rtnl_rtprot_a2n(&prot, *argv)) { | |
599 | if (strcmp(*argv, "all") != 0) | |
600 | invarg("invalid \"protocol\"\n", *argv); | |
601 | prot = 0; | |
602 | filter.protocolmask = 0; | |
603 | } | |
604 | filter.protocol = prot; | |
605 | } else{ | |
ca89c521 HL |
606 | if (matches(*argv, "dst") == 0 || |
607 | matches(*argv, "to") == 0) { | |
608 | NEXT_ARG(); | |
609 | } | |
746035b4 SP |
610 | if (get_prefix(&filter.dst, *argv, af)) |
611 | invarg("to value is invalid\n", *argv); | |
ca89c521 HL |
612 | } |
613 | argc--; argv++; | |
614 | } | |
615 | ||
b05d9a3d | 616 | if (rtnl_ruledump_req(&rth, af) < 0) { |
aba5acdf SH |
617 | perror("Cannot send dump request"); |
618 | return 1; | |
619 | } | |
620 | ||
0dd4ccc5 | 621 | new_json_obj(json); |
cb294a1d | 622 | if (rtnl_dump_filter(&rth, filter_fn, stdout) < 0) { |
aba5acdf SH |
623 | fprintf(stderr, "Dump terminated\n"); |
624 | return 1; | |
625 | } | |
0dd4ccc5 | 626 | delete_json_obj(); |
aba5acdf SH |
627 | |
628 | return 0; | |
629 | } | |
630 | ||
2f4e171f KT |
631 | static int rule_dump_check_magic(void) |
632 | { | |
633 | int ret; | |
634 | __u32 magic = 0; | |
635 | ||
636 | if (isatty(STDIN_FILENO)) { | |
637 | fprintf(stderr, "Can't restore rule dump from a terminal\n"); | |
638 | return -1; | |
639 | } | |
640 | ||
641 | ret = fread(&magic, sizeof(magic), 1, stdin); | |
642 | if (magic != rule_dump_magic) { | |
d831cc7c SH |
643 | fprintf(stderr, "Magic mismatch (%d elems, %x magic)\n", |
644 | ret, magic); | |
2f4e171f KT |
645 | return -1; |
646 | } | |
647 | ||
648 | return 0; | |
649 | } | |
650 | ||
cd554f2c | 651 | static int restore_handler(struct rtnl_ctrl_data *ctrl, |
2f4e171f KT |
652 | struct nlmsghdr *n, void *arg) |
653 | { | |
654 | int ret; | |
655 | ||
656 | n->nlmsg_flags |= NLM_F_REQUEST | NLM_F_CREATE | NLM_F_ACK; | |
657 | ||
658 | ll_init_map(&rth); | |
659 | ||
86bf43c7 | 660 | ret = rtnl_talk(&rth, n, NULL); |
2f4e171f KT |
661 | if ((ret < 0) && (errno == EEXIST)) |
662 | ret = 0; | |
663 | ||
664 | return ret; | |
665 | } | |
666 | ||
667 | ||
668 | static int iprule_restore(void) | |
669 | { | |
670 | if (rule_dump_check_magic()) | |
671 | exit(-1); | |
672 | ||
673 | exit(rtnl_from_file(stdin, &restore_handler, NULL)); | |
674 | } | |
aba5acdf | 675 | |
50772dc5 | 676 | static int iprule_modify(int cmd, int argc, char **argv) |
aba5acdf | 677 | { |
8c92e122 | 678 | int l3mdev_rule = 0; |
aba5acdf | 679 | int table_ok = 0; |
8c92e122 | 680 | __u32 tid = 0; |
aba5acdf | 681 | struct { |
4806867a | 682 | struct nlmsghdr n; |
5baaf07c | 683 | struct fib_rule_hdr frh; |
56f5daac | 684 | char buf[1024]; |
d17b136f PS |
685 | } req = { |
686 | .n.nlmsg_type = cmd, | |
5baaf07c | 687 | .n.nlmsg_len = NLMSG_LENGTH(sizeof(struct fib_rule_hdr)), |
d17b136f | 688 | .n.nlmsg_flags = NLM_F_REQUEST, |
5baaf07c DS |
689 | .frh.family = preferred_family, |
690 | .frh.action = FR_ACT_UNSPEC, | |
d17b136f | 691 | }; |
aba5acdf SH |
692 | |
693 | if (cmd == RTM_NEWRULE) { | |
694 | req.n.nlmsg_flags |= NLM_F_CREATE|NLM_F_EXCL; | |
5baaf07c | 695 | req.frh.action = FR_ACT_TO_TBL; |
aba5acdf SH |
696 | } |
697 | ||
67a990b8 AJM |
698 | if (cmd == RTM_DELRULE && argc == 0) { |
699 | fprintf(stderr, "\"ip rule del\" requires arguments.\n"); | |
700 | return -1; | |
701 | } | |
702 | ||
aba5acdf | 703 | while (argc > 0) { |
3123a0cc | 704 | if (strcmp(*argv, "not") == 0) { |
5baaf07c | 705 | req.frh.flags |= FIB_RULE_INVERT; |
3123a0cc | 706 | } else if (strcmp(*argv, "from") == 0) { |
aba5acdf | 707 | inet_prefix dst; |
56f5daac | 708 | |
aba5acdf | 709 | NEXT_ARG(); |
5baaf07c DS |
710 | get_prefix(&dst, *argv, req.frh.family); |
711 | req.frh.src_len = dst.bitlen; | |
d831cc7c SH |
712 | addattr_l(&req.n, sizeof(req), FRA_SRC, |
713 | &dst.data, dst.bytelen); | |
aba5acdf SH |
714 | } else if (strcmp(*argv, "to") == 0) { |
715 | inet_prefix dst; | |
56f5daac | 716 | |
aba5acdf | 717 | NEXT_ARG(); |
5baaf07c DS |
718 | get_prefix(&dst, *argv, req.frh.family); |
719 | req.frh.dst_len = dst.bitlen; | |
d831cc7c SH |
720 | addattr_l(&req.n, sizeof(req), FRA_DST, |
721 | &dst.data, dst.bytelen); | |
aba5acdf SH |
722 | } else if (matches(*argv, "preference") == 0 || |
723 | matches(*argv, "order") == 0 || | |
724 | matches(*argv, "priority") == 0) { | |
725 | __u32 pref; | |
56f5daac | 726 | |
aba5acdf SH |
727 | NEXT_ARG(); |
728 | if (get_u32(&pref, *argv, 0)) | |
729 | invarg("preference value is invalid\n", *argv); | |
ad1a12db | 730 | addattr32(&req.n, sizeof(req), FRA_PRIORITY, pref); |
dec01609 AH |
731 | } else if (strcmp(*argv, "tos") == 0 || |
732 | matches(*argv, "dsfield") == 0) { | |
aba5acdf | 733 | __u32 tos; |
56f5daac | 734 | |
aba5acdf SH |
735 | NEXT_ARG(); |
736 | if (rtnl_dsfield_a2n(&tos, *argv)) | |
737 | invarg("TOS value is invalid\n", *argv); | |
5baaf07c | 738 | req.frh.tos = tos; |
aba5acdf | 739 | } else if (strcmp(*argv, "fwmark") == 0) { |
be7f286e PM |
740 | char *slash; |
741 | __u32 fwmark, fwmask; | |
56f5daac | 742 | |
aba5acdf | 743 | NEXT_ARG(); |
d831cc7c SH |
744 | |
745 | slash = strchr(*argv, '/'); | |
746 | if (slash != NULL) | |
be7f286e | 747 | *slash = '\0'; |
4fb466f9 | 748 | if (get_u32(&fwmark, *argv, 0)) |
aba5acdf | 749 | invarg("fwmark value is invalid\n", *argv); |
ad1a12db | 750 | addattr32(&req.n, sizeof(req), FRA_FWMARK, fwmark); |
be7f286e PM |
751 | if (slash) { |
752 | if (get_u32(&fwmask, slash+1, 0)) | |
d831cc7c SH |
753 | invarg("fwmask value is invalid\n", |
754 | slash+1); | |
755 | addattr32(&req.n, sizeof(req), | |
756 | FRA_FWMASK, fwmask); | |
be7f286e | 757 | } |
aba5acdf SH |
758 | } else if (matches(*argv, "realms") == 0) { |
759 | __u32 realm; | |
56f5daac | 760 | |
aba5acdf | 761 | NEXT_ARG(); |
d583e88e | 762 | if (get_rt_realms_or_raw(&realm, *argv)) |
aba5acdf | 763 | invarg("invalid realms\n", *argv); |
ad1a12db | 764 | addattr32(&req.n, sizeof(req), FRA_FLOW, realm); |
33f1e250 DS |
765 | } else if (matches(*argv, "protocol") == 0) { |
766 | __u32 proto; | |
767 | ||
768 | NEXT_ARG(); | |
769 | if (rtnl_rtprot_a2n(&proto, *argv)) | |
770 | invarg("\"protocol\" value is invalid\n", *argv); | |
771 | addattr8(&req.n, sizeof(req), FRA_PROTOCOL, proto); | |
aba5acdf SH |
772 | } else if (matches(*argv, "table") == 0 || |
773 | strcmp(*argv, "lookup") == 0) { | |
aba5acdf SH |
774 | NEXT_ARG(); |
775 | if (rtnl_rttable_a2n(&tid, *argv)) | |
776 | invarg("invalid table ID\n", *argv); | |
34e95647 | 777 | if (tid < 256) |
5baaf07c | 778 | req.frh.table = tid; |
34e95647 | 779 | else { |
5baaf07c | 780 | req.frh.table = RT_TABLE_UNSPEC; |
ad1a12db | 781 | addattr32(&req.n, sizeof(req), FRA_TABLE, tid); |
34e95647 | 782 | } |
aba5acdf | 783 | table_ok = 1; |
b1d0525f ST |
784 | } else if (matches(*argv, "suppress_prefixlength") == 0 || |
785 | strcmp(*argv, "sup_pl") == 0) { | |
786 | int pl; | |
56f5daac | 787 | |
b1d0525f ST |
788 | NEXT_ARG(); |
789 | if (get_s32(&pl, *argv, 0) || pl < 0) | |
d831cc7c SH |
790 | invarg("suppress_prefixlength value is invalid\n", |
791 | *argv); | |
792 | addattr32(&req.n, sizeof(req), | |
793 | FRA_SUPPRESS_PREFIXLEN, pl); | |
b1d0525f ST |
794 | } else if (matches(*argv, "suppress_ifgroup") == 0 || |
795 | strcmp(*argv, "sup_group") == 0) { | |
796 | NEXT_ARG(); | |
797 | int group; | |
56f5daac | 798 | |
b1d0525f | 799 | if (rtnl_group_a2n(&group, *argv)) |
d831cc7c SH |
800 | invarg("Invalid \"suppress_ifgroup\" value\n", |
801 | *argv); | |
802 | addattr32(&req.n, sizeof(req), | |
803 | FRA_SUPPRESS_IFGROUP, group); | |
aba5acdf SH |
804 | } else if (strcmp(*argv, "dev") == 0 || |
805 | strcmp(*argv, "iif") == 0) { | |
806 | NEXT_ARG(); | |
625df645 PS |
807 | if (check_ifname(*argv)) |
808 | invarg("\"iif\"/\"dev\" not a valid ifname", *argv); | |
d831cc7c SH |
809 | addattr_l(&req.n, sizeof(req), FRA_IFNAME, |
810 | *argv, strlen(*argv)+1); | |
85eae222 PM |
811 | } else if (strcmp(*argv, "oif") == 0) { |
812 | NEXT_ARG(); | |
625df645 PS |
813 | if (check_ifname(*argv)) |
814 | invarg("\"oif\" not a valid ifname", *argv); | |
d831cc7c SH |
815 | addattr_l(&req.n, sizeof(req), FRA_OIFNAME, |
816 | *argv, strlen(*argv)+1); | |
8c92e122 DA |
817 | } else if (strcmp(*argv, "l3mdev") == 0) { |
818 | addattr8(&req.n, sizeof(req), FRA_L3MDEV, 1); | |
819 | table_ok = 1; | |
820 | l3mdev_rule = 1; | |
82252cdc LC |
821 | } else if (strcmp(*argv, "uidrange") == 0) { |
822 | struct fib_rule_uid_range r; | |
823 | ||
824 | NEXT_ARG(); | |
825 | if (sscanf(*argv, "%u-%u", &r.start, &r.end) != 2) | |
826 | invarg("invalid UID range\n", *argv); | |
827 | addattr_l(&req.n, sizeof(req), FRA_UID_RANGE, &r, | |
828 | sizeof(r)); | |
aba5acdf SH |
829 | } else if (strcmp(*argv, "nat") == 0 || |
830 | matches(*argv, "map-to") == 0) { | |
831 | NEXT_ARG(); | |
526afe40 | 832 | fprintf(stderr, "Warning: route NAT is deprecated\n"); |
d831cc7c SH |
833 | addattr32(&req.n, sizeof(req), RTA_GATEWAY, |
834 | get_addr32(*argv)); | |
5baaf07c | 835 | req.frh.action = RTN_NAT; |
f686f764 RP |
836 | } else if (strcmp(*argv, "ipproto") == 0) { |
837 | int ipproto; | |
838 | ||
839 | NEXT_ARG(); | |
840 | ipproto = inet_proto_a2n(*argv); | |
841 | if (ipproto < 0) | |
842 | invarg("Invalid \"ipproto\" value\n", | |
843 | *argv); | |
844 | addattr8(&req.n, sizeof(req), FRA_IP_PROTO, ipproto); | |
845 | } else if (strcmp(*argv, "sport") == 0) { | |
846 | struct fib_rule_port_range r; | |
847 | int ret = 0; | |
848 | ||
849 | NEXT_ARG(); | |
850 | ret = sscanf(*argv, "%hu-%hu", &r.start, &r.end); | |
851 | if (ret == 1) | |
852 | r.end = r.start; | |
853 | else if (ret != 2) | |
854 | invarg("invalid port range\n", *argv); | |
855 | addattr_l(&req.n, sizeof(req), FRA_SPORT_RANGE, &r, | |
856 | sizeof(r)); | |
857 | } else if (strcmp(*argv, "dport") == 0) { | |
858 | struct fib_rule_port_range r; | |
859 | int ret = 0; | |
860 | ||
861 | NEXT_ARG(); | |
862 | ret = sscanf(*argv, "%hu-%hu", &r.start, &r.end); | |
863 | if (ret == 1) | |
864 | r.end = r.start; | |
865 | else if (ret != 2) | |
866 | invarg("invalid dport range\n", *argv); | |
867 | addattr_l(&req.n, sizeof(req), FRA_DPORT_RANGE, &r, | |
868 | sizeof(r)); | |
aba5acdf SH |
869 | } else { |
870 | int type; | |
871 | ||
d831cc7c | 872 | if (strcmp(*argv, "type") == 0) |
aba5acdf | 873 | NEXT_ARG(); |
d831cc7c | 874 | |
aba5acdf SH |
875 | if (matches(*argv, "help") == 0) |
876 | usage(); | |
6b469cae TG |
877 | else if (matches(*argv, "goto") == 0) { |
878 | __u32 target; | |
56f5daac | 879 | |
6b469cae TG |
880 | type = FR_ACT_GOTO; |
881 | NEXT_ARG(); | |
882 | if (get_u32(&target, *argv, 0)) | |
883 | invarg("invalid target\n", *argv); | |
d831cc7c SH |
884 | addattr32(&req.n, sizeof(req), |
885 | FRA_GOTO, target); | |
6b469cae TG |
886 | } else if (matches(*argv, "nop") == 0) |
887 | type = FR_ACT_NOP; | |
888 | else if (rtnl_rtntype_a2n(&type, *argv)) | |
aba5acdf | 889 | invarg("Failed to parse rule type", *argv); |
5baaf07c | 890 | req.frh.action = type; |
6b469cae | 891 | table_ok = 1; |
aba5acdf SH |
892 | } |
893 | argc--; | |
894 | argv++; | |
895 | } | |
896 | ||
8c92e122 DA |
897 | if (l3mdev_rule && tid != 0) { |
898 | fprintf(stderr, | |
899 | "table can not be specified for l3mdev rules\n"); | |
900 | return -EINVAL; | |
901 | } | |
902 | ||
5baaf07c DS |
903 | if (req.frh.family == AF_UNSPEC) |
904 | req.frh.family = AF_INET; | |
aba5acdf SH |
905 | |
906 | if (!table_ok && cmd == RTM_NEWRULE) | |
5baaf07c | 907 | req.frh.table = RT_TABLE_MAIN; |
aba5acdf | 908 | |
86bf43c7 | 909 | if (rtnl_talk(&rth, &req.n, NULL) < 0) |
076ae708 | 910 | return -2; |
aba5acdf SH |
911 | |
912 | return 0; | |
913 | } | |
914 | ||
915 | int do_iprule(int argc, char **argv) | |
916 | { | |
917 | if (argc < 1) { | |
cb294a1d | 918 | return iprule_list_flush_or_save(0, NULL, IPRULE_LIST); |
aba5acdf SH |
919 | } else if (matches(argv[0], "list") == 0 || |
920 | matches(argv[0], "lst") == 0 || | |
921 | matches(argv[0], "show") == 0) { | |
cb294a1d | 922 | return iprule_list_flush_or_save(argc-1, argv+1, IPRULE_LIST); |
2f4e171f | 923 | } else if (matches(argv[0], "save") == 0) { |
cb294a1d | 924 | return iprule_list_flush_or_save(argc-1, argv+1, IPRULE_SAVE); |
2f4e171f KT |
925 | } else if (matches(argv[0], "restore") == 0) { |
926 | return iprule_restore(); | |
aba5acdf SH |
927 | } else if (matches(argv[0], "add") == 0) { |
928 | return iprule_modify(RTM_NEWRULE, argc-1, argv+1); | |
929 | } else if (matches(argv[0], "delete") == 0) { | |
930 | return iprule_modify(RTM_DELRULE, argc-1, argv+1); | |
50772dc5 | 931 | } else if (matches(argv[0], "flush") == 0) { |
cb294a1d | 932 | return iprule_list_flush_or_save(argc-1, argv+1, IPRULE_FLUSH); |
aba5acdf SH |
933 | } else if (matches(argv[0], "help") == 0) |
934 | usage(); | |
935 | ||
d831cc7c SH |
936 | fprintf(stderr, |
937 | "Command \"%s\" is unknown, try \"ip rule help\".\n", *argv); | |
aba5acdf SH |
938 | exit(-1); |
939 | } | |
940 | ||
b6c8e808 PM |
941 | int do_multirule(int argc, char **argv) |
942 | { | |
943 | switch (preferred_family) { | |
944 | case AF_UNSPEC: | |
945 | case AF_INET: | |
946 | preferred_family = RTNL_FAMILY_IPMR; | |
947 | break; | |
948 | case AF_INET6: | |
949 | preferred_family = RTNL_FAMILY_IP6MR; | |
950 | break; | |
0d1c9b57 BG |
951 | case RTNL_FAMILY_IPMR: |
952 | case RTNL_FAMILY_IP6MR: | |
953 | break; | |
b6c8e808 | 954 | default: |
d831cc7c SH |
955 | fprintf(stderr, |
956 | "Multicast rules are only supported for IPv4/IPv6, was: %i\n", | |
0d1c9b57 | 957 | preferred_family); |
b6c8e808 PM |
958 | exit(-1); |
959 | } | |
960 | ||
961 | return do_iprule(argc, argv); | |
962 | } |