Changeset 3232 in MondoRescue for branches/3.2/mindi-busybox/networking/libiproute
- Timestamp:
- Jan 1, 2014, 12:47:38 AM (10 years ago)
- Location:
- branches/3.2/mindi-busybox/networking/libiproute
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/3.2/mindi-busybox/networking/libiproute/ipaddress.c
r2725 r3232 163 163 } 164 164 #endif 165 /* IFLA_OPERSTATE was added to kernel with the same commit as IFF_DORMANT */ 166 #ifdef IFF_DORMANT 165 167 if (tb[IFLA_OPERSTATE]) { 166 168 static const char operstate_labels[] ALIGN1 = … … 170 172 *(uint8_t *)RTA_DATA(tb[IFLA_OPERSTATE]))); 171 173 } 174 #endif 172 175 if (G_filter.showqueue) 173 176 print_queuelen((char*)RTA_DATA(tb[IFLA_IFNAME])); … … 312 315 printf("brd %s ", 313 316 rt_addr_n2a(ifa->ifa_family, 314 RTA_DATA(rta_tb[IFA_BROADCAST]), 315 abuf, sizeof(abuf))); 317 RTA_DATA(rta_tb[IFA_BROADCAST]), 318 abuf, sizeof(abuf)) 319 ); 316 320 } 317 321 if (rta_tb[IFA_ANYCAST]) { 318 322 printf("any %s ", 319 323 rt_addr_n2a(ifa->ifa_family, 320 RTA_DATA(rta_tb[IFA_ANYCAST]), 321 abuf, sizeof(abuf))); 324 RTA_DATA(rta_tb[IFA_ANYCAST]), 325 abuf, sizeof(abuf)) 326 ); 322 327 } 323 328 printf("scope %s ", rtnl_rtscope_n2a(ifa->ifa_scope, b1)); -
branches/3.2/mindi-busybox/networking/libiproute/iplink.c
r2725 r3232 8 8 #include <net/if_packet.h> 9 9 #include <netpacket/packet.h> 10 #include <net /ethernet.h>10 #include <netinet/if_ether.h> 11 11 12 12 #include "ip_common.h" /* #include "libbb.h" is inside */ -
branches/3.2/mindi-busybox/networking/libiproute/iproute.c
r2725 r3232 32 32 //int typemask; - unused 33 33 //int tos, tosmask; - unused 34 int iif , iifmask;35 int oif , oifmask;34 int iif; 35 int oif; 36 36 //int realm, realmmask; - unused 37 37 //inet_prefix rprefsrc; - read-only … … 83 83 struct rtmsg *r = NLMSG_DATA(n); 84 84 int len = n->nlmsg_len; 85 struct rtattr * 85 struct rtattr *tb[RTA_MAX+1]; 86 86 char abuf[256]; 87 87 inet_prefix dst; … … 160 160 161 161 memset(tb, 0, sizeof(tb)); 162 memset(&src, 0, sizeof(src)); 163 memset(&dst, 0, sizeof(dst)); 162 164 parse_rtattr(tb, RTA_MAX, RTM_RTA(r), len); 165 166 if (tb[RTA_SRC]) { 167 src.bitlen = r->rtm_src_len; 168 src.bytelen = (r->rtm_family == AF_INET6 ? 16 : 4); 169 memcpy(src.data, RTA_DATA(tb[RTA_SRC]), src.bytelen); 170 } 171 if (tb[RTA_DST]) { 172 dst.bitlen = r->rtm_dst_len; 173 dst.bytelen = (r->rtm_family == AF_INET6 ? 16 : 4); 174 memcpy(dst.data, RTA_DATA(tb[RTA_DST]), dst.bytelen); 175 } 163 176 164 177 if (G_filter.rdst.family … … 183 196 return 0; 184 197 } 185 if (G_filter.flushb 186 && r->rtm_family == AF_INET6 187 && r->rtm_dst_len == 0 188 && r->rtm_type == RTN_UNREACHABLE 189 && tb[RTA_PRIORITY] 190 && *(int*)RTA_DATA(tb[RTA_PRIORITY]) == -1 191 ) { 192 return 0; 198 if (G_filter.oif != 0) { 199 if (!tb[RTA_OIF]) 200 return 0; 201 if (G_filter.oif != *(int*)RTA_DATA(tb[RTA_OIF])) 202 return 0; 193 203 } 194 204 195 205 if (G_filter.flushb) { 196 206 struct nlmsghdr *fn; 207 208 /* We are creating route flush commands */ 209 210 if (r->rtm_family == AF_INET6 211 && r->rtm_dst_len == 0 212 && r->rtm_type == RTN_UNREACHABLE 213 && tb[RTA_PRIORITY] 214 && *(int*)RTA_DATA(tb[RTA_PRIORITY]) == -1 215 ) { 216 return 0; 217 } 218 197 219 if (NLMSG_ALIGN(G_filter.flushp) + n->nlmsg_len > G_filter.flushe) { 198 220 if (flush_update()) 199 221 bb_error_msg_and_die("flush"); 200 222 } 201 fn = ( struct nlmsghdr*)(G_filter.flushb + NLMSG_ALIGN(G_filter.flushp));223 fn = (void*)(G_filter.flushb + NLMSG_ALIGN(G_filter.flushp)); 202 224 memcpy(fn, n, n->nlmsg_len); 203 225 fn->nlmsg_type = RTM_DELROUTE; … … 208 230 return 0; 209 231 } 232 233 /* We are printing routes */ 210 234 211 235 if (n->nlmsg_type == RTM_DELROUTE) { … … 258 282 abuf, sizeof(abuf))); 259 283 } 260 if (tb[RTA_OIF] && G_filter.oifmask != -1) {284 if (tb[RTA_OIF]) { 261 285 printf("dev %s ", ll_index_to_name(*(int*)RTA_DATA(tb[RTA_OIF]))); 262 286 } 287 288 /* Todo: parse & show "proto kernel", "scope link" here */ 263 289 264 290 if (tb[RTA_PREFSRC] && /*G_filter.rprefsrc.bitlen - always 0*/ 0 != host_len) { … … 293 319 } 294 320 } 295 if (tb[RTA_IIF] && G_filter.iif mask != -1) {321 if (tb[RTA_IIF] && G_filter.iif == 0) { 296 322 printf(" iif %s", ll_index_to_name(*(int*)RTA_DATA(tb[RTA_IIF]))); 297 323 } … … 414 440 } 415 441 if ((**argv < '0' || **argv > '9') 416 && rtnl_rtntype_a2n(&type, *argv) == 0) { 442 && rtnl_rtntype_a2n(&type, *argv) == 0 443 ) { 417 444 NEXT_ARG(); 418 445 req.r.rtm_type = type; … … 663 690 idx = xll_name_to_index(id); 664 691 G_filter.iif = idx; 665 G_filter.iifmask = -1;666 692 } 667 693 if (od) { 668 694 idx = xll_name_to_index(od); 669 695 G_filter.oif = idx; 670 G_filter.oifmask = -1;671 696 } 672 697 } -
branches/3.2/mindi-busybox/networking/libiproute/iprule.c
r2725 r3232 74 74 if (r->rtm_src_len != host_len) { 75 75 printf("%s/%u", rt_addr_n2a(r->rtm_family, 76 77 76 RTA_DATA(tb[RTA_SRC]), 77 abuf, sizeof(abuf)), 78 78 r->rtm_src_len 79 79 ); 80 80 } else { 81 81 fputs(format_host(r->rtm_family, 82 RTA_PAYLOAD(tb[RTA_SRC]), 83 RTA_DATA(tb[RTA_SRC]), 84 abuf, sizeof(abuf)), stdout); 82 RTA_PAYLOAD(tb[RTA_SRC]), 83 RTA_DATA(tb[RTA_SRC]), 84 abuf, sizeof(abuf)), 85 stdout 86 ); 85 87 } 86 88 } else if (r->rtm_src_len) { -
branches/3.2/mindi-busybox/networking/libiproute/iptunnel.c
r2725 r3232 439 439 if (p->iph.tos & ~1) 440 440 printf("%c%s ", p->iph.tos & 1 ? '/' : ' ', 441 441 rtnl_dsfield_n2a(p->iph.tos & ~1, b1)); 442 442 } 443 443 if (!(p->iph.frag_off & htons(IP_DF))) -
branches/3.2/mindi-busybox/networking/libiproute/libnetlink.c
r2725 r3232 56 56 } 57 57 58 //TODO: pass rth->fd instead of full rth? 58 59 int FAST_FUNC rtnl_send(struct rtnl_handle *rth, char *buf, int len) 59 60 { … … 393 394 tb[rta->rta_type] = rta; 394 395 } 395 rta = RTA_NEXT(rta, len);396 rta = RTA_NEXT(rta, len); 396 397 } 397 398 if (len) { -
branches/3.2/mindi-busybox/networking/libiproute/ll_proto.c
r2725 r3232 13 13 #include "utils.h" 14 14 15 #if defined(__GLIBC__) && __GLIBC__ >=2 && __GLIBC_MINOR__ >= 1 16 #include <net/ethernet.h> 17 #else 18 #include <linux/if_ether.h> 19 #endif 15 #include <netinet/if_ether.h> 20 16 21 #if !ENABLE_WERROR 22 #warning de-bloat 23 #endif 24 /* Before re-enabling this, please (1) conditionalize exotic protocols 25 * on CONFIG_something, and (2) decouple strings and numbers 26 * (use llproto_ids[] = n,n,n..; and llproto_names[] = "loop\0" "pup\0" ...;) 27 */ 17 /* Please conditionalize exotic protocols on CONFIG_something */ 28 18 29 #define __PF(f,n) { ETH_P_##f, #n }, 30 static struct { 31 int id; 32 const char *name; 33 } llproto_names[] = { 19 static const uint16_t llproto_ids[] = { 20 #define __PF(f,n) ETH_P_##f, 34 21 __PF(LOOP,loop) 35 22 __PF(PUP,pup) … … 91 78 #endif 92 79 93 { 0x8100, "802.1Q" },94 { ETH_P_IP, "ipv4" }, 80 0x8100, 81 ETH_P_IP 95 82 }; 83 #undef __PF 84 85 /* Keep declarations above and below in sync! */ 86 87 static const char llproto_names[] = 88 #define __PF(f,n) #n "\0" 89 __PF(LOOP,loop) 90 __PF(PUP,pup) 91 #ifdef ETH_P_PUPAT 92 __PF(PUPAT,pupat) 93 #endif 94 __PF(IP,ip) 95 __PF(X25,x25) 96 __PF(ARP,arp) 97 __PF(BPQ,bpq) 98 #ifdef ETH_P_IEEEPUP 99 __PF(IEEEPUP,ieeepup) 100 #endif 101 #ifdef ETH_P_IEEEPUPAT 102 __PF(IEEEPUPAT,ieeepupat) 103 #endif 104 __PF(DEC,dec) 105 __PF(DNA_DL,dna_dl) 106 __PF(DNA_RC,dna_rc) 107 __PF(DNA_RT,dna_rt) 108 __PF(LAT,lat) 109 __PF(DIAG,diag) 110 __PF(CUST,cust) 111 __PF(SCA,sca) 112 __PF(RARP,rarp) 113 __PF(ATALK,atalk) 114 __PF(AARP,aarp) 115 __PF(IPX,ipx) 116 __PF(IPV6,ipv6) 117 #ifdef ETH_P_PPP_DISC 118 __PF(PPP_DISC,ppp_disc) 119 #endif 120 #ifdef ETH_P_PPP_SES 121 __PF(PPP_SES,ppp_ses) 122 #endif 123 #ifdef ETH_P_ATMMPOA 124 __PF(ATMMPOA,atmmpoa) 125 #endif 126 #ifdef ETH_P_ATMFATE 127 __PF(ATMFATE,atmfate) 128 #endif 129 130 __PF(802_3,802_3) 131 __PF(AX25,ax25) 132 __PF(ALL,all) 133 __PF(802_2,802_2) 134 __PF(SNAP,snap) 135 __PF(DDCMP,ddcmp) 136 __PF(WAN_PPP,wan_ppp) 137 __PF(PPP_MP,ppp_mp) 138 __PF(LOCALTALK,localtalk) 139 __PF(PPPTALK,ppptalk) 140 __PF(TR_802_2,tr_802_2) 141 __PF(MOBITEX,mobitex) 142 __PF(CONTROL,control) 143 __PF(IRDA,irda) 144 #ifdef ETH_P_ECONET 145 __PF(ECONET,econet) 146 #endif 147 148 "802.1Q" "\0" 149 "ipv4" "\0" 150 ; 96 151 #undef __PF 97 152 … … 101 156 unsigned i; 102 157 id = ntohs(id); 103 for (i = 0; i < ARRAY_SIZE(llproto_ names); i++) {104 if (llproto_names[i].id== id)105 return llproto_names[i].name;158 for (i = 0; i < ARRAY_SIZE(llproto_ids); i++) { 159 if (llproto_ids[i] == id) 160 return nth_string(llproto_names, i); 106 161 } 107 snprintf(buf, len, "[% d]", id);162 snprintf(buf, len, "[%u]", id); 108 163 return buf; 109 164 } … … 112 167 { 113 168 unsigned i; 114 for (i = 0; i < ARRAY_SIZE(llproto_names); i++) { 115 if (strcasecmp(llproto_names[i].name, buf) == 0) { 116 i = llproto_names[i].id; 117 goto good; 118 } 169 const char *name = llproto_names; 170 for (i = 0; i < ARRAY_SIZE(llproto_ids); i++) { 171 if (strcasecmp(name, buf) == 0) { 172 i = llproto_ids[i]; 173 goto good; 174 } 175 name += strlen(name) + 1; 119 176 } 177 errno = 0; 120 178 i = bb_strtou(buf, NULL, 0); 121 179 if (errno || i > 0xffff) -
branches/3.2/mindi-busybox/networking/libiproute/ll_types.c
r2725 r3232 8 8 * Authors: Alexey Kuznetsov, <kuznet@ms2.inr.ac.ru> 9 9 */ 10 #include <sys/socket.h> /* linux/if_arp.h needs it on some systems */ 10 11 #include <arpa/inet.h> 11 12 #include <linux/if_arp.h> -
branches/3.2/mindi-busybox/networking/libiproute/utils.c
r2725 r3232 84 84 } 85 85 86 addr->family = AF_INET;87 86 if (family != AF_UNSPEC && family != AF_INET) 88 87 return -1; 88 89 /* Try to parse it as IPv4 */ 90 addr->family = AF_INET; 91 #if 0 /* Doesn't handle e.g. "10.10", for example, "ip r l root 10.10/16" */ 89 92 if (inet_pton(AF_INET, name, addr->data) <= 0) 90 93 return -1; 94 #else 95 { 96 unsigned i = 0; 97 unsigned n = 0; 98 const char *cp = name - 1; 99 while (*++cp) { 100 if ((unsigned char)(*cp - '0') <= 9) { 101 n = 10 * n + (unsigned char)(*cp - '0'); 102 if (n >= 256) 103 return -1; 104 ((uint8_t*)addr->data)[i] = n; 105 continue; 106 } 107 if (*cp == '.' && ++i <= 3) { 108 n = 0; 109 continue; 110 } 111 return -1; 112 } 113 } 114 #endif 91 115 addr->bytelen = 4; 92 116 addr->bitlen = -1; 117 93 118 return 0; 94 119 } 95 120 96 static int get_prefix_1(inet_prefix *dst, char *arg, int family) 97 { 98 int err; 99 unsigned plen; 121 static void get_prefix_1(inet_prefix *dst, char *arg, int family) 122 { 100 123 char *slash; 101 124 … … 109 132 /*dst->bytelen = 0; - done by memset */ 110 133 /*dst->bitlen = 0;*/ 111 return 0;134 return; 112 135 } 113 136 … … 115 138 if (slash) 116 139 *slash = '\0'; 117 err = get_addr_1(dst, arg, family); 118 if ( err== 0) {140 141 if (get_addr_1(dst, arg, family) == 0) { 119 142 dst->bitlen = (dst->family == AF_INET6) ? 128 : 32; 120 143 if (slash) { 144 unsigned plen; 121 145 inet_prefix netmask_pfx; 122 146 … … 124 148 plen = bb_strtou(slash + 1, NULL, 0); 125 149 if ((errno || plen > dst->bitlen) 126 && (get_addr_1(&netmask_pfx, slash + 1, family))) 127 err = -1; 128 else if (netmask_pfx.family == AF_INET) { 150 && get_addr_1(&netmask_pfx, slash + 1, family) != 0 151 ) { 152 goto bad; 153 } 154 if (netmask_pfx.family == AF_INET) { 129 155 /* fill in prefix length of dotted quad */ 130 156 uint32_t mask = ntohl(netmask_pfx.data[0]); … … 132 158 133 159 /* a valid netmask must be 2^n - 1 */ 134 if (!(host & (host + 1))) { 135 for (plen = 0; mask; mask <<= 1) 136 ++plen; 137 if (plen <= dst->bitlen) { 138 dst->bitlen = plen; 139 /* dst->flags |= PREFIXLEN_SPECIFIED; */ 140 } else 141 err = -1; 142 } else 143 err = -1; 144 } else { 145 /* plain prefix */ 146 dst->bitlen = plen; 147 } 148 } 149 } 160 if (host & (host + 1)) 161 goto bad; 162 163 for (plen = 0; mask; mask <<= 1) 164 ++plen; 165 if (plen > dst->bitlen) 166 goto bad; 167 /* dst->flags |= PREFIXLEN_SPECIFIED; */ 168 } 169 dst->bitlen = plen; 170 } 171 } 172 150 173 if (slash) 151 174 *slash = '/'; 152 return err; 175 return; 176 bad: 177 bb_error_msg_and_die("an %s %s is expected rather than \"%s\"", "inet", "prefix", arg); 153 178 } 154 179 … … 164 189 } 165 190 166 intget_prefix(inet_prefix *dst, char *arg, int family)191 void get_prefix(inet_prefix *dst, char *arg, int family) 167 192 { 168 193 if (family == AF_PACKET) { 169 194 bb_error_msg_and_die("\"%s\" may be inet %s, but it is not allowed in this context", arg, "prefix"); 170 195 } 171 if (get_prefix_1(dst, arg, family)) { 172 bb_error_msg_and_die("an %s %s is expected rather than \"%s\"", "inet", "prefix", arg); 173 } 174 return 0; 196 get_prefix_1(dst, arg, family); 175 197 } 176 198 … … 205 227 } 206 228 207 int inet_addr_match( inet_prefix *a,inet_prefix *b, int bits)208 { 209 uint32_t *a1 = a->data;210 uint32_t *a2 = b->data;229 int inet_addr_match(const inet_prefix *a, const inet_prefix *b, int bits) 230 { 231 const uint32_t *a1 = a->data; 232 const uint32_t *a2 = b->data; 211 233 int words = bits >> 5; 212 234 -
branches/3.2/mindi-busybox/networking/libiproute/utils.h
r2725 r3232 59 59 extern uint32_t get_addr32(char *name); 60 60 extern int get_addr_1(inet_prefix *dst, char *arg, int family); 61 /*extern intget_prefix_1(inet_prefix *dst, char *arg, int family);*/61 /*extern void get_prefix_1(inet_prefix *dst, char *arg, int family);*/ 62 62 extern int get_addr(inet_prefix *dst, char *arg, int family); 63 extern intget_prefix(inet_prefix *dst, char *arg, int family);63 extern void get_prefix(inet_prefix *dst, char *arg, int family); 64 64 65 65 extern unsigned get_unsigned(char *arg, const char *errmsg); … … 78 78 void duparg(const char *, const char *) NORETURN; 79 79 void duparg2(const char *, const char *) NORETURN; 80 int inet_addr_match( inet_prefix *a,inet_prefix *b, int bits);80 int inet_addr_match(const inet_prefix *a, const inet_prefix *b, int bits); 81 81 82 82 const char *dnet_ntop(int af, const void *addr, char *str, size_t len);
Note:
See TracChangeset
for help on using the changeset viewer.