aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHarvey Harrison <harvey.harrison@gmail.com>2009-03-28 11:38:31 -0400
committerDavid S. Miller <davem@davemloft.net>2009-03-29 02:55:58 -0400
commite7557af56a576762a655f1aaaded253ad14c5958 (patch)
tree7594980090f4c6b8fcfe1be554d94096b9d80db3
parentf940964901aa69e28ce729d7614061d014184472 (diff)
netpoll: store local and remote ip in net-endian
Allows for the removal of byteswapping in some places and the removal of HIPQUAD (replaced by %pI4). Signed-off-by: Harvey Harrison <harvey.harrison@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r--drivers/net/netconsole.c10
-rw-r--r--include/linux/netpoll.h2
-rw-r--r--net/core/netpoll.c31
3 files changed, 20 insertions, 23 deletions
diff --git a/drivers/net/netconsole.c b/drivers/net/netconsole.c
index d304d38cd5d1..eceadf787a67 100644
--- a/drivers/net/netconsole.c
+++ b/drivers/net/netconsole.c
@@ -294,14 +294,12 @@ static ssize_t show_remote_port(struct netconsole_target *nt, char *buf)
294 294
295static ssize_t show_local_ip(struct netconsole_target *nt, char *buf) 295static ssize_t show_local_ip(struct netconsole_target *nt, char *buf)
296{ 296{
297 return snprintf(buf, PAGE_SIZE, "%d.%d.%d.%d\n", 297 return snprintf(buf, PAGE_SIZE, "%pI4\n", &nt->np.local_ip);
298 HIPQUAD(nt->np.local_ip));
299} 298}
300 299
301static ssize_t show_remote_ip(struct netconsole_target *nt, char *buf) 300static ssize_t show_remote_ip(struct netconsole_target *nt, char *buf)
302{ 301{
303 return snprintf(buf, PAGE_SIZE, "%d.%d.%d.%d\n", 302 return snprintf(buf, PAGE_SIZE, "%pI4\n", &nt->np.remote_ip);
304 HIPQUAD(nt->np.remote_ip));
305} 303}
306 304
307static ssize_t show_local_mac(struct netconsole_target *nt, char *buf) 305static ssize_t show_local_mac(struct netconsole_target *nt, char *buf)
@@ -438,7 +436,7 @@ static ssize_t store_local_ip(struct netconsole_target *nt,
438 return -EINVAL; 436 return -EINVAL;
439 } 437 }
440 438
441 nt->np.local_ip = ntohl(in_aton(buf)); 439 nt->np.local_ip = in_aton(buf);
442 440
443 return strnlen(buf, count); 441 return strnlen(buf, count);
444} 442}
@@ -454,7 +452,7 @@ static ssize_t store_remote_ip(struct netconsole_target *nt,
454 return -EINVAL; 452 return -EINVAL;
455 } 453 }
456 454
457 nt->np.remote_ip = ntohl(in_aton(buf)); 455 nt->np.remote_ip = in_aton(buf);
458 456
459 return strnlen(buf, count); 457 return strnlen(buf, count);
460} 458}
diff --git a/include/linux/netpoll.h b/include/linux/netpoll.h
index de99025f2c5d..2524267210d3 100644
--- a/include/linux/netpoll.h
+++ b/include/linux/netpoll.h
@@ -18,7 +18,7 @@ struct netpoll {
18 const char *name; 18 const char *name;
19 void (*rx_hook)(struct netpoll *, int, char *, int); 19 void (*rx_hook)(struct netpoll *, int, char *, int);
20 20
21 u32 local_ip, remote_ip; 21 __be32 local_ip, remote_ip;
22 u16 local_port, remote_port; 22 u16 local_port, remote_port;
23 u8 remote_mac[ETH_ALEN]; 23 u8 remote_mac[ETH_ALEN];
24}; 24};
diff --git a/net/core/netpoll.c b/net/core/netpoll.c
index 755414cd49d1..b5873bdff612 100644
--- a/net/core/netpoll.c
+++ b/net/core/netpoll.c
@@ -345,8 +345,8 @@ void netpoll_send_udp(struct netpoll *np, const char *msg, int len)
345 udph->dest = htons(np->remote_port); 345 udph->dest = htons(np->remote_port);
346 udph->len = htons(udp_len); 346 udph->len = htons(udp_len);
347 udph->check = 0; 347 udph->check = 0;
348 udph->check = csum_tcpudp_magic(htonl(np->local_ip), 348 udph->check = csum_tcpudp_magic(np->local_ip,
349 htonl(np->remote_ip), 349 np->remote_ip,
350 udp_len, IPPROTO_UDP, 350 udp_len, IPPROTO_UDP,
351 csum_partial(udph, udp_len, 0)); 351 csum_partial(udph, udp_len, 0));
352 if (udph->check == 0) 352 if (udph->check == 0)
@@ -365,8 +365,8 @@ void netpoll_send_udp(struct netpoll *np, const char *msg, int len)
365 iph->ttl = 64; 365 iph->ttl = 64;
366 iph->protocol = IPPROTO_UDP; 366 iph->protocol = IPPROTO_UDP;
367 iph->check = 0; 367 iph->check = 0;
368 put_unaligned(htonl(np->local_ip), &(iph->saddr)); 368 put_unaligned(np->local_ip, &(iph->saddr));
369 put_unaligned(htonl(np->remote_ip), &(iph->daddr)); 369 put_unaligned(np->remote_ip, &(iph->daddr));
370 iph->check = ip_fast_csum((unsigned char *)iph, iph->ihl); 370 iph->check = ip_fast_csum((unsigned char *)iph, iph->ihl);
371 371
372 eth = (struct ethhdr *) skb_push(skb, ETH_HLEN); 372 eth = (struct ethhdr *) skb_push(skb, ETH_HLEN);
@@ -424,7 +424,7 @@ static void arp_reply(struct sk_buff *skb)
424 memcpy(&tip, arp_ptr, 4); 424 memcpy(&tip, arp_ptr, 4);
425 425
426 /* Should we ignore arp? */ 426 /* Should we ignore arp? */
427 if (tip != htonl(np->local_ip) || 427 if (tip != np->local_ip ||
428 ipv4_is_loopback(tip) || ipv4_is_multicast(tip)) 428 ipv4_is_loopback(tip) || ipv4_is_multicast(tip))
429 return; 429 return;
430 430
@@ -533,9 +533,9 @@ int __netpoll_rx(struct sk_buff *skb)
533 goto out; 533 goto out;
534 if (checksum_udp(skb, uh, ulen, iph->saddr, iph->daddr)) 534 if (checksum_udp(skb, uh, ulen, iph->saddr, iph->daddr))
535 goto out; 535 goto out;
536 if (np->local_ip && np->local_ip != ntohl(iph->daddr)) 536 if (np->local_ip && np->local_ip != iph->daddr)
537 goto out; 537 goto out;
538 if (np->remote_ip && np->remote_ip != ntohl(iph->saddr)) 538 if (np->remote_ip && np->remote_ip != iph->saddr)
539 goto out; 539 goto out;
540 if (np->local_port && np->local_port != ntohs(uh->dest)) 540 if (np->local_port && np->local_port != ntohs(uh->dest))
541 goto out; 541 goto out;
@@ -560,14 +560,14 @@ void netpoll_print_options(struct netpoll *np)
560{ 560{
561 printk(KERN_INFO "%s: local port %d\n", 561 printk(KERN_INFO "%s: local port %d\n",
562 np->name, np->local_port); 562 np->name, np->local_port);
563 printk(KERN_INFO "%s: local IP %d.%d.%d.%d\n", 563 printk(KERN_INFO "%s: local IP %pI4\n",
564 np->name, HIPQUAD(np->local_ip)); 564 np->name, &np->local_ip);
565 printk(KERN_INFO "%s: interface %s\n", 565 printk(KERN_INFO "%s: interface %s\n",
566 np->name, np->dev_name); 566 np->name, np->dev_name);
567 printk(KERN_INFO "%s: remote port %d\n", 567 printk(KERN_INFO "%s: remote port %d\n",
568 np->name, np->remote_port); 568 np->name, np->remote_port);
569 printk(KERN_INFO "%s: remote IP %d.%d.%d.%d\n", 569 printk(KERN_INFO "%s: remote IP %pI4\n",
570 np->name, HIPQUAD(np->remote_ip)); 570 np->name, &np->remote_ip);
571 printk(KERN_INFO "%s: remote ethernet address %pM\n", 571 printk(KERN_INFO "%s: remote ethernet address %pM\n",
572 np->name, np->remote_mac); 572 np->name, np->remote_mac);
573} 573}
@@ -589,7 +589,7 @@ int netpoll_parse_options(struct netpoll *np, char *opt)
589 if ((delim = strchr(cur, '/')) == NULL) 589 if ((delim = strchr(cur, '/')) == NULL)
590 goto parse_failed; 590 goto parse_failed;
591 *delim = 0; 591 *delim = 0;
592 np->local_ip = ntohl(in_aton(cur)); 592 np->local_ip = in_aton(cur);
593 cur = delim; 593 cur = delim;
594 } 594 }
595 cur++; 595 cur++;
@@ -618,7 +618,7 @@ int netpoll_parse_options(struct netpoll *np, char *opt)
618 if ((delim = strchr(cur, '/')) == NULL) 618 if ((delim = strchr(cur, '/')) == NULL)
619 goto parse_failed; 619 goto parse_failed;
620 *delim = 0; 620 *delim = 0;
621 np->remote_ip = ntohl(in_aton(cur)); 621 np->remote_ip = in_aton(cur);
622 cur = delim + 1; 622 cur = delim + 1;
623 623
624 if (*cur != 0) { 624 if (*cur != 0) {
@@ -759,10 +759,9 @@ int netpoll_setup(struct netpoll *np)
759 goto release; 759 goto release;
760 } 760 }
761 761
762 np->local_ip = ntohl(in_dev->ifa_list->ifa_local); 762 np->local_ip = in_dev->ifa_list->ifa_local;
763 rcu_read_unlock(); 763 rcu_read_unlock();
764 printk(KERN_INFO "%s: local IP %d.%d.%d.%d\n", 764 printk(KERN_INFO "%s: local IP %pI4\n", np->name, &np->local_ip);
765 np->name, HIPQUAD(np->local_ip));
766 } 765 }
767 766
768 if (np->rx_hook) { 767 if (np->rx_hook) {