Magellan Linux

Diff of /trunk/mkinitrd-magellan/busybox/networking/libiproute/ipaddress.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 983 by niro, Fri Apr 24 18:33:46 2009 UTC revision 984 by niro, Sun May 30 11:32:42 2010 UTC
# Line 83  static void print_queuelen(char *name) Line 83  static void print_queuelen(char *name)
83   return;   return;
84    
85   memset(&ifr, 0, sizeof(ifr));   memset(&ifr, 0, sizeof(ifr));
86   strncpy(ifr.ifr_name, name, sizeof(ifr.ifr_name));   strncpy_IFNAMSIZ(ifr.ifr_name, name);
87   if (ioctl_or_warn(s, SIOCGIFTXQLEN, &ifr) < 0) {   if (ioctl_or_warn(s, SIOCGIFTXQLEN, &ifr) < 0) {
88   close(s);   close(s);
89   return;   return;
# Line 94  static void print_queuelen(char *name) Line 94  static void print_queuelen(char *name)
94   printf("qlen %d", ifr.ifr_qlen);   printf("qlen %d", ifr.ifr_qlen);
95  }  }
96    
97  static int print_linkinfo(const struct nlmsghdr *n)  static NOINLINE int print_linkinfo(const struct nlmsghdr *n)
98  {  {
99   struct ifinfomsg *ifi = NLMSG_DATA(n);   struct ifinfomsg *ifi = NLMSG_DATA(n);
100   struct rtattr * tb[IFLA_MAX+1];   struct rtattr *tb[IFLA_MAX+1];
101   int len = n->nlmsg_len;   int len = n->nlmsg_len;
  unsigned m_flag = 0;  
102    
103   if (n->nlmsg_type != RTM_NEWLINK && n->nlmsg_type != RTM_DELLINK)   if (n->nlmsg_type != RTM_NEWLINK && n->nlmsg_type != RTM_DELLINK)
104   return 0;   return 0;
# Line 130  static int print_linkinfo(const struct n Line 129  static int print_linkinfo(const struct n
129   printf("Deleted ");   printf("Deleted ");
130    
131   printf("%d: %s", ifi->ifi_index,   printf("%d: %s", ifi->ifi_index,
132   tb[IFLA_IFNAME] ? (char*)RTA_DATA(tb[IFLA_IFNAME]) : "<nil>");   /*tb[IFLA_IFNAME] ? (char*)RTA_DATA(tb[IFLA_IFNAME]) : "<nil>" - we checked tb[IFLA_IFNAME] above*/
133     (char*)RTA_DATA(tb[IFLA_IFNAME])
134   if (tb[IFLA_LINK]) {   );
135   SPRINT_BUF(b1);  
136   int iflink = *(int*)RTA_DATA(tb[IFLA_LINK]);   {
137   if (iflink == 0)   unsigned m_flag = 0;
138   printf("@NONE: ");   if (tb[IFLA_LINK]) {
139   else {   SPRINT_BUF(b1);
140   printf("@%s: ", ll_idx_n2a(iflink, b1));   int iflink = *(int*)RTA_DATA(tb[IFLA_LINK]);
141   m_flag = ll_index_to_flags(iflink);   if (iflink == 0)
142   m_flag = !(m_flag & IFF_UP);   printf("@NONE: ");
143     else {
144     printf("@%s: ", ll_idx_n2a(iflink, b1));
145     m_flag = ll_index_to_flags(iflink);
146     m_flag = !(m_flag & IFF_UP);
147     }
148     } else {
149     printf(": ");
150   }   }
151   } else {   print_link_flags(ifi->ifi_flags, m_flag);
  printf(": ");  
152   }   }
  print_link_flags(ifi->ifi_flags, m_flag);  
153    
154   if (tb[IFLA_MTU])   if (tb[IFLA_MTU])
155   printf("mtu %u ", *(int*)RTA_DATA(tb[IFLA_MTU]));   printf("mtu %u ", *(int*)RTA_DATA(tb[IFLA_MTU]));
# Line 162  static int print_linkinfo(const struct n Line 166  static int print_linkinfo(const struct n
166    
167   if (!filter.family || filter.family == AF_PACKET) {   if (!filter.family || filter.family == AF_PACKET) {
168   SPRINT_BUF(b1);   SPRINT_BUF(b1);
169   printf("%c    link/%s ", _SL_, ll_type_n2a(ifi->ifi_type, b1, sizeof(b1)));   printf("%c    link/%s ", _SL_, ll_type_n2a(ifi->ifi_type, b1));
170    
171   if (tb[IFLA_ADDRESS]) {   if (tb[IFLA_ADDRESS]) {
172   fputs(ll_addr_n2a(RTA_DATA(tb[IFLA_ADDRESS]),   fputs(ll_addr_n2a(RTA_DATA(tb[IFLA_ADDRESS]),
# Line 182  static int print_linkinfo(const struct n Line 186  static int print_linkinfo(const struct n
186   }   }
187   }   }
188   bb_putchar('\n');   bb_putchar('\n');
189   /*fflush(stdout);*/   /*fflush_all();*/
190   return 0;   return 0;
191  }  }
192    
# Line 196  static int flush_update(void) Line 200  static int flush_update(void)
200   return 0;   return 0;
201  }  }
202    
203  static int print_addrinfo(const struct sockaddr_nl *who UNUSED_PARAM,  static int FAST_FUNC print_addrinfo(const struct sockaddr_nl *who UNUSED_PARAM,
204   struct nlmsghdr *n, void *arg UNUSED_PARAM)   struct nlmsghdr *n, void *arg UNUSED_PARAM)
205  {  {
206   struct ifaddrmsg *ifa = NLMSG_DATA(n);   struct ifaddrmsg *ifa = NLMSG_DATA(n);
# Line 280  static int print_addrinfo(const struct s Line 284  static int print_addrinfo(const struct s
284    
285   if (rta_tb[IFA_LOCAL]) {   if (rta_tb[IFA_LOCAL]) {
286   fputs(rt_addr_n2a(ifa->ifa_family,   fputs(rt_addr_n2a(ifa->ifa_family,
       RTA_PAYLOAD(rta_tb[IFA_LOCAL]),  
287        RTA_DATA(rta_tb[IFA_LOCAL]),        RTA_DATA(rta_tb[IFA_LOCAL]),
288        abuf, sizeof(abuf)), stdout);        abuf, sizeof(abuf)), stdout);
289    
290   if (rta_tb[IFA_ADDRESS] == NULL ||   if (rta_tb[IFA_ADDRESS] == NULL
291      memcmp(RTA_DATA(rta_tb[IFA_ADDRESS]), RTA_DATA(rta_tb[IFA_LOCAL]), 4) == 0) {   || memcmp(RTA_DATA(rta_tb[IFA_ADDRESS]), RTA_DATA(rta_tb[IFA_LOCAL]), 4) == 0
292     ) {
293   printf("/%d ", ifa->ifa_prefixlen);   printf("/%d ", ifa->ifa_prefixlen);
294   } else {   } else {
295   printf(" peer %s/%d ",   printf(" peer %s/%d ",
296   rt_addr_n2a(ifa->ifa_family,   rt_addr_n2a(ifa->ifa_family,
     RTA_PAYLOAD(rta_tb[IFA_ADDRESS]),  
297      RTA_DATA(rta_tb[IFA_ADDRESS]),      RTA_DATA(rta_tb[IFA_ADDRESS]),
298      abuf, sizeof(abuf)),      abuf, sizeof(abuf)),
299   ifa->ifa_prefixlen);   ifa->ifa_prefixlen);
# Line 300  static int print_addrinfo(const struct s Line 303  static int print_addrinfo(const struct s
303   if (rta_tb[IFA_BROADCAST]) {   if (rta_tb[IFA_BROADCAST]) {
304   printf("brd %s ",   printf("brd %s ",
305   rt_addr_n2a(ifa->ifa_family,   rt_addr_n2a(ifa->ifa_family,
     RTA_PAYLOAD(rta_tb[IFA_BROADCAST]),  
306      RTA_DATA(rta_tb[IFA_BROADCAST]),      RTA_DATA(rta_tb[IFA_BROADCAST]),
307      abuf, sizeof(abuf)));      abuf, sizeof(abuf)));
308   }   }
309   if (rta_tb[IFA_ANYCAST]) {   if (rta_tb[IFA_ANYCAST]) {
310   printf("any %s ",   printf("any %s ",
311   rt_addr_n2a(ifa->ifa_family,   rt_addr_n2a(ifa->ifa_family,
     RTA_PAYLOAD(rta_tb[IFA_ANYCAST]),  
312      RTA_DATA(rta_tb[IFA_ANYCAST]),      RTA_DATA(rta_tb[IFA_ANYCAST]),
313      abuf, sizeof(abuf)));      abuf, sizeof(abuf)));
314   }   }
315   printf("scope %s ", rtnl_rtscope_n2a(ifa->ifa_scope, b1, sizeof(b1)));   printf("scope %s ", rtnl_rtscope_n2a(ifa->ifa_scope, b1));
316   if (ifa->ifa_flags & IFA_F_SECONDARY) {   if (ifa->ifa_flags & IFA_F_SECONDARY) {
317   ifa->ifa_flags &= ~IFA_F_SECONDARY;   ifa->ifa_flags &= ~IFA_F_SECONDARY;
318   printf("secondary ");   printf("secondary ");
# Line 347  static int print_addrinfo(const struct s Line 348  static int print_addrinfo(const struct s
348   printf("       %s", buf);   printf("       %s", buf);
349   }   }
350   bb_putchar('\n');   bb_putchar('\n');
351   /*fflush(stdout);*/   /*fflush_all();*/
352   return 0;   return 0;
353  }  }
354    
355    
356  struct nlmsg_list  struct nlmsg_list {
 {  
357   struct nlmsg_list *next;   struct nlmsg_list *next;
358   struct nlmsghdr  h;   struct nlmsghdr  h;
359  };  };
# Line 380  static int print_selected_addrinfo(int i Line 380  static int print_selected_addrinfo(int i
380  }  }
381    
382    
383  static int store_nlmsg(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)  static int FAST_FUNC store_nlmsg(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
384  {  {
385   struct nlmsg_list **linfo = (struct nlmsg_list**)arg;   struct nlmsg_list **linfo = (struct nlmsg_list**)arg;
386   struct nlmsg_list *h;   struct nlmsg_list *h;
387   struct nlmsg_list **lp;   struct nlmsg_list **lp;
388    
389   h = malloc(n->nlmsg_len+sizeof(void*));   h = xzalloc(n->nlmsg_len + sizeof(void*));
  if (h == NULL)  
  return -1;  
390    
391   memcpy(&h->h, n, n->nlmsg_len);   memcpy(&h->h, n, n->nlmsg_len);
392   h->next = NULL;   /*h->next = NULL; - xzalloc did it */
393    
394   for (lp = linfo; *lp; lp = &(*lp)->next)   for (lp = linfo; *lp; lp = &(*lp)->next)
395   continue;   continue;
# Line 430  int ipaddr_list_or_flush(char **argv, in Line 428  int ipaddr_list_or_flush(char **argv, in
428   bb_error_msg_and_die(bb_msg_requires_arg, "flush");   bb_error_msg_and_die(bb_msg_requires_arg, "flush");
429   }   }
430   if (filter.family == AF_PACKET) {   if (filter.family == AF_PACKET) {
431   bb_error_msg_and_die("cannot flush link addresses");   bb_error_msg_and_die("can't flush link addresses");
432   }   }
433   }   }
434    

Legend:
Removed from v.983  
changed lines
  Added in v.984