Glenn L McGrath | 9a2d272 | 2002-11-10 01:33:55 +0000 | [diff] [blame] | 1 | /* |
| 2 | * ipaddress.c "ip address". |
| 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 | * |
| 11 | * Changes: |
| 12 | * Laszlo Valko <valko@linux.karinthy.hu> 990223: address label must be zero terminated |
| 13 | */ |
| 14 | |
Glenn L McGrath | 9a2d272 | 2002-11-10 01:33:55 +0000 | [diff] [blame] | 15 | #include <sys/socket.h> |
| 16 | #include <sys/ioctl.h> |
Glenn L McGrath | 275be87 | 2002-12-16 07:37:21 +0000 | [diff] [blame] | 17 | |
Glenn L McGrath | 9a2d272 | 2002-11-10 01:33:55 +0000 | [diff] [blame] | 18 | #include <fnmatch.h> |
Glenn L McGrath | 275be87 | 2002-12-16 07:37:21 +0000 | [diff] [blame] | 19 | #include <stdlib.h> |
| 20 | #include <string.h> |
| 21 | #include <unistd.h> |
| 22 | |
| 23 | #include <arpa/inet.h> |
Glenn L McGrath | 9a2d272 | 2002-11-10 01:33:55 +0000 | [diff] [blame] | 24 | |
Eric Andersen | 8004bb7 | 2003-01-14 08:06:07 +0000 | [diff] [blame] | 25 | #include <net/if.h> |
| 26 | #include <net/if_arp.h> |
Glenn L McGrath | 9a2d272 | 2002-11-10 01:33:55 +0000 | [diff] [blame] | 27 | |
| 28 | #include "rt_names.h" |
| 29 | #include "utils.h" |
Bernhard Reutner-Fischer | 1d62d3b | 2005-10-08 20:47:15 +0000 | [diff] [blame^] | 30 | #include "ip_common.h" |
Glenn L McGrath | 9a2d272 | 2002-11-10 01:33:55 +0000 | [diff] [blame] | 31 | |
Glenn L McGrath | 275be87 | 2002-12-16 07:37:21 +0000 | [diff] [blame] | 32 | #include "libbb.h" |
Glenn L McGrath | 9a2d272 | 2002-11-10 01:33:55 +0000 | [diff] [blame] | 33 | |
| 34 | static struct |
| 35 | { |
| 36 | int ifindex; |
| 37 | int family; |
| 38 | int oneline; |
| 39 | int showqueue; |
| 40 | inet_prefix pfx; |
| 41 | int scope, scopemask; |
| 42 | int flags, flagmask; |
| 43 | int up; |
| 44 | char *label; |
Glenn L McGrath | d66370c | 2003-01-13 21:40:38 +0000 | [diff] [blame] | 45 | int flushed; |
| 46 | char *flushb; |
| 47 | int flushp; |
| 48 | int flushe; |
Glenn L McGrath | 9a2d272 | 2002-11-10 01:33:55 +0000 | [diff] [blame] | 49 | struct rtnl_handle *rth; |
| 50 | } filter; |
| 51 | |
Eric Andersen | 14f5c8d | 2005-04-16 19:39:00 +0000 | [diff] [blame] | 52 | static void print_link_flags(FILE *fp, unsigned flags, unsigned mdown) |
Glenn L McGrath | 9a2d272 | 2002-11-10 01:33:55 +0000 | [diff] [blame] | 53 | { |
| 54 | fprintf(fp, "<"); |
| 55 | flags &= ~IFF_RUNNING; |
| 56 | #define _PF(f) if (flags&IFF_##f) { \ |
| 57 | flags &= ~IFF_##f ; \ |
| 58 | fprintf(fp, #f "%s", flags ? "," : ""); } |
| 59 | _PF(LOOPBACK); |
| 60 | _PF(BROADCAST); |
| 61 | _PF(POINTOPOINT); |
| 62 | _PF(MULTICAST); |
| 63 | _PF(NOARP); |
| 64 | #if 0 |
| 65 | _PF(ALLMULTI); |
| 66 | _PF(PROMISC); |
| 67 | _PF(MASTER); |
| 68 | _PF(SLAVE); |
| 69 | _PF(DEBUG); |
| 70 | _PF(DYNAMIC); |
| 71 | _PF(AUTOMEDIA); |
| 72 | _PF(PORTSEL); |
| 73 | _PF(NOTRAILERS); |
| 74 | #endif |
| 75 | _PF(UP); |
| 76 | #undef _PF |
| 77 | if (flags) |
| 78 | fprintf(fp, "%x", flags); |
| 79 | if (mdown) |
| 80 | fprintf(fp, ",M-DOWN"); |
| 81 | fprintf(fp, "> "); |
| 82 | } |
| 83 | |
Glenn L McGrath | 2626ef6 | 2002-12-02 01:40:05 +0000 | [diff] [blame] | 84 | static void print_queuelen(char *name) |
Glenn L McGrath | 9a2d272 | 2002-11-10 01:33:55 +0000 | [diff] [blame] | 85 | { |
| 86 | struct ifreq ifr; |
| 87 | int s; |
| 88 | |
| 89 | s = socket(AF_INET, SOCK_STREAM, 0); |
| 90 | if (s < 0) |
| 91 | return; |
| 92 | |
| 93 | memset(&ifr, 0, sizeof(ifr)); |
| 94 | strcpy(ifr.ifr_name, name); |
Eric Andersen | c7bda1c | 2004-03-15 08:29:22 +0000 | [diff] [blame] | 95 | if (ioctl(s, SIOCGIFTXQLEN, &ifr) < 0) { |
Glenn L McGrath | 9a2d272 | 2002-11-10 01:33:55 +0000 | [diff] [blame] | 96 | perror("SIOCGIFXQLEN"); |
| 97 | close(s); |
| 98 | return; |
| 99 | } |
| 100 | close(s); |
| 101 | |
| 102 | if (ifr.ifr_qlen) |
| 103 | printf("qlen %d", ifr.ifr_qlen); |
| 104 | } |
| 105 | |
Glenn L McGrath | 2626ef6 | 2002-12-02 01:40:05 +0000 | [diff] [blame] | 106 | static int print_linkinfo(struct sockaddr_nl *who, struct nlmsghdr *n, void *arg) |
Glenn L McGrath | 9a2d272 | 2002-11-10 01:33:55 +0000 | [diff] [blame] | 107 | { |
| 108 | FILE *fp = (FILE*)arg; |
| 109 | struct ifinfomsg *ifi = NLMSG_DATA(n); |
| 110 | struct rtattr * tb[IFLA_MAX+1]; |
| 111 | int len = n->nlmsg_len; |
| 112 | unsigned m_flag = 0; |
| 113 | |
| 114 | if (n->nlmsg_type != RTM_NEWLINK && n->nlmsg_type != RTM_DELLINK) |
| 115 | return 0; |
| 116 | |
| 117 | len -= NLMSG_LENGTH(sizeof(*ifi)); |
| 118 | if (len < 0) |
| 119 | return -1; |
| 120 | |
| 121 | if (filter.ifindex && ifi->ifi_index != filter.ifindex) |
| 122 | return 0; |
| 123 | if (filter.up && !(ifi->ifi_flags&IFF_UP)) |
| 124 | return 0; |
| 125 | |
| 126 | memset(tb, 0, sizeof(tb)); |
| 127 | parse_rtattr(tb, IFLA_MAX, IFLA_RTA(ifi), len); |
| 128 | if (tb[IFLA_IFNAME] == NULL) { |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 129 | bb_error_msg("nil ifname"); |
Glenn L McGrath | 9a2d272 | 2002-11-10 01:33:55 +0000 | [diff] [blame] | 130 | return -1; |
| 131 | } |
| 132 | if (filter.label && |
| 133 | (!filter.family || filter.family == AF_PACKET) && |
| 134 | fnmatch(filter.label, RTA_DATA(tb[IFLA_IFNAME]), 0)) |
| 135 | return 0; |
| 136 | |
| 137 | if (n->nlmsg_type == RTM_DELLINK) |
| 138 | fprintf(fp, "Deleted "); |
| 139 | |
| 140 | fprintf(fp, "%d: %s", ifi->ifi_index, |
| 141 | tb[IFLA_IFNAME] ? (char*)RTA_DATA(tb[IFLA_IFNAME]) : "<nil>"); |
| 142 | |
| 143 | if (tb[IFLA_LINK]) { |
| 144 | SPRINT_BUF(b1); |
| 145 | int iflink = *(int*)RTA_DATA(tb[IFLA_LINK]); |
| 146 | if (iflink == 0) |
| 147 | fprintf(fp, "@NONE: "); |
| 148 | else { |
| 149 | fprintf(fp, "@%s: ", ll_idx_n2a(iflink, b1)); |
| 150 | m_flag = ll_index_to_flags(iflink); |
| 151 | m_flag = !(m_flag & IFF_UP); |
| 152 | } |
| 153 | } else { |
| 154 | fprintf(fp, ": "); |
| 155 | } |
| 156 | print_link_flags(fp, ifi->ifi_flags, m_flag); |
| 157 | |
| 158 | if (tb[IFLA_MTU]) |
| 159 | fprintf(fp, "mtu %u ", *(int*)RTA_DATA(tb[IFLA_MTU])); |
| 160 | if (tb[IFLA_QDISC]) |
| 161 | fprintf(fp, "qdisc %s ", (char*)RTA_DATA(tb[IFLA_QDISC])); |
| 162 | #ifdef IFLA_MASTER |
| 163 | if (tb[IFLA_MASTER]) { |
| 164 | SPRINT_BUF(b1); |
| 165 | fprintf(fp, "master %s ", ll_idx_n2a(*(int*)RTA_DATA(tb[IFLA_MASTER]), b1)); |
| 166 | } |
| 167 | #endif |
| 168 | if (filter.showqueue) |
| 169 | print_queuelen((char*)RTA_DATA(tb[IFLA_IFNAME])); |
Eric Andersen | c7bda1c | 2004-03-15 08:29:22 +0000 | [diff] [blame] | 170 | |
Glenn L McGrath | 9a2d272 | 2002-11-10 01:33:55 +0000 | [diff] [blame] | 171 | if (!filter.family || filter.family == AF_PACKET) { |
| 172 | SPRINT_BUF(b1); |
| 173 | fprintf(fp, "%s", _SL_); |
| 174 | fprintf(fp, " link/%s ", ll_type_n2a(ifi->ifi_type, b1, sizeof(b1))); |
| 175 | |
| 176 | if (tb[IFLA_ADDRESS]) { |
| 177 | fprintf(fp, "%s", ll_addr_n2a(RTA_DATA(tb[IFLA_ADDRESS]), |
| 178 | RTA_PAYLOAD(tb[IFLA_ADDRESS]), |
| 179 | ifi->ifi_type, |
| 180 | b1, sizeof(b1))); |
| 181 | } |
| 182 | if (tb[IFLA_BROADCAST]) { |
| 183 | if (ifi->ifi_flags&IFF_POINTOPOINT) |
| 184 | fprintf(fp, " peer "); |
| 185 | else |
| 186 | fprintf(fp, " brd "); |
| 187 | fprintf(fp, "%s", ll_addr_n2a(RTA_DATA(tb[IFLA_BROADCAST]), |
| 188 | RTA_PAYLOAD(tb[IFLA_BROADCAST]), |
| 189 | ifi->ifi_type, |
| 190 | b1, sizeof(b1))); |
| 191 | } |
| 192 | } |
| 193 | fprintf(fp, "\n"); |
| 194 | fflush(fp); |
| 195 | return 0; |
| 196 | } |
| 197 | |
Glenn L McGrath | d66370c | 2003-01-13 21:40:38 +0000 | [diff] [blame] | 198 | static int flush_update(void) |
| 199 | { |
| 200 | if (rtnl_send(filter.rth, filter.flushb, filter.flushp) < 0) { |
| 201 | perror("Failed to send flush request\n"); |
| 202 | return -1; |
| 203 | } |
| 204 | filter.flushp = 0; |
| 205 | return 0; |
| 206 | } |
| 207 | |
Glenn L McGrath | 2626ef6 | 2002-12-02 01:40:05 +0000 | [diff] [blame] | 208 | static int print_addrinfo(struct sockaddr_nl *who, struct nlmsghdr *n, void *arg) |
Glenn L McGrath | 9a2d272 | 2002-11-10 01:33:55 +0000 | [diff] [blame] | 209 | { |
| 210 | FILE *fp = (FILE*)arg; |
| 211 | struct ifaddrmsg *ifa = NLMSG_DATA(n); |
| 212 | int len = n->nlmsg_len; |
| 213 | struct rtattr * rta_tb[IFA_MAX+1]; |
| 214 | char abuf[256]; |
| 215 | SPRINT_BUF(b1); |
| 216 | |
| 217 | if (n->nlmsg_type != RTM_NEWADDR && n->nlmsg_type != RTM_DELADDR) |
| 218 | return 0; |
| 219 | len -= NLMSG_LENGTH(sizeof(*ifa)); |
| 220 | if (len < 0) { |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 221 | bb_error_msg("wrong nlmsg len %d", len); |
Glenn L McGrath | 9a2d272 | 2002-11-10 01:33:55 +0000 | [diff] [blame] | 222 | return -1; |
| 223 | } |
| 224 | |
Glenn L McGrath | d66370c | 2003-01-13 21:40:38 +0000 | [diff] [blame] | 225 | if (filter.flushb && n->nlmsg_type != RTM_NEWADDR) |
| 226 | return 0; |
| 227 | |
Glenn L McGrath | 9a2d272 | 2002-11-10 01:33:55 +0000 | [diff] [blame] | 228 | memset(rta_tb, 0, sizeof(rta_tb)); |
| 229 | parse_rtattr(rta_tb, IFA_MAX, IFA_RTA(ifa), n->nlmsg_len - NLMSG_LENGTH(sizeof(*ifa))); |
| 230 | |
| 231 | if (!rta_tb[IFA_LOCAL]) |
| 232 | rta_tb[IFA_LOCAL] = rta_tb[IFA_ADDRESS]; |
| 233 | if (!rta_tb[IFA_ADDRESS]) |
| 234 | rta_tb[IFA_ADDRESS] = rta_tb[IFA_LOCAL]; |
| 235 | |
| 236 | if (filter.ifindex && filter.ifindex != ifa->ifa_index) |
| 237 | return 0; |
| 238 | if ((filter.scope^ifa->ifa_scope)&filter.scopemask) |
| 239 | return 0; |
| 240 | if ((filter.flags^ifa->ifa_flags)&filter.flagmask) |
| 241 | return 0; |
| 242 | if (filter.label) { |
Glenn L McGrath | 9a2d272 | 2002-11-10 01:33:55 +0000 | [diff] [blame] | 243 | const char *label; |
| 244 | if (rta_tb[IFA_LABEL]) |
| 245 | label = RTA_DATA(rta_tb[IFA_LABEL]); |
| 246 | else |
| 247 | label = ll_idx_n2a(ifa->ifa_index, b1); |
| 248 | if (fnmatch(filter.label, label, 0) != 0) |
| 249 | return 0; |
| 250 | } |
| 251 | if (filter.pfx.family) { |
| 252 | if (rta_tb[IFA_LOCAL]) { |
| 253 | inet_prefix dst; |
| 254 | memset(&dst, 0, sizeof(dst)); |
| 255 | dst.family = ifa->ifa_family; |
| 256 | memcpy(&dst.data, RTA_DATA(rta_tb[IFA_LOCAL]), RTA_PAYLOAD(rta_tb[IFA_LOCAL])); |
| 257 | if (inet_addr_match(&dst, &filter.pfx, filter.pfx.bitlen)) |
| 258 | return 0; |
| 259 | } |
| 260 | } |
| 261 | |
Glenn L McGrath | d66370c | 2003-01-13 21:40:38 +0000 | [diff] [blame] | 262 | if (filter.flushb) { |
| 263 | struct nlmsghdr *fn; |
| 264 | if (NLMSG_ALIGN(filter.flushp) + n->nlmsg_len > filter.flushe) { |
| 265 | if (flush_update()) |
| 266 | return -1; |
| 267 | } |
| 268 | fn = (struct nlmsghdr*)(filter.flushb + NLMSG_ALIGN(filter.flushp)); |
| 269 | memcpy(fn, n, n->nlmsg_len); |
| 270 | fn->nlmsg_type = RTM_DELADDR; |
| 271 | fn->nlmsg_flags = NLM_F_REQUEST; |
| 272 | fn->nlmsg_seq = ++filter.rth->seq; |
| 273 | filter.flushp = (((char*)fn) + n->nlmsg_len) - filter.flushb; |
| 274 | filter.flushed++; |
| 275 | return 0; |
| 276 | } |
| 277 | |
Glenn L McGrath | 9a2d272 | 2002-11-10 01:33:55 +0000 | [diff] [blame] | 278 | if (n->nlmsg_type == RTM_DELADDR) |
| 279 | fprintf(fp, "Deleted "); |
| 280 | |
| 281 | if (filter.oneline) |
| 282 | fprintf(fp, "%u: %s", ifa->ifa_index, ll_index_to_name(ifa->ifa_index)); |
| 283 | if (ifa->ifa_family == AF_INET) |
| 284 | fprintf(fp, " inet "); |
| 285 | else if (ifa->ifa_family == AF_INET6) |
| 286 | fprintf(fp, " inet6 "); |
| 287 | else |
| 288 | fprintf(fp, " family %d ", ifa->ifa_family); |
| 289 | |
| 290 | if (rta_tb[IFA_LOCAL]) { |
| 291 | fprintf(fp, "%s", rt_addr_n2a(ifa->ifa_family, |
| 292 | RTA_PAYLOAD(rta_tb[IFA_LOCAL]), |
| 293 | RTA_DATA(rta_tb[IFA_LOCAL]), |
| 294 | abuf, sizeof(abuf))); |
| 295 | |
| 296 | if (rta_tb[IFA_ADDRESS] == NULL || |
| 297 | memcmp(RTA_DATA(rta_tb[IFA_ADDRESS]), RTA_DATA(rta_tb[IFA_LOCAL]), 4) == 0) { |
| 298 | fprintf(fp, "/%d ", ifa->ifa_prefixlen); |
| 299 | } else { |
| 300 | fprintf(fp, " peer %s/%d ", |
| 301 | rt_addr_n2a(ifa->ifa_family, |
| 302 | RTA_PAYLOAD(rta_tb[IFA_ADDRESS]), |
| 303 | RTA_DATA(rta_tb[IFA_ADDRESS]), |
| 304 | abuf, sizeof(abuf)), |
| 305 | ifa->ifa_prefixlen); |
| 306 | } |
| 307 | } |
| 308 | |
| 309 | if (rta_tb[IFA_BROADCAST]) { |
| 310 | fprintf(fp, "brd %s ", |
| 311 | rt_addr_n2a(ifa->ifa_family, |
| 312 | RTA_PAYLOAD(rta_tb[IFA_BROADCAST]), |
| 313 | RTA_DATA(rta_tb[IFA_BROADCAST]), |
| 314 | abuf, sizeof(abuf))); |
| 315 | } |
| 316 | if (rta_tb[IFA_ANYCAST]) { |
| 317 | fprintf(fp, "any %s ", |
| 318 | rt_addr_n2a(ifa->ifa_family, |
| 319 | RTA_PAYLOAD(rta_tb[IFA_ANYCAST]), |
| 320 | RTA_DATA(rta_tb[IFA_ANYCAST]), |
| 321 | abuf, sizeof(abuf))); |
| 322 | } |
| 323 | fprintf(fp, "scope %s ", rtnl_rtscope_n2a(ifa->ifa_scope, b1, sizeof(b1))); |
| 324 | if (ifa->ifa_flags&IFA_F_SECONDARY) { |
| 325 | ifa->ifa_flags &= ~IFA_F_SECONDARY; |
| 326 | fprintf(fp, "secondary "); |
| 327 | } |
| 328 | if (ifa->ifa_flags&IFA_F_TENTATIVE) { |
| 329 | ifa->ifa_flags &= ~IFA_F_TENTATIVE; |
| 330 | fprintf(fp, "tentative "); |
| 331 | } |
| 332 | if (ifa->ifa_flags&IFA_F_DEPRECATED) { |
| 333 | ifa->ifa_flags &= ~IFA_F_DEPRECATED; |
| 334 | fprintf(fp, "deprecated "); |
| 335 | } |
| 336 | if (!(ifa->ifa_flags&IFA_F_PERMANENT)) { |
| 337 | fprintf(fp, "dynamic "); |
| 338 | } else |
| 339 | ifa->ifa_flags &= ~IFA_F_PERMANENT; |
| 340 | if (ifa->ifa_flags) |
| 341 | fprintf(fp, "flags %02x ", ifa->ifa_flags); |
| 342 | if (rta_tb[IFA_LABEL]) |
| 343 | fprintf(fp, "%s", (char*)RTA_DATA(rta_tb[IFA_LABEL])); |
| 344 | if (rta_tb[IFA_CACHEINFO]) { |
| 345 | struct ifa_cacheinfo *ci = RTA_DATA(rta_tb[IFA_CACHEINFO]); |
| 346 | char buf[128]; |
| 347 | fprintf(fp, "%s", _SL_); |
| 348 | if (ci->ifa_valid == 0xFFFFFFFFU) |
| 349 | sprintf(buf, "valid_lft forever"); |
| 350 | else |
| 351 | sprintf(buf, "valid_lft %dsec", ci->ifa_valid); |
| 352 | if (ci->ifa_prefered == 0xFFFFFFFFU) |
| 353 | sprintf(buf+strlen(buf), " preferred_lft forever"); |
| 354 | else |
| 355 | sprintf(buf+strlen(buf), " preferred_lft %dsec", ci->ifa_prefered); |
| 356 | fprintf(fp, " %s", buf); |
| 357 | } |
| 358 | fprintf(fp, "\n"); |
| 359 | fflush(fp); |
| 360 | return 0; |
| 361 | } |
| 362 | |
| 363 | |
| 364 | struct nlmsg_list |
| 365 | { |
| 366 | struct nlmsg_list *next; |
| 367 | struct nlmsghdr h; |
| 368 | }; |
| 369 | |
Glenn L McGrath | 2626ef6 | 2002-12-02 01:40:05 +0000 | [diff] [blame] | 370 | static int print_selected_addrinfo(int ifindex, struct nlmsg_list *ainfo, FILE *fp) |
Glenn L McGrath | 9a2d272 | 2002-11-10 01:33:55 +0000 | [diff] [blame] | 371 | { |
| 372 | for ( ;ainfo ; ainfo = ainfo->next) { |
| 373 | struct nlmsghdr *n = &ainfo->h; |
| 374 | struct ifaddrmsg *ifa = NLMSG_DATA(n); |
| 375 | |
| 376 | if (n->nlmsg_type != RTM_NEWADDR) |
| 377 | continue; |
| 378 | |
| 379 | if (n->nlmsg_len < NLMSG_LENGTH(sizeof(ifa))) |
| 380 | return -1; |
| 381 | |
Eric Andersen | c7bda1c | 2004-03-15 08:29:22 +0000 | [diff] [blame] | 382 | if (ifa->ifa_index != ifindex || |
Glenn L McGrath | 9a2d272 | 2002-11-10 01:33:55 +0000 | [diff] [blame] | 383 | (filter.family && filter.family != ifa->ifa_family)) |
| 384 | continue; |
| 385 | |
| 386 | print_addrinfo(NULL, n, fp); |
| 387 | } |
| 388 | return 0; |
| 389 | } |
| 390 | |
| 391 | |
Glenn L McGrath | 2626ef6 | 2002-12-02 01:40:05 +0000 | [diff] [blame] | 392 | static int store_nlmsg(struct sockaddr_nl *who, struct nlmsghdr *n, void *arg) |
Glenn L McGrath | 9a2d272 | 2002-11-10 01:33:55 +0000 | [diff] [blame] | 393 | { |
| 394 | struct nlmsg_list **linfo = (struct nlmsg_list**)arg; |
| 395 | struct nlmsg_list *h; |
| 396 | struct nlmsg_list **lp; |
| 397 | |
| 398 | h = malloc(n->nlmsg_len+sizeof(void*)); |
| 399 | if (h == NULL) |
| 400 | return -1; |
| 401 | |
| 402 | memcpy(&h->h, n, n->nlmsg_len); |
| 403 | h->next = NULL; |
| 404 | |
| 405 | for (lp = linfo; *lp; lp = &(*lp)->next) /* NOTHING */; |
| 406 | *lp = h; |
| 407 | |
| 408 | ll_remember_index(who, n, NULL); |
| 409 | return 0; |
| 410 | } |
| 411 | |
Glenn L McGrath | 2626ef6 | 2002-12-02 01:40:05 +0000 | [diff] [blame] | 412 | static void ipaddr_reset_filter(int _oneline) |
Glenn L McGrath | 9a2d272 | 2002-11-10 01:33:55 +0000 | [diff] [blame] | 413 | { |
Glenn L McGrath | 2626ef6 | 2002-12-02 01:40:05 +0000 | [diff] [blame] | 414 | memset(&filter, 0, sizeof(filter)); |
| 415 | filter.oneline = _oneline; |
| 416 | } |
| 417 | |
Glenn L McGrath | d66370c | 2003-01-13 21:40:38 +0000 | [diff] [blame] | 418 | extern int ipaddr_list_or_flush(int argc, char **argv, int flush) |
Glenn L McGrath | 2626ef6 | 2002-12-02 01:40:05 +0000 | [diff] [blame] | 419 | { |
| 420 | const char *option[] = { "to", "scope", "up", "label", "dev", 0 }; |
Glenn L McGrath | 9a2d272 | 2002-11-10 01:33:55 +0000 | [diff] [blame] | 421 | struct nlmsg_list *linfo = NULL; |
| 422 | struct nlmsg_list *ainfo = NULL; |
| 423 | struct nlmsg_list *l; |
| 424 | struct rtnl_handle rth; |
| 425 | char *filter_dev = NULL; |
| 426 | int no_link = 0; |
| 427 | |
| 428 | ipaddr_reset_filter(oneline); |
| 429 | filter.showqueue = 1; |
| 430 | |
| 431 | if (filter.family == AF_UNSPEC) |
| 432 | filter.family = preferred_family; |
| 433 | |
Glenn L McGrath | d66370c | 2003-01-13 21:40:38 +0000 | [diff] [blame] | 434 | if (flush) { |
| 435 | if (argc <= 0) { |
| 436 | fprintf(stderr, "Flush requires arguments.\n"); |
| 437 | return -1; |
| 438 | } |
| 439 | if (filter.family == AF_PACKET) { |
| 440 | fprintf(stderr, "Cannot flush link addresses.\n"); |
| 441 | return -1; |
| 442 | } |
| 443 | } |
| 444 | |
Glenn L McGrath | 9a2d272 | 2002-11-10 01:33:55 +0000 | [diff] [blame] | 445 | while (argc > 0) { |
Glenn L McGrath | 2626ef6 | 2002-12-02 01:40:05 +0000 | [diff] [blame] | 446 | const unsigned short option_num = compare_string_array(option, *argv); |
| 447 | switch (option_num) { |
| 448 | case 0: /* to */ |
Glenn L McGrath | 9a2d272 | 2002-11-10 01:33:55 +0000 | [diff] [blame] | 449 | NEXT_ARG(); |
Glenn L McGrath | 2626ef6 | 2002-12-02 01:40:05 +0000 | [diff] [blame] | 450 | get_prefix(&filter.pfx, *argv, filter.family); |
| 451 | if (filter.family == AF_UNSPEC) { |
| 452 | filter.family = filter.pfx.family; |
| 453 | } |
| 454 | break; |
| 455 | case 1: /* scope */ |
| 456 | { |
| 457 | int scope = 0; |
| 458 | NEXT_ARG(); |
| 459 | filter.scopemask = -1; |
| 460 | if (rtnl_rtscope_a2n(&scope, *argv)) { |
| 461 | if (strcmp(*argv, "all") != 0) { |
| 462 | invarg("invalid \"scope\"\n", *argv); |
| 463 | } |
| 464 | scope = RT_SCOPE_NOWHERE; |
| 465 | filter.scopemask = 0; |
| 466 | } |
| 467 | filter.scope = scope; |
| 468 | break; |
Glenn L McGrath | 9a2d272 | 2002-11-10 01:33:55 +0000 | [diff] [blame] | 469 | } |
Glenn L McGrath | 2626ef6 | 2002-12-02 01:40:05 +0000 | [diff] [blame] | 470 | case 2: /* up */ |
| 471 | filter.up = 1; |
| 472 | break; |
| 473 | case 3: /* label */ |
| 474 | NEXT_ARG(); |
| 475 | filter.label = *argv; |
| 476 | break; |
| 477 | case 4: /* dev */ |
| 478 | NEXT_ARG(); |
| 479 | default: |
| 480 | if (filter_dev) { |
| 481 | duparg2("dev", *argv); |
| 482 | } |
| 483 | filter_dev = *argv; |
Glenn L McGrath | 9a2d272 | 2002-11-10 01:33:55 +0000 | [diff] [blame] | 484 | } |
Glenn L McGrath | 2626ef6 | 2002-12-02 01:40:05 +0000 | [diff] [blame] | 485 | argv++; |
| 486 | argc--; |
Glenn L McGrath | 9a2d272 | 2002-11-10 01:33:55 +0000 | [diff] [blame] | 487 | } |
| 488 | |
| 489 | if (rtnl_open(&rth, 0) < 0) |
| 490 | exit(1); |
| 491 | |
| 492 | if (rtnl_wilddump_request(&rth, preferred_family, RTM_GETLINK) < 0) { |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 493 | bb_perror_msg_and_die("Cannot send dump request"); |
Glenn L McGrath | 9a2d272 | 2002-11-10 01:33:55 +0000 | [diff] [blame] | 494 | } |
| 495 | |
| 496 | if (rtnl_dump_filter(&rth, store_nlmsg, &linfo, NULL, NULL) < 0) { |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 497 | bb_error_msg_and_die("Dump terminated"); |
Glenn L McGrath | 9a2d272 | 2002-11-10 01:33:55 +0000 | [diff] [blame] | 498 | } |
| 499 | |
| 500 | if (filter_dev) { |
| 501 | filter.ifindex = ll_name_to_index(filter_dev); |
| 502 | if (filter.ifindex <= 0) { |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 503 | bb_error_msg("Device \"%s\" does not exist.", filter_dev); |
Glenn L McGrath | 9a2d272 | 2002-11-10 01:33:55 +0000 | [diff] [blame] | 504 | return -1; |
| 505 | } |
| 506 | } |
| 507 | |
Glenn L McGrath | d66370c | 2003-01-13 21:40:38 +0000 | [diff] [blame] | 508 | if (flush) { |
| 509 | int round = 0; |
| 510 | char flushb[4096-512]; |
| 511 | |
| 512 | filter.flushb = flushb; |
| 513 | filter.flushp = 0; |
| 514 | filter.flushe = sizeof(flushb); |
| 515 | filter.rth = &rth; |
| 516 | |
| 517 | for (;;) { |
| 518 | if (rtnl_wilddump_request(&rth, filter.family, RTM_GETADDR) < 0) { |
| 519 | perror("Cannot send dump request"); |
| 520 | exit(1); |
| 521 | } |
| 522 | filter.flushed = 0; |
| 523 | if (rtnl_dump_filter(&rth, print_addrinfo, stdout, NULL, NULL) < 0) { |
| 524 | fprintf(stderr, "Flush terminated\n"); |
| 525 | exit(1); |
| 526 | } |
| 527 | if (filter.flushed == 0) { |
Eric Andersen | 66a3af9 | 2003-01-27 17:41:19 +0000 | [diff] [blame] | 528 | #if 0 |
Glenn L McGrath | d66370c | 2003-01-13 21:40:38 +0000 | [diff] [blame] | 529 | if (round == 0) |
| 530 | fprintf(stderr, "Nothing to flush.\n"); |
Eric Andersen | 66a3af9 | 2003-01-27 17:41:19 +0000 | [diff] [blame] | 531 | #endif |
Glenn L McGrath | d66370c | 2003-01-13 21:40:38 +0000 | [diff] [blame] | 532 | fflush(stdout); |
| 533 | return 0; |
| 534 | } |
| 535 | round++; |
| 536 | if (flush_update() < 0) |
| 537 | exit(1); |
| 538 | } |
| 539 | } |
| 540 | |
Glenn L McGrath | 9a2d272 | 2002-11-10 01:33:55 +0000 | [diff] [blame] | 541 | if (filter.family != AF_PACKET) { |
| 542 | if (rtnl_wilddump_request(&rth, filter.family, RTM_GETADDR) < 0) { |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 543 | bb_perror_msg_and_die("Cannot send dump request"); |
Glenn L McGrath | 9a2d272 | 2002-11-10 01:33:55 +0000 | [diff] [blame] | 544 | } |
| 545 | |
| 546 | if (rtnl_dump_filter(&rth, store_nlmsg, &ainfo, NULL, NULL) < 0) { |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 547 | bb_error_msg_and_die("Dump terminated"); |
Glenn L McGrath | 9a2d272 | 2002-11-10 01:33:55 +0000 | [diff] [blame] | 548 | } |
| 549 | } |
| 550 | |
| 551 | |
| 552 | if (filter.family && filter.family != AF_PACKET) { |
| 553 | struct nlmsg_list **lp; |
| 554 | lp=&linfo; |
| 555 | |
| 556 | if (filter.oneline) |
| 557 | no_link = 1; |
| 558 | |
| 559 | while ((l=*lp)!=NULL) { |
| 560 | int ok = 0; |
| 561 | struct ifinfomsg *ifi = NLMSG_DATA(&l->h); |
| 562 | struct nlmsg_list *a; |
| 563 | |
| 564 | for (a=ainfo; a; a=a->next) { |
| 565 | struct nlmsghdr *n = &a->h; |
| 566 | struct ifaddrmsg *ifa = NLMSG_DATA(n); |
| 567 | |
Eric Andersen | c7bda1c | 2004-03-15 08:29:22 +0000 | [diff] [blame] | 568 | if (ifa->ifa_index != ifi->ifi_index || |
Glenn L McGrath | 9a2d272 | 2002-11-10 01:33:55 +0000 | [diff] [blame] | 569 | (filter.family && filter.family != ifa->ifa_family)) |
| 570 | continue; |
| 571 | if ((filter.scope^ifa->ifa_scope)&filter.scopemask) |
| 572 | continue; |
| 573 | if ((filter.flags^ifa->ifa_flags)&filter.flagmask) |
| 574 | continue; |
| 575 | if (filter.pfx.family || filter.label) { |
| 576 | struct rtattr *tb[IFA_MAX+1]; |
| 577 | memset(tb, 0, sizeof(tb)); |
| 578 | parse_rtattr(tb, IFA_MAX, IFA_RTA(ifa), IFA_PAYLOAD(n)); |
| 579 | if (!tb[IFA_LOCAL]) |
| 580 | tb[IFA_LOCAL] = tb[IFA_ADDRESS]; |
| 581 | |
| 582 | if (filter.pfx.family && tb[IFA_LOCAL]) { |
| 583 | inet_prefix dst; |
| 584 | memset(&dst, 0, sizeof(dst)); |
| 585 | dst.family = ifa->ifa_family; |
| 586 | memcpy(&dst.data, RTA_DATA(tb[IFA_LOCAL]), RTA_PAYLOAD(tb[IFA_LOCAL])); |
| 587 | if (inet_addr_match(&dst, &filter.pfx, filter.pfx.bitlen)) |
| 588 | continue; |
| 589 | } |
| 590 | if (filter.label) { |
| 591 | SPRINT_BUF(b1); |
| 592 | const char *label; |
| 593 | if (tb[IFA_LABEL]) |
| 594 | label = RTA_DATA(tb[IFA_LABEL]); |
| 595 | else |
| 596 | label = ll_idx_n2a(ifa->ifa_index, b1); |
| 597 | if (fnmatch(filter.label, label, 0) != 0) |
| 598 | continue; |
| 599 | } |
| 600 | } |
| 601 | |
| 602 | ok = 1; |
| 603 | break; |
| 604 | } |
| 605 | if (!ok) |
| 606 | *lp = l->next; |
| 607 | else |
| 608 | lp = &l->next; |
| 609 | } |
| 610 | } |
| 611 | |
| 612 | for (l=linfo; l; l = l->next) { |
| 613 | if (no_link || print_linkinfo(NULL, &l->h, stdout) == 0) { |
| 614 | struct ifinfomsg *ifi = NLMSG_DATA(&l->h); |
| 615 | if (filter.family != AF_PACKET) |
| 616 | print_selected_addrinfo(ifi->ifi_index, ainfo, stdout); |
| 617 | } |
| 618 | fflush(stdout); |
| 619 | } |
| 620 | |
| 621 | exit(0); |
| 622 | } |
| 623 | |
Glenn L McGrath | 2626ef6 | 2002-12-02 01:40:05 +0000 | [diff] [blame] | 624 | static int default_scope(inet_prefix *lcl) |
Glenn L McGrath | 9a2d272 | 2002-11-10 01:33:55 +0000 | [diff] [blame] | 625 | { |
| 626 | if (lcl->family == AF_INET) { |
| 627 | if (lcl->bytelen >= 1 && *(__u8*)&lcl->data == 127) |
| 628 | return RT_SCOPE_HOST; |
| 629 | } |
| 630 | return 0; |
| 631 | } |
| 632 | |
Glenn L McGrath | 2626ef6 | 2002-12-02 01:40:05 +0000 | [diff] [blame] | 633 | static int ipaddr_modify(int cmd, int argc, char **argv) |
Glenn L McGrath | 9a2d272 | 2002-11-10 01:33:55 +0000 | [diff] [blame] | 634 | { |
Glenn L McGrath | 2626ef6 | 2002-12-02 01:40:05 +0000 | [diff] [blame] | 635 | const char *option[] = { "peer", "remote", "broadcast", "brd", |
| 636 | "anycast", "scope", "dev", "label", "local", 0 }; |
Glenn L McGrath | 9a2d272 | 2002-11-10 01:33:55 +0000 | [diff] [blame] | 637 | struct rtnl_handle rth; |
| 638 | struct { |
| 639 | struct nlmsghdr n; |
| 640 | struct ifaddrmsg ifa; |
| 641 | char buf[256]; |
| 642 | } req; |
| 643 | char *d = NULL; |
| 644 | char *l = NULL; |
| 645 | inet_prefix lcl; |
| 646 | inet_prefix peer; |
| 647 | int local_len = 0; |
| 648 | int peer_len = 0; |
| 649 | int brd_len = 0; |
| 650 | int any_len = 0; |
| 651 | int scoped = 0; |
| 652 | |
| 653 | memset(&req, 0, sizeof(req)); |
| 654 | |
| 655 | req.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct ifaddrmsg)); |
| 656 | req.n.nlmsg_flags = NLM_F_REQUEST; |
| 657 | req.n.nlmsg_type = cmd; |
| 658 | req.ifa.ifa_family = preferred_family; |
| 659 | |
| 660 | while (argc > 0) { |
Glenn L McGrath | 2626ef6 | 2002-12-02 01:40:05 +0000 | [diff] [blame] | 661 | const unsigned short option_num = compare_string_array(option, *argv); |
| 662 | switch (option_num) { |
| 663 | case 0: /* peer */ |
| 664 | case 1: /* remote */ |
Glenn L McGrath | 9a2d272 | 2002-11-10 01:33:55 +0000 | [diff] [blame] | 665 | NEXT_ARG(); |
Glenn L McGrath | 2626ef6 | 2002-12-02 01:40:05 +0000 | [diff] [blame] | 666 | |
| 667 | if (peer_len) { |
| 668 | duparg("peer", *argv); |
| 669 | } |
| 670 | get_prefix(&peer, *argv, req.ifa.ifa_family); |
| 671 | peer_len = peer.bytelen; |
| 672 | if (req.ifa.ifa_family == AF_UNSPEC) { |
| 673 | req.ifa.ifa_family = peer.family; |
| 674 | } |
| 675 | addattr_l(&req.n, sizeof(req), IFA_ADDRESS, &peer.data, peer.bytelen); |
| 676 | req.ifa.ifa_prefixlen = peer.bitlen; |
| 677 | break; |
| 678 | case 2: /* broadcast */ |
| 679 | case 3: /* brd */ |
| 680 | { |
| 681 | inet_prefix addr; |
| 682 | NEXT_ARG(); |
| 683 | if (brd_len) { |
| 684 | duparg("broadcast", *argv); |
| 685 | } |
| 686 | if (strcmp(*argv, "+") == 0) { |
| 687 | brd_len = -1; |
| 688 | } |
| 689 | else if (strcmp(*argv, "-") == 0) { |
| 690 | brd_len = -2; |
| 691 | } else { |
| 692 | get_addr(&addr, *argv, req.ifa.ifa_family); |
| 693 | if (req.ifa.ifa_family == AF_UNSPEC) |
| 694 | req.ifa.ifa_family = addr.family; |
| 695 | addattr_l(&req.n, sizeof(req), IFA_BROADCAST, &addr.data, addr.bytelen); |
| 696 | brd_len = addr.bytelen; |
| 697 | } |
| 698 | break; |
Glenn L McGrath | 9a2d272 | 2002-11-10 01:33:55 +0000 | [diff] [blame] | 699 | } |
Glenn L McGrath | 2626ef6 | 2002-12-02 01:40:05 +0000 | [diff] [blame] | 700 | case 4: /* anycast */ |
| 701 | { |
| 702 | inet_prefix addr; |
| 703 | NEXT_ARG(); |
| 704 | if (any_len) { |
| 705 | duparg("anycast", *argv); |
| 706 | } |
| 707 | get_addr(&addr, *argv, req.ifa.ifa_family); |
| 708 | if (req.ifa.ifa_family == AF_UNSPEC) { |
| 709 | req.ifa.ifa_family = addr.family; |
| 710 | } |
| 711 | addattr_l(&req.n, sizeof(req), IFA_ANYCAST, &addr.data, addr.bytelen); |
| 712 | any_len = addr.bytelen; |
| 713 | break; |
| 714 | } |
| 715 | case 5: /* scope */ |
| 716 | { |
| 717 | int scope = 0; |
| 718 | NEXT_ARG(); |
| 719 | if (rtnl_rtscope_a2n(&scope, *argv)) { |
| 720 | invarg(*argv, "invalid scope value."); |
| 721 | } |
| 722 | req.ifa.ifa_scope = scope; |
| 723 | scoped = 1; |
| 724 | break; |
| 725 | } |
| 726 | case 6: /* dev */ |
| 727 | NEXT_ARG(); |
| 728 | d = *argv; |
| 729 | break; |
| 730 | case 7: /* label */ |
| 731 | NEXT_ARG(); |
| 732 | l = *argv; |
| 733 | addattr_l(&req.n, sizeof(req), IFA_LABEL, l, strlen(l)+1); |
| 734 | break; |
| 735 | case 8: /* local */ |
| 736 | NEXT_ARG(); |
| 737 | default: |
| 738 | if (local_len) { |
| 739 | duparg2("local", *argv); |
| 740 | } |
| 741 | get_prefix(&lcl, *argv, req.ifa.ifa_family); |
| 742 | if (req.ifa.ifa_family == AF_UNSPEC) { |
| 743 | req.ifa.ifa_family = lcl.family; |
| 744 | } |
| 745 | addattr_l(&req.n, sizeof(req), IFA_LOCAL, &lcl.data, lcl.bytelen); |
| 746 | local_len = lcl.bytelen; |
Glenn L McGrath | 9a2d272 | 2002-11-10 01:33:55 +0000 | [diff] [blame] | 747 | } |
Glenn L McGrath | 2626ef6 | 2002-12-02 01:40:05 +0000 | [diff] [blame] | 748 | argc--; |
| 749 | argv++; |
Glenn L McGrath | 9a2d272 | 2002-11-10 01:33:55 +0000 | [diff] [blame] | 750 | } |
Glenn L McGrath | 2626ef6 | 2002-12-02 01:40:05 +0000 | [diff] [blame] | 751 | |
Glenn L McGrath | 9a2d272 | 2002-11-10 01:33:55 +0000 | [diff] [blame] | 752 | if (d == NULL) { |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 753 | bb_error_msg("Not enough information: \"dev\" argument is required."); |
Glenn L McGrath | 9a2d272 | 2002-11-10 01:33:55 +0000 | [diff] [blame] | 754 | return -1; |
| 755 | } |
| 756 | if (l && matches(d, l) != 0) { |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 757 | bb_error_msg_and_die("\"dev\" (%s) must match \"label\" (%s).", d, l); |
Glenn L McGrath | 9a2d272 | 2002-11-10 01:33:55 +0000 | [diff] [blame] | 758 | } |
| 759 | |
| 760 | if (peer_len == 0 && local_len && cmd != RTM_DELADDR) { |
| 761 | peer = lcl; |
| 762 | addattr_l(&req.n, sizeof(req), IFA_ADDRESS, &lcl.data, lcl.bytelen); |
| 763 | } |
| 764 | if (req.ifa.ifa_prefixlen == 0) |
| 765 | req.ifa.ifa_prefixlen = lcl.bitlen; |
| 766 | |
| 767 | if (brd_len < 0 && cmd != RTM_DELADDR) { |
| 768 | inet_prefix brd; |
| 769 | int i; |
| 770 | if (req.ifa.ifa_family != AF_INET) { |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 771 | bb_error_msg("Broadcast can be set only for IPv4 addresses"); |
Glenn L McGrath | 9a2d272 | 2002-11-10 01:33:55 +0000 | [diff] [blame] | 772 | return -1; |
| 773 | } |
| 774 | brd = peer; |
| 775 | if (brd.bitlen <= 30) { |
| 776 | for (i=31; i>=brd.bitlen; i--) { |
| 777 | if (brd_len == -1) |
| 778 | brd.data[0] |= htonl(1<<(31-i)); |
| 779 | else |
| 780 | brd.data[0] &= ~htonl(1<<(31-i)); |
| 781 | } |
| 782 | addattr_l(&req.n, sizeof(req), IFA_BROADCAST, &brd.data, brd.bytelen); |
| 783 | brd_len = brd.bytelen; |
| 784 | } |
| 785 | } |
| 786 | if (!scoped && cmd != RTM_DELADDR) |
| 787 | req.ifa.ifa_scope = default_scope(&lcl); |
| 788 | |
| 789 | if (rtnl_open(&rth, 0) < 0) |
| 790 | exit(1); |
| 791 | |
| 792 | ll_init_map(&rth); |
| 793 | |
| 794 | if ((req.ifa.ifa_index = ll_name_to_index(d)) == 0) { |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 795 | bb_error_msg("Cannot find device \"%s\"", d); |
Glenn L McGrath | 9a2d272 | 2002-11-10 01:33:55 +0000 | [diff] [blame] | 796 | return -1; |
| 797 | } |
| 798 | |
| 799 | if (rtnl_talk(&rth, &req.n, 0, 0, NULL, NULL, NULL) < 0) |
| 800 | exit(2); |
| 801 | |
| 802 | exit(0); |
| 803 | } |
| 804 | |
Glenn L McGrath | 2626ef6 | 2002-12-02 01:40:05 +0000 | [diff] [blame] | 805 | extern int do_ipaddr(int argc, char **argv) |
Glenn L McGrath | 9a2d272 | 2002-11-10 01:33:55 +0000 | [diff] [blame] | 806 | { |
Glenn L McGrath | d66370c | 2003-01-13 21:40:38 +0000 | [diff] [blame] | 807 | const char *commands[] = { "add", "delete", "list", "show", "lst", "flush", 0 }; |
Glenn L McGrath | 2626ef6 | 2002-12-02 01:40:05 +0000 | [diff] [blame] | 808 | unsigned short command_num = 2; |
| 809 | |
| 810 | if (*argv) { |
| 811 | command_num = compare_string_array(commands, *argv); |
| 812 | } |
| 813 | switch (command_num) { |
| 814 | case 0: /* add */ |
| 815 | return ipaddr_modify(RTM_NEWADDR, argc-1, argv+1); |
| 816 | case 1: /* delete */ |
| 817 | return ipaddr_modify(RTM_DELADDR, argc-1, argv+1); |
| 818 | case 2: /* list */ |
| 819 | case 3: /* show */ |
| 820 | case 4: /* lst */ |
Glenn L McGrath | d66370c | 2003-01-13 21:40:38 +0000 | [diff] [blame] | 821 | return ipaddr_list_or_flush(argc-1, argv+1, 0); |
| 822 | case 5: /* flush */ |
| 823 | return ipaddr_list_or_flush(argc-1, argv+1, 1); |
Glenn L McGrath | 2626ef6 | 2002-12-02 01:40:05 +0000 | [diff] [blame] | 824 | } |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 825 | bb_error_msg_and_die("Unknown command %s", *argv); |
Glenn L McGrath | 9a2d272 | 2002-11-10 01:33:55 +0000 | [diff] [blame] | 826 | } |