]>
Commit | Line | Data |
---|---|---|
aba5acdf SH |
1 | /* |
2 | * iproute.c "ip route". | |
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> | |
16 | #include <syslog.h> | |
17 | #include <fcntl.h> | |
18 | #include <string.h> | |
33551240 | 19 | #include <time.h> |
aba5acdf SH |
20 | #include <sys/time.h> |
21 | #include <sys/socket.h> | |
22 | #include <netinet/in.h> | |
23 | #include <netinet/ip.h> | |
24 | #include <arpa/inet.h> | |
25 | #include <linux/in_route.h> | |
194e9b85 | 26 | #include <linux/icmpv6.h> |
f4ff11e3 | 27 | #include <errno.h> |
aba5acdf SH |
28 | |
29 | #include "rt_names.h" | |
30 | #include "utils.h" | |
31 | #include "ip_common.h" | |
32 | ||
33 | #ifndef RTAX_RTTVAR | |
34 | #define RTAX_RTTVAR RTAX_HOPS | |
35 | #endif | |
36 | ||
f4ff11e3 DS |
37 | enum list_action { |
38 | IPROUTE_LIST, | |
39 | IPROUTE_FLUSH, | |
40 | IPROUTE_SAVE, | |
41 | }; | |
f38c7334 SH |
42 | static const char *mx_names[RTAX_MAX+1] = { |
43 | [RTAX_MTU] = "mtu", | |
44 | [RTAX_WINDOW] = "window", | |
45 | [RTAX_RTT] = "rtt", | |
46 | [RTAX_RTTVAR] = "rttvar", | |
47 | [RTAX_SSTHRESH] = "ssthresh", | |
48 | [RTAX_CWND] = "cwnd", | |
49 | [RTAX_ADVMSS] = "advmss", | |
50 | [RTAX_REORDERING]="reordering", | |
51 | [RTAX_HOPLIMIT] = "hoplimit", | |
52 | [RTAX_INITCWND] = "initcwnd", | |
53 | [RTAX_FEATURES] = "features", | |
54e0b2e7 | 54 | [RTAX_RTO_MIN] = "rto_min", |
f5fd8003 | 55 | [RTAX_INITRWND] = "initrwnd", |
b37f2c89 | 56 | [RTAX_QUICKACK] = "quickack", |
6ef87f9c | 57 | [RTAX_CC_ALGO] = "congctl", |
f38c7334 | 58 | }; |
aba5acdf SH |
59 | static void usage(void) __attribute__((noreturn)); |
60 | ||
61 | static void usage(void) | |
62 | { | |
63 | fprintf(stderr, "Usage: ip route { list | flush } SELECTOR\n"); | |
f4ff11e3 DS |
64 | fprintf(stderr, " ip route save SELECTOR\n"); |
65 | fprintf(stderr, " ip route restore\n"); | |
93b79863 | 66 | fprintf(stderr, " ip route showdump\n"); |
aba5acdf | 67 | fprintf(stderr, " ip route get ADDRESS [ from ADDRESS iif STRING ]\n"); |
8f480637 | 68 | fprintf(stderr, " [ oif STRING ] [ tos TOS ]\n"); |
b0373bfb | 69 | fprintf(stderr, " [ mark NUMBER ]\n"); |
c0c44bfe | 70 | fprintf(stderr, " ip route { add | del | change | append | replace } ROUTE\n"); |
aba5acdf SH |
71 | fprintf(stderr, "SELECTOR := [ root PREFIX ] [ match PREFIX ] [ exact PREFIX ]\n"); |
72 | fprintf(stderr, " [ table TABLE_ID ] [ proto RTPROTO ]\n"); | |
73 | fprintf(stderr, " [ type TYPE ] [ scope SCOPE ]\n"); | |
74 | fprintf(stderr, "ROUTE := NODE_SPEC [ INFO_SPEC ]\n"); | |
75 | fprintf(stderr, "NODE_SPEC := [ TYPE ] PREFIX [ tos TOS ]\n"); | |
76 | fprintf(stderr, " [ table TABLE_ID ] [ proto RTPROTO ]\n"); | |
77 | fprintf(stderr, " [ scope SCOPE ] [ metric METRIC ]\n"); | |
78 | fprintf(stderr, "INFO_SPEC := NH OPTIONS FLAGS [ nexthop NH ]...\n"); | |
93ae2835 | 79 | fprintf(stderr, "NH := [ via [ FAMILY ] ADDRESS ] [ dev STRING ] [ weight NUMBER ] NHFLAGS\n"); |
38a7f268 | 80 | fprintf(stderr, "FAMILY := [ inet | inet6 | ipx | dnet | mpls | bridge | link ]\n"); |
6f7a9f4d | 81 | fprintf(stderr, "OPTIONS := FLAGS [ mtu NUMBER ] [ advmss NUMBER ] [ as [ to ] ADDRESS ]\n"); |
8f480637 | 82 | fprintf(stderr, " [ rtt TIME ] [ rttvar TIME ] [ reordering NUMBER ]\n"); |
a1f1143e | 83 | fprintf(stderr, " [ window NUMBER] [ cwnd NUMBER ] [ initcwnd NUMBER ]\n"); |
576c63ee | 84 | fprintf(stderr, " [ ssthresh NUMBER ] [ realms REALM ] [ src ADDRESS ]\n"); |
f5fd8003 | 85 | fprintf(stderr, " [ rto_min TIME ] [ hoplimit NUMBER ] [ initrwnd NUMBER ]\n"); |
6ef87f9c | 86 | fprintf(stderr, " [ features FEATURES ] [ quickack BOOL ] [ congctl NAME ]\n"); |
194e9b85 | 87 | fprintf(stderr, " [ pref PREF ]\n"); |
aba5acdf SH |
88 | fprintf(stderr, "TYPE := [ unicast | local | broadcast | multicast | throw |\n"); |
89 | fprintf(stderr, " unreachable | prohibit | blackhole | nat ]\n"); | |
90 | fprintf(stderr, "TABLE_ID := [ local | main | default | all | NUMBER ]\n"); | |
91 | fprintf(stderr, "SCOPE := [ host | link | global | NUMBER ]\n"); | |
aba5acdf SH |
92 | fprintf(stderr, "NHFLAGS := [ onlink | pervasive ]\n"); |
93 | fprintf(stderr, "RTPROTO := [ kernel | boot | static | NUMBER ]\n"); | |
194e9b85 | 94 | fprintf(stderr, "PREF := [ low | medium | high ]\n"); |
9b2cdc00 | 95 | fprintf(stderr, "TIME := NUMBER[s|ms]\n"); |
b37f2c89 | 96 | fprintf(stderr, "BOOL := [1|0]\n"); |
29d1f730 | 97 | fprintf(stderr, "FEATURES := ecn\n"); |
aba5acdf SH |
98 | exit(-1); |
99 | } | |
100 | ||
101 | ||
102 | static struct | |
103 | { | |
caae16b3 | 104 | unsigned int tb; |
bd4bcdad | 105 | int cloned; |
aba5acdf SH |
106 | int flushed; |
107 | char *flushb; | |
108 | int flushp; | |
109 | int flushe; | |
aba5acdf SH |
110 | int protocol, protocolmask; |
111 | int scope, scopemask; | |
112 | int type, typemask; | |
113 | int tos, tosmask; | |
114 | int iif, iifmask; | |
115 | int oif, oifmask; | |
b0373bfb | 116 | int mark, markmask; |
aba5acdf SH |
117 | int realm, realmmask; |
118 | inet_prefix rprefsrc; | |
119 | inet_prefix rvia; | |
120 | inet_prefix rdst; | |
121 | inet_prefix mdst; | |
122 | inet_prefix rsrc; | |
123 | inet_prefix msrc; | |
124 | } filter; | |
125 | ||
126 | static int flush_update(void) | |
127 | { | |
f31a37f7 | 128 | if (rtnl_send_check(&rth, filter.flushb, filter.flushp) < 0) { |
1fb0a998 | 129 | perror("Failed to send flush request"); |
aba5acdf SH |
130 | return -1; |
131 | } | |
132 | filter.flushp = 0; | |
133 | return 0; | |
134 | } | |
135 | ||
d1f28cf1 | 136 | static int filter_nlmsg(struct nlmsghdr *n, struct rtattr **tb, int host_len) |
aba5acdf | 137 | { |
aba5acdf | 138 | struct rtmsg *r = NLMSG_DATA(n); |
aba5acdf SH |
139 | inet_prefix dst; |
140 | inet_prefix src; | |
aba5acdf | 141 | inet_prefix via; |
f4ff11e3 | 142 | inet_prefix prefsrc; |
34e95647 | 143 | __u32 table; |
f4ff11e3 | 144 | static int ip6_multiple_tables; |
aba5acdf | 145 | |
34e95647 PM |
146 | table = rtm_get_table(r, tb); |
147 | ||
5b9ac190 AV |
148 | if (preferred_family != AF_UNSPEC && r->rtm_family != preferred_family) |
149 | return 0; | |
150 | ||
34e95647 | 151 | if (r->rtm_family == AF_INET6 && table != RT_TABLE_MAIN) |
e0b29fe7 PM |
152 | ip6_multiple_tables = 1; |
153 | ||
44792827 UW |
154 | if (filter.cloned == !(r->rtm_flags&RTM_F_CLONED)) |
155 | return 0; | |
156 | ||
e0b29fe7 | 157 | if (r->rtm_family == AF_INET6 && !ip6_multiple_tables) { |
aba5acdf | 158 | if (filter.tb) { |
bd4bcdad PM |
159 | if (filter.tb == RT_TABLE_LOCAL) { |
160 | if (r->rtm_type != RTN_LOCAL) | |
aba5acdf | 161 | return 0; |
bd4bcdad PM |
162 | } else if (filter.tb == RT_TABLE_MAIN) { |
163 | if (r->rtm_type == RTN_LOCAL) | |
aba5acdf | 164 | return 0; |
bd4bcdad PM |
165 | } else { |
166 | return 0; | |
aba5acdf SH |
167 | } |
168 | } | |
169 | } else { | |
34e95647 | 170 | if (filter.tb > 0 && filter.tb != table) |
aba5acdf SH |
171 | return 0; |
172 | } | |
173 | if ((filter.protocol^r->rtm_protocol)&filter.protocolmask) | |
174 | return 0; | |
175 | if ((filter.scope^r->rtm_scope)&filter.scopemask) | |
176 | return 0; | |
177 | if ((filter.type^r->rtm_type)&filter.typemask) | |
178 | return 0; | |
179 | if ((filter.tos^r->rtm_tos)&filter.tosmask) | |
180 | return 0; | |
181 | if (filter.rdst.family && | |
182 | (r->rtm_family != filter.rdst.family || filter.rdst.bitlen > r->rtm_dst_len)) | |
183 | return 0; | |
184 | if (filter.mdst.family && | |
185 | (r->rtm_family != filter.mdst.family || | |
186 | (filter.mdst.bitlen >= 0 && filter.mdst.bitlen < r->rtm_dst_len))) | |
187 | return 0; | |
188 | if (filter.rsrc.family && | |
189 | (r->rtm_family != filter.rsrc.family || filter.rsrc.bitlen > r->rtm_src_len)) | |
190 | return 0; | |
191 | if (filter.msrc.family && | |
192 | (r->rtm_family != filter.msrc.family || | |
193 | (filter.msrc.bitlen >= 0 && filter.msrc.bitlen < r->rtm_src_len))) | |
194 | return 0; | |
93ae2835 EB |
195 | if (filter.rvia.family) { |
196 | int family = r->rtm_family; | |
197 | if (tb[RTA_VIA]) { | |
198 | struct rtvia *via = RTA_DATA(tb[RTA_VIA]); | |
199 | family = via->rtvia_family; | |
200 | } | |
201 | if (family != filter.rvia.family) | |
202 | return 0; | |
203 | } | |
aba5acdf SH |
204 | if (filter.rprefsrc.family && r->rtm_family != filter.rprefsrc.family) |
205 | return 0; | |
206 | ||
aba5acdf SH |
207 | memset(&dst, 0, sizeof(dst)); |
208 | dst.family = r->rtm_family; | |
209 | if (tb[RTA_DST]) | |
210 | memcpy(&dst.data, RTA_DATA(tb[RTA_DST]), (r->rtm_dst_len+7)/8); | |
211 | if (filter.rsrc.family || filter.msrc.family) { | |
212 | memset(&src, 0, sizeof(src)); | |
213 | src.family = r->rtm_family; | |
214 | if (tb[RTA_SRC]) | |
215 | memcpy(&src.data, RTA_DATA(tb[RTA_SRC]), (r->rtm_src_len+7)/8); | |
216 | } | |
217 | if (filter.rvia.bitlen>0) { | |
218 | memset(&via, 0, sizeof(via)); | |
219 | via.family = r->rtm_family; | |
220 | if (tb[RTA_GATEWAY]) | |
7849fb55 | 221 | memcpy(&via.data, RTA_DATA(tb[RTA_GATEWAY]), host_len/8); |
93ae2835 EB |
222 | if (tb[RTA_VIA]) { |
223 | size_t len = RTA_PAYLOAD(tb[RTA_VIA]) - 2; | |
224 | struct rtvia *rtvia = RTA_DATA(tb[RTA_VIA]); | |
225 | via.family = rtvia->rtvia_family; | |
226 | memcpy(&via.data, rtvia->rtvia_addr, len); | |
227 | } | |
aba5acdf SH |
228 | } |
229 | if (filter.rprefsrc.bitlen>0) { | |
230 | memset(&prefsrc, 0, sizeof(prefsrc)); | |
231 | prefsrc.family = r->rtm_family; | |
232 | if (tb[RTA_PREFSRC]) | |
7849fb55 | 233 | memcpy(&prefsrc.data, RTA_DATA(tb[RTA_PREFSRC]), host_len/8); |
aba5acdf SH |
234 | } |
235 | ||
236 | if (filter.rdst.family && inet_addr_match(&dst, &filter.rdst, filter.rdst.bitlen)) | |
237 | return 0; | |
238 | if (filter.mdst.family && filter.mdst.bitlen >= 0 && | |
239 | inet_addr_match(&dst, &filter.mdst, r->rtm_dst_len)) | |
240 | return 0; | |
241 | ||
242 | if (filter.rsrc.family && inet_addr_match(&src, &filter.rsrc, filter.rsrc.bitlen)) | |
243 | return 0; | |
244 | if (filter.msrc.family && filter.msrc.bitlen >= 0 && | |
245 | inet_addr_match(&src, &filter.msrc, r->rtm_src_len)) | |
246 | return 0; | |
247 | ||
248 | if (filter.rvia.family && inet_addr_match(&via, &filter.rvia, filter.rvia.bitlen)) | |
249 | return 0; | |
250 | if (filter.rprefsrc.family && inet_addr_match(&prefsrc, &filter.rprefsrc, filter.rprefsrc.bitlen)) | |
251 | return 0; | |
252 | if (filter.realmmask) { | |
253 | __u32 realms = 0; | |
254 | if (tb[RTA_FLOW]) | |
ff24746c | 255 | realms = rta_getattr_u32(tb[RTA_FLOW]); |
aba5acdf SH |
256 | if ((realms^filter.realm)&filter.realmmask) |
257 | return 0; | |
258 | } | |
259 | if (filter.iifmask) { | |
260 | int iif = 0; | |
261 | if (tb[RTA_IIF]) | |
262 | iif = *(int*)RTA_DATA(tb[RTA_IIF]); | |
263 | if ((iif^filter.iif)&filter.iifmask) | |
264 | return 0; | |
265 | } | |
266 | if (filter.oifmask) { | |
267 | int oif = 0; | |
268 | if (tb[RTA_OIF]) | |
269 | oif = *(int*)RTA_DATA(tb[RTA_OIF]); | |
270 | if ((oif^filter.oif)&filter.oifmask) | |
271 | return 0; | |
272 | } | |
b0373bfb ED |
273 | if (filter.markmask) { |
274 | int mark = 0; | |
275 | if (tb[RTA_MARK]) | |
276 | mark = *(int *)RTA_DATA(tb[RTA_MARK]); | |
277 | if ((mark ^ filter.mark) & filter.markmask) | |
278 | return 0; | |
279 | } | |
ae665a52 | 280 | if (filter.flushb && |
aba5acdf SH |
281 | r->rtm_family == AF_INET6 && |
282 | r->rtm_dst_len == 0 && | |
283 | r->rtm_type == RTN_UNREACHABLE && | |
284 | tb[RTA_PRIORITY] && | |
285 | *(int*)RTA_DATA(tb[RTA_PRIORITY]) == -1) | |
286 | return 0; | |
287 | ||
f4ff11e3 DS |
288 | return 1; |
289 | } | |
290 | ||
29d1f730 FW |
291 | static void print_rtax_features(FILE *fp, unsigned int features) |
292 | { | |
293 | unsigned int of = features; | |
294 | ||
295 | if (features & RTAX_FEATURE_ECN) { | |
296 | fprintf(fp, " ecn"); | |
297 | features &= ~RTAX_FEATURE_ECN; | |
298 | } | |
299 | ||
300 | if (features) | |
301 | fprintf(fp, " 0x%x", of); | |
302 | } | |
303 | ||
f4ff11e3 DS |
304 | int print_route(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg) |
305 | { | |
306 | FILE *fp = (FILE*)arg; | |
307 | struct rtmsg *r = NLMSG_DATA(n); | |
308 | int len = n->nlmsg_len; | |
309 | struct rtattr * tb[RTA_MAX+1]; | |
310 | char abuf[256]; | |
f3a2ddc1 | 311 | int host_len; |
f4ff11e3 DS |
312 | __u32 table; |
313 | SPRINT_BUF(b1); | |
314 | static int hz; | |
315 | ||
316 | if (n->nlmsg_type != RTM_NEWROUTE && n->nlmsg_type != RTM_DELROUTE) { | |
317 | fprintf(stderr, "Not a route: %08x %08x %08x\n", | |
318 | n->nlmsg_len, n->nlmsg_type, n->nlmsg_flags); | |
319 | return 0; | |
320 | } | |
321 | if (filter.flushb && n->nlmsg_type != RTM_NEWROUTE) | |
322 | return 0; | |
323 | len -= NLMSG_LENGTH(sizeof(*r)); | |
324 | if (len < 0) { | |
325 | fprintf(stderr, "BUG: wrong nlmsg len %d\n", len); | |
326 | return -1; | |
327 | } | |
328 | ||
f3a2ddc1 | 329 | host_len = af_bit_len(r->rtm_family); |
f4ff11e3 DS |
330 | |
331 | parse_rtattr(tb, RTA_MAX, RTM_RTA(r), len); | |
332 | table = rtm_get_table(r, tb); | |
333 | ||
334 | if (!filter_nlmsg(n, tb, host_len)) | |
335 | return 0; | |
336 | ||
aba5acdf SH |
337 | if (filter.flushb) { |
338 | struct nlmsghdr *fn; | |
339 | if (NLMSG_ALIGN(filter.flushp) + n->nlmsg_len > filter.flushe) { | |
340 | if (flush_update()) | |
341 | return -1; | |
342 | } | |
343 | fn = (struct nlmsghdr*)(filter.flushb + NLMSG_ALIGN(filter.flushp)); | |
344 | memcpy(fn, n, n->nlmsg_len); | |
345 | fn->nlmsg_type = RTM_DELROUTE; | |
346 | fn->nlmsg_flags = NLM_F_REQUEST; | |
351efcde | 347 | fn->nlmsg_seq = ++rth.seq; |
aba5acdf SH |
348 | filter.flushp = (((char*)fn) + n->nlmsg_len) - filter.flushb; |
349 | filter.flushed++; | |
350 | if (show_stats < 2) | |
351 | return 0; | |
352 | } | |
353 | ||
354 | if (n->nlmsg_type == RTM_DELROUTE) | |
355 | fprintf(fp, "Deleted "); | |
577e5a53 | 356 | if ((r->rtm_type != RTN_UNICAST || show_details > 0) && !filter.type) |
aba5acdf SH |
357 | fprintf(fp, "%s ", rtnl_rtntype_n2a(r->rtm_type, b1, sizeof(b1))); |
358 | ||
359 | if (tb[RTA_DST]) { | |
360 | if (r->rtm_dst_len != host_len) { | |
361 | fprintf(fp, "%s/%u ", rt_addr_n2a(r->rtm_family, | |
26dcdf3a EB |
362 | RTA_PAYLOAD(tb[RTA_DST]), |
363 | RTA_DATA(tb[RTA_DST]), | |
364 | abuf, sizeof(abuf)), | |
aba5acdf SH |
365 | r->rtm_dst_len |
366 | ); | |
367 | } else { | |
368 | fprintf(fp, "%s ", format_host(r->rtm_family, | |
369 | RTA_PAYLOAD(tb[RTA_DST]), | |
370 | RTA_DATA(tb[RTA_DST]), | |
371 | abuf, sizeof(abuf)) | |
372 | ); | |
373 | } | |
374 | } else if (r->rtm_dst_len) { | |
375 | fprintf(fp, "0/%d ", r->rtm_dst_len); | |
376 | } else { | |
377 | fprintf(fp, "default "); | |
378 | } | |
379 | if (tb[RTA_SRC]) { | |
380 | if (r->rtm_src_len != host_len) { | |
381 | fprintf(fp, "from %s/%u ", rt_addr_n2a(r->rtm_family, | |
26dcdf3a EB |
382 | RTA_PAYLOAD(tb[RTA_SRC]), |
383 | RTA_DATA(tb[RTA_SRC]), | |
384 | abuf, sizeof(abuf)), | |
aba5acdf SH |
385 | r->rtm_src_len |
386 | ); | |
387 | } else { | |
388 | fprintf(fp, "from %s ", format_host(r->rtm_family, | |
389 | RTA_PAYLOAD(tb[RTA_SRC]), | |
390 | RTA_DATA(tb[RTA_SRC]), | |
391 | abuf, sizeof(abuf)) | |
392 | ); | |
393 | } | |
394 | } else if (r->rtm_src_len) { | |
395 | fprintf(fp, "from 0/%u ", r->rtm_src_len); | |
396 | } | |
6f7a9f4d EB |
397 | if (tb[RTA_NEWDST]) { |
398 | fprintf(fp, "as to %s ", format_host(r->rtm_family, | |
399 | RTA_PAYLOAD(tb[RTA_NEWDST]), | |
400 | RTA_DATA(tb[RTA_NEWDST]), | |
401 | abuf, sizeof(abuf)) | |
402 | ); | |
403 | } | |
aba5acdf SH |
404 | if (r->rtm_tos && filter.tosmask != -1) { |
405 | SPRINT_BUF(b1); | |
406 | fprintf(fp, "tos %s ", rtnl_dsfield_n2a(r->rtm_tos, b1, sizeof(b1))); | |
407 | } | |
02d2ae55 | 408 | |
aba5acdf | 409 | if (tb[RTA_GATEWAY] && filter.rvia.bitlen != host_len) { |
ae665a52 | 410 | fprintf(fp, "via %s ", |
aba5acdf SH |
411 | format_host(r->rtm_family, |
412 | RTA_PAYLOAD(tb[RTA_GATEWAY]), | |
413 | RTA_DATA(tb[RTA_GATEWAY]), | |
414 | abuf, sizeof(abuf))); | |
415 | } | |
93ae2835 EB |
416 | if (tb[RTA_VIA]) { |
417 | size_t len = RTA_PAYLOAD(tb[RTA_VIA]) - 2; | |
418 | struct rtvia *via = RTA_DATA(tb[RTA_VIA]); | |
419 | fprintf(fp, "via %s %s ", | |
420 | family_name(via->rtvia_family), | |
421 | format_host(via->rtvia_family, len, via->rtvia_addr, | |
422 | abuf, sizeof(abuf))); | |
423 | } | |
aba5acdf SH |
424 | if (tb[RTA_OIF] && filter.oifmask != -1) |
425 | fprintf(fp, "dev %s ", ll_index_to_name(*(int*)RTA_DATA(tb[RTA_OIF]))); | |
426 | ||
427 | if (!(r->rtm_flags&RTM_F_CLONED)) { | |
577e5a53 | 428 | if ((table != RT_TABLE_MAIN || show_details > 0) && !filter.tb) |
34e95647 | 429 | fprintf(fp, " table %s ", rtnl_rttable_n2a(table, b1, sizeof(b1))); |
577e5a53 | 430 | if ((r->rtm_protocol != RTPROT_BOOT || show_details > 0) && filter.protocolmask != -1) |
aba5acdf | 431 | fprintf(fp, " proto %s ", rtnl_rtprot_n2a(r->rtm_protocol, b1, sizeof(b1))); |
577e5a53 | 432 | if ((r->rtm_scope != RT_SCOPE_UNIVERSE || show_details > 0) && filter.scopemask != -1) |
aba5acdf SH |
433 | fprintf(fp, " scope %s ", rtnl_rtscope_n2a(r->rtm_scope, b1, sizeof(b1))); |
434 | } | |
435 | if (tb[RTA_PREFSRC] && filter.rprefsrc.bitlen != host_len) { | |
436 | /* Do not use format_host(). It is our local addr | |
437 | and symbolic name will not be useful. | |
438 | */ | |
ae665a52 | 439 | fprintf(fp, " src %s ", |
aba5acdf | 440 | rt_addr_n2a(r->rtm_family, |
26dcdf3a | 441 | RTA_PAYLOAD(tb[RTA_PREFSRC]), |
aba5acdf SH |
442 | RTA_DATA(tb[RTA_PREFSRC]), |
443 | abuf, sizeof(abuf))); | |
444 | } | |
445 | if (tb[RTA_PRIORITY]) | |
ff24746c | 446 | fprintf(fp, " metric %u ", rta_getattr_u32(tb[RTA_PRIORITY])); |
aba5acdf SH |
447 | if (r->rtm_flags & RTNH_F_DEAD) |
448 | fprintf(fp, "dead "); | |
449 | if (r->rtm_flags & RTNH_F_ONLINK) | |
450 | fprintf(fp, "onlink "); | |
451 | if (r->rtm_flags & RTNH_F_PERVASIVE) | |
452 | fprintf(fp, "pervasive "); | |
c52827e9 | 453 | if (r->rtm_flags & RTNH_F_OFFLOAD) |
aa05b988 | 454 | fprintf(fp, "offload "); |
aba5acdf SH |
455 | if (r->rtm_flags & RTM_F_NOTIFY) |
456 | fprintf(fp, "notify "); | |
528c2551 AG |
457 | if (r->rtm_flags & RTNH_F_LINKDOWN) |
458 | fprintf(fp, "linkdown "); | |
b0373bfb ED |
459 | if (tb[RTA_MARK]) { |
460 | unsigned int mark = *(unsigned int*)RTA_DATA(tb[RTA_MARK]); | |
461 | if (mark) { | |
462 | if (mark >= 16) | |
463 | fprintf(fp, " mark 0x%x", mark); | |
464 | else | |
465 | fprintf(fp, " mark %u", mark); | |
466 | } | |
467 | } | |
aba5acdf SH |
468 | |
469 | if (tb[RTA_FLOW] && filter.realmmask != ~0U) { | |
ff24746c | 470 | __u32 to = rta_getattr_u32(tb[RTA_FLOW]); |
aba5acdf SH |
471 | __u32 from = to>>16; |
472 | to &= 0xFFFF; | |
473 | fprintf(fp, "realm%s ", from ? "s" : ""); | |
474 | if (from) { | |
475 | fprintf(fp, "%s/", | |
476 | rtnl_rtrealm_n2a(from, b1, sizeof(b1))); | |
477 | } | |
478 | fprintf(fp, "%s ", | |
479 | rtnl_rtrealm_n2a(to, b1, sizeof(b1))); | |
480 | } | |
481 | if ((r->rtm_flags&RTM_F_CLONED) && r->rtm_family == AF_INET) { | |
482 | __u32 flags = r->rtm_flags&~0xFFFF; | |
483 | int first = 1; | |
484 | ||
485 | fprintf(fp, "%s cache ", _SL_); | |
486 | ||
487 | #define PRTFL(fl,flname) if (flags&RTCF_##fl) { \ | |
488 | flags &= ~RTCF_##fl; \ | |
489 | fprintf(fp, "%s" flname "%s", first ? "<" : "", flags ? "," : "> "); \ | |
490 | first = 0; } | |
491 | PRTFL(LOCAL, "local"); | |
492 | PRTFL(REJECT, "reject"); | |
493 | PRTFL(MULTICAST, "mc"); | |
494 | PRTFL(BROADCAST, "brd"); | |
495 | PRTFL(DNAT, "dst-nat"); | |
496 | PRTFL(SNAT, "src-nat"); | |
497 | PRTFL(MASQ, "masq"); | |
498 | PRTFL(DIRECTDST, "dst-direct"); | |
499 | PRTFL(DIRECTSRC, "src-direct"); | |
500 | PRTFL(REDIRECTED, "redirected"); | |
501 | PRTFL(DOREDIRECT, "redirect"); | |
502 | PRTFL(FAST, "fastroute"); | |
503 | PRTFL(NOTIFY, "notify"); | |
504 | PRTFL(TPROXY, "proxy"); | |
63a0f20a | 505 | |
aba5acdf SH |
506 | if (flags) |
507 | fprintf(fp, "%s%x> ", first ? "<" : "", flags); | |
508 | if (tb[RTA_CACHEINFO]) { | |
509 | struct rta_cacheinfo *ci = RTA_DATA(tb[RTA_CACHEINFO]); | |
aba5acdf | 510 | if (!hz) |
5e8bc631 | 511 | hz = get_user_hz(); |
aba5acdf SH |
512 | if (ci->rta_expires != 0) |
513 | fprintf(fp, " expires %dsec", ci->rta_expires/hz); | |
514 | if (ci->rta_error != 0) | |
515 | fprintf(fp, " error %d", ci->rta_error); | |
516 | if (show_stats) { | |
517 | if (ci->rta_clntref) | |
518 | fprintf(fp, " users %d", ci->rta_clntref); | |
519 | if (ci->rta_used != 0) | |
520 | fprintf(fp, " used %d", ci->rta_used); | |
521 | if (ci->rta_lastuse != 0) | |
522 | fprintf(fp, " age %dsec", ci->rta_lastuse/hz); | |
523 | } | |
aba5acdf SH |
524 | if (ci->rta_id) |
525 | fprintf(fp, " ipid 0x%04x", ci->rta_id); | |
526 | if (ci->rta_ts || ci->rta_tsage) | |
d5b7420a SH |
527 | fprintf(fp, " ts 0x%x tsage %dsec", |
528 | ci->rta_ts, ci->rta_tsage); | |
aba5acdf SH |
529 | } |
530 | } else if (r->rtm_family == AF_INET6) { | |
531 | struct rta_cacheinfo *ci = NULL; | |
532 | if (tb[RTA_CACHEINFO]) | |
533 | ci = RTA_DATA(tb[RTA_CACHEINFO]); | |
534 | if ((r->rtm_flags & RTM_F_CLONED) || (ci && ci->rta_expires)) { | |
aba5acdf | 535 | if (!hz) |
5e8bc631 | 536 | hz = get_user_hz(); |
aba5acdf SH |
537 | if (r->rtm_flags & RTM_F_CLONED) |
538 | fprintf(fp, "%s cache ", _SL_); | |
539 | if (ci->rta_expires) | |
540 | fprintf(fp, " expires %dsec", ci->rta_expires/hz); | |
541 | if (ci->rta_error != 0) | |
542 | fprintf(fp, " error %d", ci->rta_error); | |
543 | if (show_stats) { | |
544 | if (ci->rta_clntref) | |
545 | fprintf(fp, " users %d", ci->rta_clntref); | |
546 | if (ci->rta_used != 0) | |
547 | fprintf(fp, " used %d", ci->rta_used); | |
548 | if (ci->rta_lastuse != 0) | |
549 | fprintf(fp, " age %dsec", ci->rta_lastuse/hz); | |
550 | } | |
551 | } else if (ci) { | |
552 | if (ci->rta_error != 0) | |
553 | fprintf(fp, " error %d", ci->rta_error); | |
554 | } | |
555 | } | |
556 | if (tb[RTA_METRICS]) { | |
557 | int i; | |
558 | unsigned mxlock = 0; | |
559 | struct rtattr *mxrta[RTAX_MAX+1]; | |
560 | ||
aba5acdf SH |
561 | parse_rtattr(mxrta, RTAX_MAX, RTA_DATA(tb[RTA_METRICS]), |
562 | RTA_PAYLOAD(tb[RTA_METRICS])); | |
563 | if (mxrta[RTAX_LOCK]) | |
564 | mxlock = *(unsigned*)RTA_DATA(mxrta[RTAX_LOCK]); | |
565 | ||
f38c7334 | 566 | for (i=2; i<= RTAX_MAX; i++) { |
6ef87f9c | 567 | __u32 val; |
ced61d7d | 568 | |
aba5acdf SH |
569 | if (mxrta[i] == NULL) |
570 | continue; | |
6a79240b SH |
571 | |
572 | if (i < sizeof(mx_names)/sizeof(char*) && mx_names[i]) | |
573 | fprintf(fp, " %s", mx_names[i]); | |
aba5acdf | 574 | else |
5e8bc631 | 575 | fprintf(fp, " metric %d", i); |
6ef87f9c | 576 | |
aba5acdf SH |
577 | if (mxlock & (1<<i)) |
578 | fprintf(fp, " lock"); | |
6ef87f9c DB |
579 | if (i != RTAX_CC_ALGO) |
580 | val = rta_getattr_u32(mxrta[i]); | |
aba5acdf | 581 | |
ced61d7d | 582 | switch (i) { |
29d1f730 FW |
583 | case RTAX_FEATURES: |
584 | print_rtax_features(fp, val); | |
585 | break; | |
ced61d7d | 586 | case RTAX_HOPLIMIT: |
62011a0b | 587 | if ((int)val == -1) |
ced61d7d SH |
588 | val = 0; |
589 | /* fall through */ | |
590 | default: | |
591 | fprintf(fp, " %u", val); | |
592 | break; | |
aba5acdf | 593 | |
ced61d7d SH |
594 | case RTAX_RTT: |
595 | case RTAX_RTTVAR: | |
596 | case RTAX_RTO_MIN: | |
aba5acdf SH |
597 | if (i == RTAX_RTT) |
598 | val /= 8; | |
54e0b2e7 | 599 | else if (i == RTAX_RTTVAR) |
aba5acdf | 600 | val /= 4; |
ced61d7d | 601 | |
9b2cdc00 GR |
602 | if (val >= 1000) |
603 | fprintf(fp, " %gs", val/1e3); | |
aba5acdf | 604 | else |
9b2cdc00 | 605 | fprintf(fp, " %ums", val); |
6ef87f9c DB |
606 | break; |
607 | case RTAX_CC_ALGO: | |
608 | fprintf(fp, " %s", rta_getattr_str(mxrta[i])); | |
609 | break; | |
aba5acdf SH |
610 | } |
611 | } | |
612 | } | |
613 | if (tb[RTA_IIF] && filter.iifmask != -1) { | |
614 | fprintf(fp, " iif %s", ll_index_to_name(*(int*)RTA_DATA(tb[RTA_IIF]))); | |
615 | } | |
616 | if (tb[RTA_MULTIPATH]) { | |
617 | struct rtnexthop *nh = RTA_DATA(tb[RTA_MULTIPATH]); | |
618 | int first = 0; | |
619 | ||
620 | len = RTA_PAYLOAD(tb[RTA_MULTIPATH]); | |
621 | ||
622 | for (;;) { | |
623 | if (len < sizeof(*nh)) | |
624 | break; | |
625 | if (nh->rtnh_len > len) | |
626 | break; | |
627 | if (r->rtm_flags&RTM_F_CLONED && r->rtm_type == RTN_MULTICAST) { | |
628 | if (first) | |
629 | fprintf(fp, " Oifs:"); | |
630 | else | |
631 | fprintf(fp, " "); | |
632 | } else | |
633 | fprintf(fp, "%s\tnexthop", _SL_); | |
634 | if (nh->rtnh_len > sizeof(*nh)) { | |
aba5acdf SH |
635 | parse_rtattr(tb, RTA_MAX, RTNH_DATA(nh), nh->rtnh_len - sizeof(*nh)); |
636 | if (tb[RTA_GATEWAY]) { | |
ae665a52 | 637 | fprintf(fp, " via %s ", |
aba5acdf SH |
638 | format_host(r->rtm_family, |
639 | RTA_PAYLOAD(tb[RTA_GATEWAY]), | |
640 | RTA_DATA(tb[RTA_GATEWAY]), | |
641 | abuf, sizeof(abuf))); | |
642 | } | |
93ae2835 EB |
643 | if (tb[RTA_VIA]) { |
644 | size_t len = RTA_PAYLOAD(tb[RTA_VIA]) - 2; | |
645 | struct rtvia *via = RTA_DATA(tb[RTA_VIA]); | |
646 | fprintf(fp, "via %s %s ", | |
647 | family_name(via->rtvia_family), | |
648 | format_host(via->rtvia_family, len, via->rtvia_addr, | |
649 | abuf, sizeof(abuf))); | |
650 | } | |
f4f6d640 | 651 | if (tb[RTA_FLOW]) { |
ff24746c | 652 | __u32 to = rta_getattr_u32(tb[RTA_FLOW]); |
f4f6d640 PM |
653 | __u32 from = to>>16; |
654 | to &= 0xFFFF; | |
655 | fprintf(fp, " realm%s ", from ? "s" : ""); | |
656 | if (from) { | |
657 | fprintf(fp, "%s/", | |
658 | rtnl_rtrealm_n2a(from, b1, sizeof(b1))); | |
659 | } | |
660 | fprintf(fp, "%s", | |
661 | rtnl_rtrealm_n2a(to, b1, sizeof(b1))); | |
662 | } | |
aba5acdf SH |
663 | } |
664 | if (r->rtm_flags&RTM_F_CLONED && r->rtm_type == RTN_MULTICAST) { | |
665 | fprintf(fp, " %s", ll_index_to_name(nh->rtnh_ifindex)); | |
666 | if (nh->rtnh_hops != 1) | |
667 | fprintf(fp, "(ttl>%d)", nh->rtnh_hops); | |
668 | } else { | |
669 | fprintf(fp, " dev %s", ll_index_to_name(nh->rtnh_ifindex)); | |
670 | fprintf(fp, " weight %d", nh->rtnh_hops+1); | |
671 | } | |
672 | if (nh->rtnh_flags & RTNH_F_DEAD) | |
673 | fprintf(fp, " dead"); | |
674 | if (nh->rtnh_flags & RTNH_F_ONLINK) | |
675 | fprintf(fp, " onlink"); | |
676 | if (nh->rtnh_flags & RTNH_F_PERVASIVE) | |
677 | fprintf(fp, " pervasive"); | |
528c2551 AG |
678 | if (nh->rtnh_flags & RTNH_F_LINKDOWN) |
679 | fprintf(fp, " linkdown"); | |
aba5acdf SH |
680 | len -= NLMSG_ALIGN(nh->rtnh_len); |
681 | nh = RTNH_NEXT(nh); | |
682 | } | |
683 | } | |
194e9b85 LR |
684 | if (tb[RTA_PREF]) { |
685 | unsigned int pref = rta_getattr_u8(tb[RTA_PREF]); | |
686 | fprintf(fp, " pref "); | |
687 | ||
688 | switch (pref) { | |
689 | case ICMPV6_ROUTER_PREF_LOW: | |
690 | fprintf(fp, "low"); | |
691 | break; | |
692 | case ICMPV6_ROUTER_PREF_MEDIUM: | |
693 | fprintf(fp, "medium"); | |
694 | break; | |
695 | case ICMPV6_ROUTER_PREF_HIGH: | |
696 | fprintf(fp, "high"); | |
697 | break; | |
698 | default: | |
699 | fprintf(fp, "%u", pref); | |
700 | } | |
701 | } | |
aba5acdf SH |
702 | fprintf(fp, "\n"); |
703 | fflush(fp); | |
704 | return 0; | |
705 | } | |
706 | ||
707 | ||
d1f28cf1 SH |
708 | static int parse_one_nh(struct rtmsg *r, struct rtattr *rta, |
709 | struct rtnexthop *rtnh, | |
710 | int *argcp, char ***argvp) | |
aba5acdf SH |
711 | { |
712 | int argc = *argcp; | |
713 | char **argv = *argvp; | |
714 | ||
715 | while (++argv, --argc > 0) { | |
716 | if (strcmp(*argv, "via") == 0) { | |
4d6c3796 | 717 | inet_prefix addr; |
93ae2835 | 718 | int family; |
aba5acdf | 719 | NEXT_ARG(); |
93ae2835 EB |
720 | family = read_family(*argv); |
721 | if (family == AF_UNSPEC) | |
722 | family = r->rtm_family; | |
723 | else | |
724 | NEXT_ARG(); | |
725 | get_addr(&addr, *argv, family); | |
4d6c3796 VB |
726 | if (r->rtm_family == AF_UNSPEC) |
727 | r->rtm_family = addr.family; | |
93ae2835 EB |
728 | if (addr.family == r->rtm_family) { |
729 | rta_addattr_l(rta, 4096, RTA_GATEWAY, &addr.data, addr.bytelen); | |
730 | rtnh->rtnh_len += sizeof(struct rtattr) + addr.bytelen; | |
731 | } else { | |
732 | rta_addattr_l(rta, 4096, RTA_VIA, &addr.family, addr.bytelen+2); | |
733 | rtnh->rtnh_len += sizeof(struct rtattr) + addr.bytelen+2; | |
734 | } | |
aba5acdf SH |
735 | } else if (strcmp(*argv, "dev") == 0) { |
736 | NEXT_ARG(); | |
737 | if ((rtnh->rtnh_ifindex = ll_name_to_index(*argv)) == 0) { | |
738 | fprintf(stderr, "Cannot find device \"%s\"\n", *argv); | |
739 | exit(1); | |
740 | } | |
741 | } else if (strcmp(*argv, "weight") == 0) { | |
742 | unsigned w; | |
743 | NEXT_ARG(); | |
744 | if (get_unsigned(&w, *argv, 0) || w == 0 || w > 256) | |
745 | invarg("\"weight\" is invalid\n", *argv); | |
746 | rtnh->rtnh_hops = w - 1; | |
747 | } else if (strcmp(*argv, "onlink") == 0) { | |
748 | rtnh->rtnh_flags |= RTNH_F_ONLINK; | |
f4f6d640 PM |
749 | } else if (matches(*argv, "realms") == 0) { |
750 | __u32 realm; | |
751 | NEXT_ARG(); | |
752 | if (get_rt_realms(&realm, *argv)) | |
753 | invarg("\"realm\" value is invalid\n", *argv); | |
754 | rta_addattr32(rta, 4096, RTA_FLOW, realm); | |
755 | rtnh->rtnh_len += sizeof(struct rtattr) + 4; | |
aba5acdf SH |
756 | } else |
757 | break; | |
758 | } | |
759 | *argcp = argc; | |
760 | *argvp = argv; | |
761 | return 0; | |
762 | } | |
763 | ||
d1f28cf1 SH |
764 | static int parse_nexthops(struct nlmsghdr *n, struct rtmsg *r, |
765 | int argc, char **argv) | |
aba5acdf SH |
766 | { |
767 | char buf[1024]; | |
768 | struct rtattr *rta = (void*)buf; | |
769 | struct rtnexthop *rtnh; | |
770 | ||
771 | rta->rta_type = RTA_MULTIPATH; | |
772 | rta->rta_len = RTA_LENGTH(0); | |
773 | rtnh = RTA_DATA(rta); | |
774 | ||
775 | while (argc > 0) { | |
776 | if (strcmp(*argv, "nexthop") != 0) { | |
777 | fprintf(stderr, "Error: \"nexthop\" or end of line is expected instead of \"%s\"\n", *argv); | |
778 | exit(-1); | |
779 | } | |
780 | if (argc <= 1) { | |
781 | fprintf(stderr, "Error: unexpected end of line after \"nexthop\"\n"); | |
782 | exit(-1); | |
783 | } | |
784 | memset(rtnh, 0, sizeof(*rtnh)); | |
785 | rtnh->rtnh_len = sizeof(*rtnh); | |
786 | rta->rta_len += rtnh->rtnh_len; | |
4d6c3796 | 787 | parse_one_nh(r, rta, rtnh, &argc, &argv); |
aba5acdf SH |
788 | rtnh = RTNH_NEXT(rtnh); |
789 | } | |
790 | ||
791 | if (rta->rta_len > RTA_LENGTH(0)) | |
792 | addattr_l(n, 1024, RTA_MULTIPATH, RTA_DATA(rta), RTA_PAYLOAD(rta)); | |
793 | return 0; | |
794 | } | |
795 | ||
d1f28cf1 | 796 | static int iproute_modify(int cmd, unsigned flags, int argc, char **argv) |
aba5acdf | 797 | { |
aba5acdf | 798 | struct { |
4806867a SH |
799 | struct nlmsghdr n; |
800 | struct rtmsg r; | |
801 | char buf[1024]; | |
aba5acdf SH |
802 | } req; |
803 | char mxbuf[256]; | |
804 | struct rtattr * mxrta = (void*)mxbuf; | |
805 | unsigned mxlock = 0; | |
806 | char *d = NULL; | |
807 | int gw_ok = 0; | |
808 | int dst_ok = 0; | |
809 | int nhs_ok = 0; | |
810 | int scope_ok = 0; | |
811 | int table_ok = 0; | |
54e0b2e7 | 812 | int raw = 0; |
f638e9f7 | 813 | int type_ok = 0; |
aba5acdf SH |
814 | |
815 | memset(&req, 0, sizeof(req)); | |
816 | ||
817 | req.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct rtmsg)); | |
818 | req.n.nlmsg_flags = NLM_F_REQUEST|flags; | |
819 | req.n.nlmsg_type = cmd; | |
820 | req.r.rtm_family = preferred_family; | |
821 | req.r.rtm_table = RT_TABLE_MAIN; | |
822 | req.r.rtm_scope = RT_SCOPE_NOWHERE; | |
823 | ||
824 | if (cmd != RTM_DELROUTE) { | |
825 | req.r.rtm_protocol = RTPROT_BOOT; | |
826 | req.r.rtm_scope = RT_SCOPE_UNIVERSE; | |
827 | req.r.rtm_type = RTN_UNICAST; | |
828 | } | |
829 | ||
830 | mxrta->rta_type = RTA_METRICS; | |
831 | mxrta->rta_len = RTA_LENGTH(0); | |
832 | ||
833 | while (argc > 0) { | |
834 | if (strcmp(*argv, "src") == 0) { | |
835 | inet_prefix addr; | |
836 | NEXT_ARG(); | |
837 | get_addr(&addr, *argv, req.r.rtm_family); | |
838 | if (req.r.rtm_family == AF_UNSPEC) | |
839 | req.r.rtm_family = addr.family; | |
840 | addattr_l(&req.n, sizeof(req), RTA_PREFSRC, &addr.data, addr.bytelen); | |
6f7a9f4d EB |
841 | } else if (strcmp(*argv, "as") == 0) { |
842 | inet_prefix addr; | |
843 | NEXT_ARG(); | |
844 | if (strcmp(*argv, "to") == 0) { | |
845 | NEXT_ARG(); | |
846 | } | |
847 | get_addr(&addr, *argv, req.r.rtm_family); | |
848 | if (req.r.rtm_family == AF_UNSPEC) | |
849 | req.r.rtm_family = addr.family; | |
850 | addattr_l(&req.n, sizeof(req), RTA_NEWDST, &addr.data, addr.bytelen); | |
aba5acdf SH |
851 | } else if (strcmp(*argv, "via") == 0) { |
852 | inet_prefix addr; | |
93ae2835 | 853 | int family; |
aba5acdf SH |
854 | gw_ok = 1; |
855 | NEXT_ARG(); | |
93ae2835 EB |
856 | family = read_family(*argv); |
857 | if (family == AF_UNSPEC) | |
858 | family = req.r.rtm_family; | |
859 | else | |
860 | NEXT_ARG(); | |
861 | get_addr(&addr, *argv, family); | |
aba5acdf SH |
862 | if (req.r.rtm_family == AF_UNSPEC) |
863 | req.r.rtm_family = addr.family; | |
93ae2835 EB |
864 | if (addr.family == req.r.rtm_family) |
865 | addattr_l(&req.n, sizeof(req), RTA_GATEWAY, &addr.data, addr.bytelen); | |
866 | else | |
867 | addattr_l(&req.n, sizeof(req), RTA_VIA, &addr.family, addr.bytelen+2); | |
aba5acdf SH |
868 | } else if (strcmp(*argv, "from") == 0) { |
869 | inet_prefix addr; | |
870 | NEXT_ARG(); | |
871 | get_prefix(&addr, *argv, req.r.rtm_family); | |
872 | if (req.r.rtm_family == AF_UNSPEC) | |
873 | req.r.rtm_family = addr.family; | |
874 | if (addr.bytelen) | |
875 | addattr_l(&req.n, sizeof(req), RTA_SRC, &addr.data, addr.bytelen); | |
876 | req.r.rtm_src_len = addr.bitlen; | |
877 | } else if (strcmp(*argv, "tos") == 0 || | |
878 | matches(*argv, "dsfield") == 0) { | |
879 | __u32 tos; | |
880 | NEXT_ARG(); | |
881 | if (rtnl_dsfield_a2n(&tos, *argv)) | |
882 | invarg("\"tos\" value is invalid\n", *argv); | |
883 | req.r.rtm_tos = tos; | |
884 | } else if (matches(*argv, "metric") == 0 || | |
885 | matches(*argv, "priority") == 0 || | |
194e9b85 | 886 | strcmp(*argv, "preference") == 0) { |
aba5acdf SH |
887 | __u32 metric; |
888 | NEXT_ARG(); | |
889 | if (get_u32(&metric, *argv, 0)) | |
890 | invarg("\"metric\" value is invalid\n", *argv); | |
891 | addattr32(&req.n, sizeof(req), RTA_PRIORITY, metric); | |
892 | } else if (strcmp(*argv, "scope") == 0) { | |
f332d169 | 893 | __u32 scope = 0; |
aba5acdf SH |
894 | NEXT_ARG(); |
895 | if (rtnl_rtscope_a2n(&scope, *argv)) | |
896 | invarg("invalid \"scope\" value\n", *argv); | |
897 | req.r.rtm_scope = scope; | |
898 | scope_ok = 1; | |
899 | } else if (strcmp(*argv, "mtu") == 0) { | |
900 | unsigned mtu; | |
901 | NEXT_ARG(); | |
902 | if (strcmp(*argv, "lock") == 0) { | |
903 | mxlock |= (1<<RTAX_MTU); | |
904 | NEXT_ARG(); | |
905 | } | |
906 | if (get_unsigned(&mtu, *argv, 0)) | |
907 | invarg("\"mtu\" value is invalid\n", *argv); | |
908 | rta_addattr32(mxrta, sizeof(mxbuf), RTAX_MTU, mtu); | |
71e58151 GBY |
909 | } else if (strcmp(*argv, "hoplimit") == 0) { |
910 | unsigned hoplimit; | |
911 | NEXT_ARG(); | |
912 | if (strcmp(*argv, "lock") == 0) { | |
913 | mxlock |= (1<<RTAX_HOPLIMIT); | |
914 | NEXT_ARG(); | |
915 | } | |
916 | if (get_unsigned(&hoplimit, *argv, 0)) | |
917 | invarg("\"hoplimit\" value is invalid\n", *argv); | |
918 | rta_addattr32(mxrta, sizeof(mxbuf), RTAX_HOPLIMIT, hoplimit); | |
aba5acdf SH |
919 | } else if (strcmp(*argv, "advmss") == 0) { |
920 | unsigned mss; | |
921 | NEXT_ARG(); | |
922 | if (strcmp(*argv, "lock") == 0) { | |
923 | mxlock |= (1<<RTAX_ADVMSS); | |
924 | NEXT_ARG(); | |
925 | } | |
926 | if (get_unsigned(&mss, *argv, 0)) | |
927 | invarg("\"mss\" value is invalid\n", *argv); | |
928 | rta_addattr32(mxrta, sizeof(mxbuf), RTAX_ADVMSS, mss); | |
aba5acdf SH |
929 | } else if (matches(*argv, "reordering") == 0) { |
930 | unsigned reord; | |
931 | NEXT_ARG(); | |
932 | if (strcmp(*argv, "lock") == 0) { | |
933 | mxlock |= (1<<RTAX_REORDERING); | |
934 | NEXT_ARG(); | |
935 | } | |
936 | if (get_unsigned(&reord, *argv, 0)) | |
937 | invarg("\"reordering\" value is invalid\n", *argv); | |
938 | rta_addattr32(mxrta, sizeof(mxbuf), RTAX_REORDERING, reord); | |
aba5acdf SH |
939 | } else if (strcmp(*argv, "rtt") == 0) { |
940 | unsigned rtt; | |
941 | NEXT_ARG(); | |
942 | if (strcmp(*argv, "lock") == 0) { | |
943 | mxlock |= (1<<RTAX_RTT); | |
944 | NEXT_ARG(); | |
945 | } | |
81d03dc3 | 946 | if (get_time_rtt(&rtt, *argv, &raw)) |
aba5acdf | 947 | invarg("\"rtt\" value is invalid\n", *argv); |
0612519e | 948 | rta_addattr32(mxrta, sizeof(mxbuf), RTAX_RTT, |
54e0b2e7 RJ |
949 | (raw) ? rtt : rtt * 8); |
950 | } else if (strcmp(*argv, "rto_min") == 0) { | |
951 | unsigned rto_min; | |
952 | NEXT_ARG(); | |
953 | mxlock |= (1<<RTAX_RTO_MIN); | |
81d03dc3 | 954 | if (get_time_rtt(&rto_min, *argv, &raw)) |
54e0b2e7 RJ |
955 | invarg("\"rto_min\" value is invalid\n", |
956 | *argv); | |
957 | rta_addattr32(mxrta, sizeof(mxbuf), RTAX_RTO_MIN, | |
958 | rto_min); | |
aba5acdf SH |
959 | } else if (matches(*argv, "window") == 0) { |
960 | unsigned win; | |
961 | NEXT_ARG(); | |
962 | if (strcmp(*argv, "lock") == 0) { | |
963 | mxlock |= (1<<RTAX_WINDOW); | |
964 | NEXT_ARG(); | |
965 | } | |
966 | if (get_unsigned(&win, *argv, 0)) | |
967 | invarg("\"window\" value is invalid\n", *argv); | |
968 | rta_addattr32(mxrta, sizeof(mxbuf), RTAX_WINDOW, win); | |
969 | } else if (matches(*argv, "cwnd") == 0) { | |
970 | unsigned win; | |
971 | NEXT_ARG(); | |
972 | if (strcmp(*argv, "lock") == 0) { | |
973 | mxlock |= (1<<RTAX_CWND); | |
974 | NEXT_ARG(); | |
975 | } | |
976 | if (get_unsigned(&win, *argv, 0)) | |
977 | invarg("\"cwnd\" value is invalid\n", *argv); | |
978 | rta_addattr32(mxrta, sizeof(mxbuf), RTAX_CWND, win); | |
a1f1143e VW |
979 | } else if (matches(*argv, "initcwnd") == 0) { |
980 | unsigned win; | |
981 | NEXT_ARG(); | |
982 | if (strcmp(*argv, "lock") == 0) { | |
983 | mxlock |= (1<<RTAX_INITCWND); | |
984 | NEXT_ARG(); | |
985 | } | |
986 | if (get_unsigned(&win, *argv, 0)) | |
987 | invarg("\"initcwnd\" value is invalid\n", *argv); | |
988 | rta_addattr32(mxrta, sizeof(mxbuf), RTAX_INITCWND, win); | |
f5fd8003 | 989 | } else if (matches(*argv, "initrwnd") == 0) { |
990 | unsigned win; | |
991 | NEXT_ARG(); | |
992 | if (strcmp(*argv, "lock") == 0) { | |
993 | mxlock |= (1<<RTAX_INITRWND); | |
994 | NEXT_ARG(); | |
995 | } | |
996 | if (get_unsigned(&win, *argv, 0)) | |
997 | invarg("\"initrwnd\" value is invalid\n", *argv); | |
998 | rta_addattr32(mxrta, sizeof(mxbuf), RTAX_INITRWND, win); | |
29d1f730 FW |
999 | } else if (matches(*argv, "features") == 0) { |
1000 | unsigned int features = 0; | |
1001 | ||
1002 | while (argc > 0) { | |
1003 | NEXT_ARG(); | |
1004 | ||
1005 | if (strcmp(*argv, "ecn") == 0) | |
1006 | features |= RTAX_FEATURE_ECN; | |
1007 | else | |
1008 | invarg("\"features\" value not valid\n", *argv); | |
1009 | break; | |
1010 | } | |
1011 | ||
1012 | rta_addattr32(mxrta, sizeof(mxbuf), RTAX_FEATURES, features); | |
b37f2c89 CW |
1013 | } else if (matches(*argv, "quickack") == 0) { |
1014 | unsigned quickack; | |
1015 | NEXT_ARG(); | |
1016 | if (get_unsigned(&quickack, *argv, 0)) | |
1017 | invarg("\"quickack\" value is invalid\n", *argv); | |
1018 | if (quickack != 1 && quickack != 0) | |
1019 | invarg("\"quickack\" value should be 0 or 1\n", *argv); | |
1020 | rta_addattr32(mxrta, sizeof(mxbuf), RTAX_QUICKACK, quickack); | |
6ef87f9c DB |
1021 | } else if (matches(*argv, "congctl") == 0) { |
1022 | NEXT_ARG(); | |
1023 | if (strcmp(*argv, "lock") == 0) { | |
1024 | mxlock |= 1 << RTAX_CC_ALGO; | |
1025 | NEXT_ARG(); | |
1026 | } | |
1027 | rta_addattr_l(mxrta, sizeof(mxbuf), RTAX_CC_ALGO, *argv, | |
1028 | strlen(*argv)); | |
aba5acdf SH |
1029 | } else if (matches(*argv, "rttvar") == 0) { |
1030 | unsigned win; | |
1031 | NEXT_ARG(); | |
1032 | if (strcmp(*argv, "lock") == 0) { | |
1033 | mxlock |= (1<<RTAX_RTTVAR); | |
1034 | NEXT_ARG(); | |
1035 | } | |
81d03dc3 | 1036 | if (get_time_rtt(&win, *argv, &raw)) |
aba5acdf | 1037 | invarg("\"rttvar\" value is invalid\n", *argv); |
54e0b2e7 RJ |
1038 | rta_addattr32(mxrta, sizeof(mxbuf), RTAX_RTTVAR, |
1039 | (raw) ? win : win * 4); | |
aba5acdf SH |
1040 | } else if (matches(*argv, "ssthresh") == 0) { |
1041 | unsigned win; | |
1042 | NEXT_ARG(); | |
1043 | if (strcmp(*argv, "lock") == 0) { | |
1044 | mxlock |= (1<<RTAX_SSTHRESH); | |
1045 | NEXT_ARG(); | |
1046 | } | |
1047 | if (get_unsigned(&win, *argv, 0)) | |
1048 | invarg("\"ssthresh\" value is invalid\n", *argv); | |
1049 | rta_addattr32(mxrta, sizeof(mxbuf), RTAX_SSTHRESH, win); | |
1050 | } else if (matches(*argv, "realms") == 0) { | |
1051 | __u32 realm; | |
1052 | NEXT_ARG(); | |
1053 | if (get_rt_realms(&realm, *argv)) | |
1054 | invarg("\"realm\" value is invalid\n", *argv); | |
1055 | addattr32(&req.n, sizeof(req), RTA_FLOW, realm); | |
1056 | } else if (strcmp(*argv, "onlink") == 0) { | |
1057 | req.r.rtm_flags |= RTNH_F_ONLINK; | |
aba5acdf SH |
1058 | } else if (strcmp(*argv, "nexthop") == 0) { |
1059 | nhs_ok = 1; | |
1060 | break; | |
1061 | } else if (matches(*argv, "protocol") == 0) { | |
f332d169 | 1062 | __u32 prot; |
aba5acdf SH |
1063 | NEXT_ARG(); |
1064 | if (rtnl_rtprot_a2n(&prot, *argv)) | |
1065 | invarg("\"protocol\" value is invalid\n", *argv); | |
1066 | req.r.rtm_protocol = prot; | |
aba5acdf | 1067 | } else if (matches(*argv, "table") == 0) { |
f332d169 | 1068 | __u32 tid; |
aba5acdf SH |
1069 | NEXT_ARG(); |
1070 | if (rtnl_rttable_a2n(&tid, *argv)) | |
1071 | invarg("\"table\" value is invalid\n", *argv); | |
34e95647 PM |
1072 | if (tid < 256) |
1073 | req.r.rtm_table = tid; | |
1074 | else { | |
1075 | req.r.rtm_table = RT_TABLE_UNSPEC; | |
1076 | addattr32(&req.n, sizeof(req), RTA_TABLE, tid); | |
1077 | } | |
aba5acdf SH |
1078 | table_ok = 1; |
1079 | } else if (strcmp(*argv, "dev") == 0 || | |
1080 | strcmp(*argv, "oif") == 0) { | |
1081 | NEXT_ARG(); | |
1082 | d = *argv; | |
194e9b85 LR |
1083 | } else if (matches(*argv, "pref") == 0) { |
1084 | __u8 pref; | |
1085 | NEXT_ARG(); | |
1086 | if (strcmp(*argv, "low") == 0) | |
1087 | pref = ICMPV6_ROUTER_PREF_LOW; | |
1088 | else if (strcmp(*argv, "medium") == 0) | |
1089 | pref = ICMPV6_ROUTER_PREF_MEDIUM; | |
1090 | else if (strcmp(*argv, "high") == 0) | |
1091 | pref = ICMPV6_ROUTER_PREF_HIGH; | |
1092 | else if (get_u8(&pref, *argv, 0)) | |
1093 | invarg("\"pref\" value is invalid\n", *argv); | |
1094 | addattr8(&req.n, sizeof(req), RTA_PREF, pref); | |
aba5acdf SH |
1095 | } else { |
1096 | int type; | |
1097 | inet_prefix dst; | |
1098 | ||
1099 | if (strcmp(*argv, "to") == 0) { | |
1100 | NEXT_ARG(); | |
1101 | } | |
1102 | if ((**argv < '0' || **argv > '9') && | |
1103 | rtnl_rtntype_a2n(&type, *argv) == 0) { | |
1104 | NEXT_ARG(); | |
1105 | req.r.rtm_type = type; | |
f638e9f7 | 1106 | type_ok = 1; |
aba5acdf SH |
1107 | } |
1108 | ||
1109 | if (matches(*argv, "help") == 0) | |
1110 | usage(); | |
1111 | if (dst_ok) | |
1112 | duparg2("to", *argv); | |
1113 | get_prefix(&dst, *argv, req.r.rtm_family); | |
1114 | if (req.r.rtm_family == AF_UNSPEC) | |
1115 | req.r.rtm_family = dst.family; | |
1116 | req.r.rtm_dst_len = dst.bitlen; | |
1117 | dst_ok = 1; | |
1118 | if (dst.bytelen) | |
1119 | addattr_l(&req.n, sizeof(req), RTA_DST, &dst.data, dst.bytelen); | |
1120 | } | |
1121 | argc--; argv++; | |
1122 | } | |
1123 | ||
922b4822 PS |
1124 | if (!dst_ok) |
1125 | usage(); | |
1126 | ||
aba5acdf SH |
1127 | if (d || nhs_ok) { |
1128 | int idx; | |
1129 | ||
aba5acdf SH |
1130 | if (d) { |
1131 | if ((idx = ll_name_to_index(d)) == 0) { | |
1132 | fprintf(stderr, "Cannot find device \"%s\"\n", d); | |
1133 | return -1; | |
1134 | } | |
1135 | addattr32(&req.n, sizeof(req), RTA_OIF, idx); | |
1136 | } | |
1137 | } | |
1138 | ||
1139 | if (mxrta->rta_len > RTA_LENGTH(0)) { | |
1140 | if (mxlock) | |
1141 | rta_addattr32(mxrta, sizeof(mxbuf), RTAX_LOCK, mxlock); | |
1142 | addattr_l(&req.n, sizeof(req), RTA_METRICS, RTA_DATA(mxrta), RTA_PAYLOAD(mxrta)); | |
1143 | } | |
1144 | ||
1145 | if (nhs_ok) | |
1146 | parse_nexthops(&req.n, &req.r, argc, argv); | |
1147 | ||
f638e9f7 RP |
1148 | if (req.r.rtm_family == AF_UNSPEC) |
1149 | req.r.rtm_family = AF_INET; | |
1150 | ||
aba5acdf SH |
1151 | if (!table_ok) { |
1152 | if (req.r.rtm_type == RTN_LOCAL || | |
1153 | req.r.rtm_type == RTN_BROADCAST || | |
1154 | req.r.rtm_type == RTN_NAT || | |
1155 | req.r.rtm_type == RTN_ANYCAST) | |
1156 | req.r.rtm_table = RT_TABLE_LOCAL; | |
1157 | } | |
1158 | if (!scope_ok) { | |
f638e9f7 RP |
1159 | if (req.r.rtm_family == AF_INET6 || |
1160 | req.r.rtm_family == AF_MPLS) | |
1161 | req.r.rtm_scope = RT_SCOPE_UNIVERSE; | |
1162 | else if (req.r.rtm_type == RTN_LOCAL || | |
1163 | req.r.rtm_type == RTN_NAT) | |
aba5acdf SH |
1164 | req.r.rtm_scope = RT_SCOPE_HOST; |
1165 | else if (req.r.rtm_type == RTN_BROADCAST || | |
1166 | req.r.rtm_type == RTN_MULTICAST || | |
1167 | req.r.rtm_type == RTN_ANYCAST) | |
1168 | req.r.rtm_scope = RT_SCOPE_LINK; | |
1169 | else if (req.r.rtm_type == RTN_UNICAST || | |
1170 | req.r.rtm_type == RTN_UNSPEC) { | |
1171 | if (cmd == RTM_DELROUTE) | |
1172 | req.r.rtm_scope = RT_SCOPE_NOWHERE; | |
1173 | else if (!gw_ok && !nhs_ok) | |
1174 | req.r.rtm_scope = RT_SCOPE_LINK; | |
1175 | } | |
1176 | } | |
1177 | ||
f638e9f7 RP |
1178 | if (!type_ok && req.r.rtm_family == AF_MPLS) |
1179 | req.r.rtm_type = RTN_UNICAST; | |
aba5acdf | 1180 | |
c079e121 | 1181 | if (rtnl_talk(&rth, &req.n, NULL, 0) < 0) |
d58ba4ba | 1182 | return -2; |
aba5acdf SH |
1183 | |
1184 | return 0; | |
1185 | } | |
1186 | ||
1187 | static int rtnl_rtcache_request(struct rtnl_handle *rth, int family) | |
1188 | { | |
1189 | struct { | |
1190 | struct nlmsghdr nlh; | |
1191 | struct rtmsg rtm; | |
1192 | } req; | |
1193 | struct sockaddr_nl nladdr; | |
1194 | ||
1195 | memset(&nladdr, 0, sizeof(nladdr)); | |
1196 | memset(&req, 0, sizeof(req)); | |
1197 | nladdr.nl_family = AF_NETLINK; | |
1198 | ||
1199 | req.nlh.nlmsg_len = sizeof(req); | |
1200 | req.nlh.nlmsg_type = RTM_GETROUTE; | |
1201 | req.nlh.nlmsg_flags = NLM_F_ROOT|NLM_F_REQUEST; | |
1202 | req.nlh.nlmsg_pid = 0; | |
1203 | req.nlh.nlmsg_seq = rth->dump = ++rth->seq; | |
1204 | req.rtm.rtm_family = family; | |
1205 | req.rtm.rtm_flags |= RTM_F_CLONED; | |
1206 | ||
1207 | return sendto(rth->fd, (void*)&req, sizeof(req), 0, (struct sockaddr*)&nladdr, sizeof(nladdr)); | |
1208 | } | |
1209 | ||
1210 | static int iproute_flush_cache(void) | |
1211 | { | |
1212 | #define ROUTE_FLUSH_PATH "/proc/sys/net/ipv4/route/flush" | |
1213 | ||
1214 | int len; | |
1215 | int flush_fd = open (ROUTE_FLUSH_PATH, O_WRONLY); | |
1216 | char *buffer = "-1"; | |
1217 | ||
1218 | if (flush_fd < 0) { | |
9827fa57 DK |
1219 | fprintf (stderr, "Cannot open \"%s\": %s\n", |
1220 | ROUTE_FLUSH_PATH, strerror(errno)); | |
aba5acdf SH |
1221 | return -1; |
1222 | } | |
1223 | ||
1224 | len = strlen (buffer); | |
ae665a52 | 1225 | |
aba5acdf SH |
1226 | if ((write (flush_fd, (void *)buffer, len)) < len) { |
1227 | fprintf (stderr, "Cannot flush routing cache\n"); | |
25352af7 | 1228 | close(flush_fd); |
aba5acdf SH |
1229 | return -1; |
1230 | } | |
1231 | close(flush_fd); | |
1232 | return 0; | |
1233 | } | |
1234 | ||
76c61b34 PE |
1235 | static __u32 route_dump_magic = 0x45311224; |
1236 | ||
d1f28cf1 SH |
1237 | static int save_route(const struct sockaddr_nl *who, struct nlmsghdr *n, |
1238 | void *arg) | |
f4ff11e3 DS |
1239 | { |
1240 | int ret; | |
1241 | int len = n->nlmsg_len; | |
1242 | struct rtmsg *r = NLMSG_DATA(n); | |
1243 | struct rtattr *tb[RTA_MAX+1]; | |
f3a2ddc1 | 1244 | int host_len; |
f4ff11e3 | 1245 | |
f3a2ddc1 | 1246 | host_len = af_bit_len(r->rtm_family); |
f4ff11e3 DS |
1247 | len -= NLMSG_LENGTH(sizeof(*r)); |
1248 | parse_rtattr(tb, RTA_MAX, RTM_RTA(r), len); | |
1249 | ||
1250 | if (!filter_nlmsg(n, tb, host_len)) | |
1251 | return 0; | |
1252 | ||
1253 | ret = write(STDOUT_FILENO, n, n->nlmsg_len); | |
1254 | if ((ret > 0) && (ret != n->nlmsg_len)) { | |
1255 | fprintf(stderr, "Short write while saving nlmsg\n"); | |
1256 | ret = -EIO; | |
1257 | } | |
1258 | ||
1259 | return ret == n->nlmsg_len ? 0 : ret; | |
1260 | } | |
aba5acdf | 1261 | |
76c61b34 PE |
1262 | static int save_route_prep(void) |
1263 | { | |
1264 | int ret; | |
1265 | ||
1266 | if (isatty(STDOUT_FILENO)) { | |
14645ec2 | 1267 | fprintf(stderr, "Not sending a binary stream to stdout\n"); |
76c61b34 PE |
1268 | return -1; |
1269 | } | |
1270 | ||
1271 | ret = write(STDOUT_FILENO, &route_dump_magic, sizeof(route_dump_magic)); | |
1272 | if (ret != sizeof(route_dump_magic)) { | |
1273 | fprintf(stderr, "Can't write magic to dump file\n"); | |
1274 | return -1; | |
1275 | } | |
1276 | ||
1277 | return 0; | |
1278 | } | |
1279 | ||
f4ff11e3 | 1280 | static int iproute_list_flush_or_save(int argc, char **argv, int action) |
aba5acdf SH |
1281 | { |
1282 | int do_ipv6 = preferred_family; | |
aba5acdf SH |
1283 | char *id = NULL; |
1284 | char *od = NULL; | |
b0373bfb | 1285 | unsigned int mark = 0; |
f4ff11e3 DS |
1286 | rtnl_filter_t filter_fn; |
1287 | ||
76c61b34 PE |
1288 | if (action == IPROUTE_SAVE) { |
1289 | if (save_route_prep()) | |
1290 | return -1; | |
1291 | ||
f4ff11e3 | 1292 | filter_fn = save_route; |
76c61b34 | 1293 | } else |
f4ff11e3 | 1294 | filter_fn = print_route; |
aba5acdf | 1295 | |
093b7646 | 1296 | iproute_reset_filter(0); |
aba5acdf SH |
1297 | filter.tb = RT_TABLE_MAIN; |
1298 | ||
f4ff11e3 | 1299 | if ((action == IPROUTE_FLUSH) && argc <= 0) { |
aba5acdf SH |
1300 | fprintf(stderr, "\"ip route flush\" requires arguments.\n"); |
1301 | return -1; | |
1302 | } | |
1303 | ||
1304 | while (argc > 0) { | |
1305 | if (matches(*argv, "table") == 0) { | |
f332d169 | 1306 | __u32 tid; |
aba5acdf SH |
1307 | NEXT_ARG(); |
1308 | if (rtnl_rttable_a2n(&tid, *argv)) { | |
1309 | if (strcmp(*argv, "all") == 0) { | |
bd4bcdad | 1310 | filter.tb = 0; |
aba5acdf | 1311 | } else if (strcmp(*argv, "cache") == 0) { |
bd4bcdad | 1312 | filter.cloned = 1; |
aba5acdf SH |
1313 | } else if (strcmp(*argv, "help") == 0) { |
1314 | usage(); | |
1315 | } else { | |
1316 | invarg("table id value is invalid\n", *argv); | |
1317 | } | |
bd4bcdad PM |
1318 | } else |
1319 | filter.tb = tid; | |
aba5acdf SH |
1320 | } else if (matches(*argv, "cached") == 0 || |
1321 | matches(*argv, "cloned") == 0) { | |
bd4bcdad | 1322 | filter.cloned = 1; |
aba5acdf SH |
1323 | } else if (strcmp(*argv, "tos") == 0 || |
1324 | matches(*argv, "dsfield") == 0) { | |
1325 | __u32 tos; | |
1326 | NEXT_ARG(); | |
1327 | if (rtnl_dsfield_a2n(&tos, *argv)) | |
1328 | invarg("TOS value is invalid\n", *argv); | |
1329 | filter.tos = tos; | |
1330 | filter.tosmask = -1; | |
1331 | } else if (matches(*argv, "protocol") == 0) { | |
f332d169 | 1332 | __u32 prot = 0; |
aba5acdf SH |
1333 | NEXT_ARG(); |
1334 | filter.protocolmask = -1; | |
1335 | if (rtnl_rtprot_a2n(&prot, *argv)) { | |
1336 | if (strcmp(*argv, "all") != 0) | |
1337 | invarg("invalid \"protocol\"\n", *argv); | |
1338 | prot = 0; | |
1339 | filter.protocolmask = 0; | |
1340 | } | |
1341 | filter.protocol = prot; | |
1342 | } else if (matches(*argv, "scope") == 0) { | |
f332d169 | 1343 | __u32 scope = 0; |
aba5acdf SH |
1344 | NEXT_ARG(); |
1345 | filter.scopemask = -1; | |
1346 | if (rtnl_rtscope_a2n(&scope, *argv)) { | |
1347 | if (strcmp(*argv, "all") != 0) | |
1348 | invarg("invalid \"scope\"\n", *argv); | |
1349 | scope = RT_SCOPE_NOWHERE; | |
1350 | filter.scopemask = 0; | |
1351 | } | |
1352 | filter.scope = scope; | |
1353 | } else if (matches(*argv, "type") == 0) { | |
1354 | int type; | |
1355 | NEXT_ARG(); | |
1356 | filter.typemask = -1; | |
1357 | if (rtnl_rtntype_a2n(&type, *argv)) | |
1358 | invarg("node type value is invalid\n", *argv); | |
1359 | filter.type = type; | |
1360 | } else if (strcmp(*argv, "dev") == 0 || | |
1361 | strcmp(*argv, "oif") == 0) { | |
1362 | NEXT_ARG(); | |
1363 | od = *argv; | |
1364 | } else if (strcmp(*argv, "iif") == 0) { | |
1365 | NEXT_ARG(); | |
1366 | id = *argv; | |
b0373bfb ED |
1367 | } else if (strcmp(*argv, "mark") == 0) { |
1368 | NEXT_ARG(); | |
1369 | get_unsigned(&mark, *argv, 0); | |
1370 | filter.markmask = -1; | |
aba5acdf | 1371 | } else if (strcmp(*argv, "via") == 0) { |
93ae2835 | 1372 | int family; |
aba5acdf | 1373 | NEXT_ARG(); |
93ae2835 EB |
1374 | family = read_family(*argv); |
1375 | if (family == AF_UNSPEC) | |
1376 | family = do_ipv6; | |
1377 | else | |
1378 | NEXT_ARG(); | |
1379 | get_prefix(&filter.rvia, *argv, family); | |
aba5acdf SH |
1380 | } else if (strcmp(*argv, "src") == 0) { |
1381 | NEXT_ARG(); | |
1382 | get_prefix(&filter.rprefsrc, *argv, do_ipv6); | |
1383 | } else if (matches(*argv, "realms") == 0) { | |
1384 | __u32 realm; | |
1385 | NEXT_ARG(); | |
1386 | if (get_rt_realms(&realm, *argv)) | |
1387 | invarg("invalid realms\n", *argv); | |
1388 | filter.realm = realm; | |
1389 | filter.realmmask = ~0U; | |
1390 | if ((filter.realm&0xFFFF) == 0 && | |
1391 | (*argv)[strlen(*argv) - 1] == '/') | |
1392 | filter.realmmask &= ~0xFFFF; | |
1393 | if ((filter.realm&0xFFFF0000U) == 0 && | |
1394 | (strchr(*argv, '/') == NULL || | |
1395 | (*argv)[0] == '/')) | |
1396 | filter.realmmask &= ~0xFFFF0000U; | |
1397 | } else if (matches(*argv, "from") == 0) { | |
1398 | NEXT_ARG(); | |
1399 | if (matches(*argv, "root") == 0) { | |
1400 | NEXT_ARG(); | |
1401 | get_prefix(&filter.rsrc, *argv, do_ipv6); | |
1402 | } else if (matches(*argv, "match") == 0) { | |
1403 | NEXT_ARG(); | |
1404 | get_prefix(&filter.msrc, *argv, do_ipv6); | |
1405 | } else { | |
1406 | if (matches(*argv, "exact") == 0) { | |
1407 | NEXT_ARG(); | |
1408 | } | |
1409 | get_prefix(&filter.msrc, *argv, do_ipv6); | |
1410 | filter.rsrc = filter.msrc; | |
1411 | } | |
1412 | } else { | |
1413 | if (matches(*argv, "to") == 0) { | |
1414 | NEXT_ARG(); | |
1415 | } | |
1416 | if (matches(*argv, "root") == 0) { | |
1417 | NEXT_ARG(); | |
1418 | get_prefix(&filter.rdst, *argv, do_ipv6); | |
1419 | } else if (matches(*argv, "match") == 0) { | |
1420 | NEXT_ARG(); | |
1421 | get_prefix(&filter.mdst, *argv, do_ipv6); | |
1422 | } else { | |
1423 | if (matches(*argv, "exact") == 0) { | |
1424 | NEXT_ARG(); | |
1425 | } | |
1426 | get_prefix(&filter.mdst, *argv, do_ipv6); | |
1427 | filter.rdst = filter.mdst; | |
1428 | } | |
1429 | } | |
1430 | argc--; argv++; | |
1431 | } | |
1432 | ||
1433 | if (do_ipv6 == AF_UNSPEC && filter.tb) | |
1434 | do_ipv6 = AF_INET; | |
1435 | ||
aba5acdf SH |
1436 | if (id || od) { |
1437 | int idx; | |
1438 | ||
1439 | if (id) { | |
1440 | if ((idx = ll_name_to_index(id)) == 0) { | |
1441 | fprintf(stderr, "Cannot find device \"%s\"\n", id); | |
1442 | return -1; | |
1443 | } | |
1444 | filter.iif = idx; | |
1445 | filter.iifmask = -1; | |
1446 | } | |
1447 | if (od) { | |
1448 | if ((idx = ll_name_to_index(od)) == 0) { | |
1449 | fprintf(stderr, "Cannot find device \"%s\"\n", od); | |
1450 | return -1; | |
1451 | } | |
1452 | filter.oif = idx; | |
1453 | filter.oifmask = -1; | |
1454 | } | |
1455 | } | |
b0373bfb | 1456 | filter.mark = mark; |
aba5acdf | 1457 | |
f4ff11e3 | 1458 | if (action == IPROUTE_FLUSH) { |
aba5acdf SH |
1459 | int round = 0; |
1460 | char flushb[4096-512]; | |
33551240 | 1461 | time_t start = time(0); |
aba5acdf | 1462 | |
bd4bcdad | 1463 | if (filter.cloned) { |
aba5acdf SH |
1464 | if (do_ipv6 != AF_INET6) { |
1465 | iproute_flush_cache(); | |
1466 | if (show_stats) | |
1467 | printf("*** IPv4 routing cache is flushed.\n"); | |
1468 | } | |
1469 | if (do_ipv6 == AF_INET) | |
1470 | return 0; | |
1471 | } | |
1472 | ||
1473 | filter.flushb = flushb; | |
1474 | filter.flushp = 0; | |
1475 | filter.flushe = sizeof(flushb); | |
aba5acdf SH |
1476 | |
1477 | for (;;) { | |
1478 | if (rtnl_wilddump_request(&rth, do_ipv6, RTM_GETROUTE) < 0) { | |
1479 | perror("Cannot send dump request"); | |
1480 | exit(1); | |
1481 | } | |
1482 | filter.flushed = 0; | |
cd70f3f5 | 1483 | if (rtnl_dump_filter(&rth, filter_fn, stdout) < 0) { |
aba5acdf SH |
1484 | fprintf(stderr, "Flush terminated\n"); |
1485 | exit(1); | |
1486 | } | |
1487 | if (filter.flushed == 0) { | |
f0b34d2d AH |
1488 | if (show_stats) { |
1489 | if (round == 0 && (!filter.cloned || do_ipv6 == AF_INET6)) | |
1490 | printf("Nothing to flush.\n"); | |
1491 | else | |
1492 | printf("*** Flush is complete after %d round%s ***\n", round, round>1?"s":""); | |
1493 | } | |
aba5acdf SH |
1494 | fflush(stdout); |
1495 | return 0; | |
1496 | } | |
1497 | round++; | |
1498 | if (flush_update() < 0) | |
1499 | exit(1); | |
33551240 SH |
1500 | |
1501 | if (time(0) - start > 30) { | |
1502 | printf("\n*** Flush not completed after %ld seconds, %d entries remain ***\n", | |
5d8a7529 | 1503 | (long)(time(0) - start), filter.flushed); |
33551240 SH |
1504 | exit(1); |
1505 | } | |
1506 | ||
aba5acdf SH |
1507 | if (show_stats) { |
1508 | printf("\n*** Round %d, deleting %d entries ***\n", round, filter.flushed); | |
1509 | fflush(stdout); | |
1510 | } | |
1511 | } | |
1512 | } | |
1513 | ||
bd4bcdad | 1514 | if (!filter.cloned) { |
aba5acdf SH |
1515 | if (rtnl_wilddump_request(&rth, do_ipv6, RTM_GETROUTE) < 0) { |
1516 | perror("Cannot send dump request"); | |
1517 | exit(1); | |
1518 | } | |
1519 | } else { | |
1520 | if (rtnl_rtcache_request(&rth, do_ipv6) < 0) { | |
1521 | perror("Cannot send dump request"); | |
1522 | exit(1); | |
1523 | } | |
1524 | } | |
1525 | ||
cd70f3f5 | 1526 | if (rtnl_dump_filter(&rth, filter_fn, stdout) < 0) { |
aba5acdf SH |
1527 | fprintf(stderr, "Dump terminated\n"); |
1528 | exit(1); | |
1529 | } | |
1530 | ||
1531 | exit(0); | |
1532 | } | |
1533 | ||
1534 | ||
d1f28cf1 | 1535 | static int iproute_get(int argc, char **argv) |
aba5acdf | 1536 | { |
aba5acdf | 1537 | struct { |
4806867a SH |
1538 | struct nlmsghdr n; |
1539 | struct rtmsg r; | |
1540 | char buf[1024]; | |
aba5acdf SH |
1541 | } req; |
1542 | char *idev = NULL; | |
1543 | char *odev = NULL; | |
1544 | int connected = 0; | |
1545 | int from_ok = 0; | |
b0373bfb | 1546 | unsigned int mark = 0; |
aba5acdf SH |
1547 | |
1548 | memset(&req, 0, sizeof(req)); | |
1549 | ||
093b7646 | 1550 | iproute_reset_filter(0); |
c73f3e02 | 1551 | filter.cloned = 2; |
aba5acdf SH |
1552 | |
1553 | req.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct rtmsg)); | |
1554 | req.n.nlmsg_flags = NLM_F_REQUEST; | |
1555 | req.n.nlmsg_type = RTM_GETROUTE; | |
1556 | req.r.rtm_family = preferred_family; | |
1557 | req.r.rtm_table = 0; | |
1558 | req.r.rtm_protocol = 0; | |
1559 | req.r.rtm_scope = 0; | |
1560 | req.r.rtm_type = 0; | |
1561 | req.r.rtm_src_len = 0; | |
1562 | req.r.rtm_dst_len = 0; | |
1563 | req.r.rtm_tos = 0; | |
ae665a52 | 1564 | |
aba5acdf SH |
1565 | while (argc > 0) { |
1566 | if (strcmp(*argv, "tos") == 0 || | |
1567 | matches(*argv, "dsfield") == 0) { | |
1568 | __u32 tos; | |
1569 | NEXT_ARG(); | |
1570 | if (rtnl_dsfield_a2n(&tos, *argv)) | |
1571 | invarg("TOS value is invalid\n", *argv); | |
1572 | req.r.rtm_tos = tos; | |
1573 | } else if (matches(*argv, "from") == 0) { | |
1574 | inet_prefix addr; | |
1575 | NEXT_ARG(); | |
1576 | if (matches(*argv, "help") == 0) | |
1577 | usage(); | |
1578 | from_ok = 1; | |
1579 | get_prefix(&addr, *argv, req.r.rtm_family); | |
1580 | if (req.r.rtm_family == AF_UNSPEC) | |
1581 | req.r.rtm_family = addr.family; | |
1582 | if (addr.bytelen) | |
1583 | addattr_l(&req.n, sizeof(req), RTA_SRC, &addr.data, addr.bytelen); | |
1584 | req.r.rtm_src_len = addr.bitlen; | |
1585 | } else if (matches(*argv, "iif") == 0) { | |
1586 | NEXT_ARG(); | |
1587 | idev = *argv; | |
b0373bfb ED |
1588 | } else if (matches(*argv, "mark") == 0) { |
1589 | NEXT_ARG(); | |
1590 | get_unsigned(&mark, *argv, 0); | |
aba5acdf SH |
1591 | } else if (matches(*argv, "oif") == 0 || |
1592 | strcmp(*argv, "dev") == 0) { | |
1593 | NEXT_ARG(); | |
1594 | odev = *argv; | |
1595 | } else if (matches(*argv, "notify") == 0) { | |
1596 | req.r.rtm_flags |= RTM_F_NOTIFY; | |
1597 | } else if (matches(*argv, "connected") == 0) { | |
1598 | connected = 1; | |
1599 | } else { | |
1600 | inet_prefix addr; | |
1601 | if (strcmp(*argv, "to") == 0) { | |
1602 | NEXT_ARG(); | |
1603 | } | |
1604 | if (matches(*argv, "help") == 0) | |
1605 | usage(); | |
1606 | get_prefix(&addr, *argv, req.r.rtm_family); | |
1607 | if (req.r.rtm_family == AF_UNSPEC) | |
1608 | req.r.rtm_family = addr.family; | |
1609 | if (addr.bytelen) | |
1610 | addattr_l(&req.n, sizeof(req), RTA_DST, &addr.data, addr.bytelen); | |
1611 | req.r.rtm_dst_len = addr.bitlen; | |
1612 | } | |
1613 | argc--; argv++; | |
1614 | } | |
1615 | ||
1616 | if (req.r.rtm_dst_len == 0) { | |
14645ec2 | 1617 | fprintf(stderr, "need at least a destination address\n"); |
aba5acdf SH |
1618 | exit(1); |
1619 | } | |
1620 | ||
aba5acdf SH |
1621 | if (idev || odev) { |
1622 | int idx; | |
1623 | ||
1624 | if (idev) { | |
1625 | if ((idx = ll_name_to_index(idev)) == 0) { | |
1626 | fprintf(stderr, "Cannot find device \"%s\"\n", idev); | |
1627 | return -1; | |
1628 | } | |
1629 | addattr32(&req.n, sizeof(req), RTA_IIF, idx); | |
1630 | } | |
1631 | if (odev) { | |
1632 | if ((idx = ll_name_to_index(odev)) == 0) { | |
1633 | fprintf(stderr, "Cannot find device \"%s\"\n", odev); | |
1634 | return -1; | |
1635 | } | |
1636 | addattr32(&req.n, sizeof(req), RTA_OIF, idx); | |
1637 | } | |
1638 | } | |
b0373bfb ED |
1639 | if (mark) |
1640 | addattr32(&req.n, sizeof(req), RTA_MARK, mark); | |
aba5acdf SH |
1641 | |
1642 | if (req.r.rtm_family == AF_UNSPEC) | |
1643 | req.r.rtm_family = AF_INET; | |
1644 | ||
c079e121 | 1645 | if (rtnl_talk(&rth, &req.n, &req.n, sizeof(req)) < 0) |
8b21cef1 | 1646 | return -2; |
aba5acdf SH |
1647 | |
1648 | if (connected && !from_ok) { | |
1649 | struct rtmsg *r = NLMSG_DATA(&req.n); | |
1650 | int len = req.n.nlmsg_len; | |
1651 | struct rtattr * tb[RTA_MAX+1]; | |
1652 | ||
1653 | if (print_route(NULL, &req.n, (void*)stdout) < 0) { | |
1654 | fprintf(stderr, "An error :-)\n"); | |
1655 | exit(1); | |
1656 | } | |
1657 | ||
1658 | if (req.n.nlmsg_type != RTM_NEWROUTE) { | |
1659 | fprintf(stderr, "Not a route?\n"); | |
1660 | return -1; | |
1661 | } | |
1662 | len -= NLMSG_LENGTH(sizeof(*r)); | |
1663 | if (len < 0) { | |
1664 | fprintf(stderr, "Wrong len %d\n", len); | |
1665 | return -1; | |
1666 | } | |
1667 | ||
aba5acdf SH |
1668 | parse_rtattr(tb, RTA_MAX, RTM_RTA(r), len); |
1669 | ||
1670 | if (tb[RTA_PREFSRC]) { | |
1671 | tb[RTA_PREFSRC]->rta_type = RTA_SRC; | |
1672 | r->rtm_src_len = 8*RTA_PAYLOAD(tb[RTA_PREFSRC]); | |
1673 | } else if (!tb[RTA_SRC]) { | |
1674 | fprintf(stderr, "Failed to connect the route\n"); | |
1675 | return -1; | |
1676 | } | |
1677 | if (!odev && tb[RTA_OIF]) | |
1678 | tb[RTA_OIF]->rta_type = 0; | |
1679 | if (tb[RTA_GATEWAY]) | |
1680 | tb[RTA_GATEWAY]->rta_type = 0; | |
93ae2835 EB |
1681 | if (tb[RTA_VIA]) |
1682 | tb[RTA_VIA]->rta_type = 0; | |
aba5acdf SH |
1683 | if (!idev && tb[RTA_IIF]) |
1684 | tb[RTA_IIF]->rta_type = 0; | |
1685 | req.n.nlmsg_flags = NLM_F_REQUEST; | |
1686 | req.n.nlmsg_type = RTM_GETROUTE; | |
1687 | ||
c079e121 | 1688 | if (rtnl_talk(&rth, &req.n, &req.n, sizeof(req)) < 0) |
56d8ff0a | 1689 | return -2; |
aba5acdf SH |
1690 | } |
1691 | ||
1692 | if (print_route(NULL, &req.n, (void*)stdout) < 0) { | |
1693 | fprintf(stderr, "An error :-)\n"); | |
56d8ff0a | 1694 | return -1; |
aba5acdf SH |
1695 | } |
1696 | ||
56d8ff0a | 1697 | return 0; |
aba5acdf SH |
1698 | } |
1699 | ||
0628cddd ND |
1700 | static int restore_handler(const struct sockaddr_nl *nl, |
1701 | struct rtnl_ctrl_data *ctrl, | |
1702 | struct nlmsghdr *n, void *arg) | |
f4ff11e3 DS |
1703 | { |
1704 | int ret; | |
1705 | ||
1706 | n->nlmsg_flags |= NLM_F_REQUEST | NLM_F_CREATE | NLM_F_ACK; | |
1707 | ||
1708 | ll_init_map(&rth); | |
1709 | ||
c079e121 | 1710 | ret = rtnl_talk(&rth, n, n, sizeof(*n)); |
f4ff11e3 DS |
1711 | if ((ret < 0) && (errno == EEXIST)) |
1712 | ret = 0; | |
1713 | ||
1714 | return ret; | |
1715 | } | |
1716 | ||
76c61b34 PE |
1717 | static int route_dump_check_magic(void) |
1718 | { | |
1719 | int ret; | |
1720 | __u32 magic = 0; | |
1721 | ||
1722 | if (isatty(STDIN_FILENO)) { | |
1723 | fprintf(stderr, "Can't restore route dump from a terminal\n"); | |
1724 | return -1; | |
1725 | } | |
1726 | ||
1727 | ret = fread(&magic, sizeof(magic), 1, stdin); | |
1728 | if (magic != route_dump_magic) { | |
1729 | fprintf(stderr, "Magic mismatch (%d elems, %x magic)\n", ret, magic); | |
1730 | return -1; | |
1731 | } | |
1732 | ||
1733 | return 0; | |
1734 | } | |
1735 | ||
d1f28cf1 | 1736 | static int iproute_restore(void) |
f4ff11e3 | 1737 | { |
76c61b34 PE |
1738 | if (route_dump_check_magic()) |
1739 | exit(-1); | |
1740 | ||
f4ff11e3 DS |
1741 | exit(rtnl_from_file(stdin, &restore_handler, NULL)); |
1742 | } | |
1743 | ||
0628cddd ND |
1744 | static int show_handler(const struct sockaddr_nl *nl, |
1745 | struct rtnl_ctrl_data *ctrl, | |
1746 | struct nlmsghdr *n, void *arg) | |
93b79863 PE |
1747 | { |
1748 | print_route(nl, n, stdout); | |
1749 | return 0; | |
1750 | } | |
1751 | ||
1752 | static int iproute_showdump(void) | |
1753 | { | |
1754 | if (route_dump_check_magic()) | |
1755 | exit(-1); | |
1756 | ||
1757 | exit(rtnl_from_file(stdin, &show_handler, NULL)); | |
1758 | } | |
1759 | ||
093b7646 | 1760 | void iproute_reset_filter(int ifindex) |
aba5acdf SH |
1761 | { |
1762 | memset(&filter, 0, sizeof(filter)); | |
1763 | filter.mdst.bitlen = -1; | |
1764 | filter.msrc.bitlen = -1; | |
093b7646 | 1765 | filter.oif = ifindex; |
1766 | if (filter.oif > 0) | |
1767 | filter.oifmask = -1; | |
aba5acdf SH |
1768 | } |
1769 | ||
1770 | int do_iproute(int argc, char **argv) | |
1771 | { | |
1772 | if (argc < 1) | |
f4ff11e3 | 1773 | return iproute_list_flush_or_save(0, NULL, IPROUTE_LIST); |
ae665a52 | 1774 | |
aba5acdf SH |
1775 | if (matches(*argv, "add") == 0) |
1776 | return iproute_modify(RTM_NEWROUTE, NLM_F_CREATE|NLM_F_EXCL, | |
1777 | argc-1, argv+1); | |
1778 | if (matches(*argv, "change") == 0 || strcmp(*argv, "chg") == 0) | |
1779 | return iproute_modify(RTM_NEWROUTE, NLM_F_REPLACE, | |
1780 | argc-1, argv+1); | |
1781 | if (matches(*argv, "replace") == 0) | |
1782 | return iproute_modify(RTM_NEWROUTE, NLM_F_CREATE|NLM_F_REPLACE, | |
1783 | argc-1, argv+1); | |
1784 | if (matches(*argv, "prepend") == 0) | |
1785 | return iproute_modify(RTM_NEWROUTE, NLM_F_CREATE, | |
1786 | argc-1, argv+1); | |
1787 | if (matches(*argv, "append") == 0) | |
1788 | return iproute_modify(RTM_NEWROUTE, NLM_F_CREATE|NLM_F_APPEND, | |
1789 | argc-1, argv+1); | |
1790 | if (matches(*argv, "test") == 0) | |
1791 | return iproute_modify(RTM_NEWROUTE, NLM_F_EXCL, | |
1792 | argc-1, argv+1); | |
1793 | if (matches(*argv, "delete") == 0) | |
1794 | return iproute_modify(RTM_DELROUTE, 0, | |
1795 | argc-1, argv+1); | |
1796 | if (matches(*argv, "list") == 0 || matches(*argv, "show") == 0 | |
1797 | || matches(*argv, "lst") == 0) | |
f4ff11e3 | 1798 | return iproute_list_flush_or_save(argc-1, argv+1, IPROUTE_LIST); |
aba5acdf SH |
1799 | if (matches(*argv, "get") == 0) |
1800 | return iproute_get(argc-1, argv+1); | |
1801 | if (matches(*argv, "flush") == 0) | |
f4ff11e3 DS |
1802 | return iproute_list_flush_or_save(argc-1, argv+1, IPROUTE_FLUSH); |
1803 | if (matches(*argv, "save") == 0) | |
1804 | return iproute_list_flush_or_save(argc-1, argv+1, IPROUTE_SAVE); | |
1805 | if (matches(*argv, "restore") == 0) | |
1806 | return iproute_restore(); | |
93b79863 PE |
1807 | if (matches(*argv, "showdump") == 0) |
1808 | return iproute_showdump(); | |
aba5acdf SH |
1809 | if (matches(*argv, "help") == 0) |
1810 | usage(); | |
1811 | fprintf(stderr, "Command \"%s\" is unknown, try \"ip route help\".\n", *argv); | |
1812 | exit(-1); | |
1813 | } | |
1814 |