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>
This commit is contained in:
parent
f940964901
commit
e7557af56a
@ -294,14 +294,12 @@ static ssize_t show_remote_port(struct netconsole_target *nt, char *buf)
|
|||||||
|
|
||||||
static ssize_t show_local_ip(struct netconsole_target *nt, char *buf)
|
static ssize_t show_local_ip(struct netconsole_target *nt, char *buf)
|
||||||
{
|
{
|
||||||
return snprintf(buf, PAGE_SIZE, "%d.%d.%d.%d\n",
|
return snprintf(buf, PAGE_SIZE, "%pI4\n", &nt->np.local_ip);
|
||||||
HIPQUAD(nt->np.local_ip));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static ssize_t show_remote_ip(struct netconsole_target *nt, char *buf)
|
static ssize_t show_remote_ip(struct netconsole_target *nt, char *buf)
|
||||||
{
|
{
|
||||||
return snprintf(buf, PAGE_SIZE, "%d.%d.%d.%d\n",
|
return snprintf(buf, PAGE_SIZE, "%pI4\n", &nt->np.remote_ip);
|
||||||
HIPQUAD(nt->np.remote_ip));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static ssize_t show_local_mac(struct netconsole_target *nt, char *buf)
|
static 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,
|
|||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
nt->np.local_ip = ntohl(in_aton(buf));
|
nt->np.local_ip = in_aton(buf);
|
||||||
|
|
||||||
return strnlen(buf, count);
|
return strnlen(buf, count);
|
||||||
}
|
}
|
||||||
@ -454,7 +452,7 @@ static ssize_t store_remote_ip(struct netconsole_target *nt,
|
|||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
nt->np.remote_ip = ntohl(in_aton(buf));
|
nt->np.remote_ip = in_aton(buf);
|
||||||
|
|
||||||
return strnlen(buf, count);
|
return strnlen(buf, count);
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,7 @@ struct netpoll {
|
|||||||
const char *name;
|
const char *name;
|
||||||
void (*rx_hook)(struct netpoll *, int, char *, int);
|
void (*rx_hook)(struct netpoll *, int, char *, int);
|
||||||
|
|
||||||
u32 local_ip, remote_ip;
|
__be32 local_ip, remote_ip;
|
||||||
u16 local_port, remote_port;
|
u16 local_port, remote_port;
|
||||||
u8 remote_mac[ETH_ALEN];
|
u8 remote_mac[ETH_ALEN];
|
||||||
};
|
};
|
||||||
|
@ -345,8 +345,8 @@ void netpoll_send_udp(struct netpoll *np, const char *msg, int len)
|
|||||||
udph->dest = htons(np->remote_port);
|
udph->dest = htons(np->remote_port);
|
||||||
udph->len = htons(udp_len);
|
udph->len = htons(udp_len);
|
||||||
udph->check = 0;
|
udph->check = 0;
|
||||||
udph->check = csum_tcpudp_magic(htonl(np->local_ip),
|
udph->check = csum_tcpudp_magic(np->local_ip,
|
||||||
htonl(np->remote_ip),
|
np->remote_ip,
|
||||||
udp_len, IPPROTO_UDP,
|
udp_len, IPPROTO_UDP,
|
||||||
csum_partial(udph, udp_len, 0));
|
csum_partial(udph, udp_len, 0));
|
||||||
if (udph->check == 0)
|
if (udph->check == 0)
|
||||||
@ -365,8 +365,8 @@ void netpoll_send_udp(struct netpoll *np, const char *msg, int len)
|
|||||||
iph->ttl = 64;
|
iph->ttl = 64;
|
||||||
iph->protocol = IPPROTO_UDP;
|
iph->protocol = IPPROTO_UDP;
|
||||||
iph->check = 0;
|
iph->check = 0;
|
||||||
put_unaligned(htonl(np->local_ip), &(iph->saddr));
|
put_unaligned(np->local_ip, &(iph->saddr));
|
||||||
put_unaligned(htonl(np->remote_ip), &(iph->daddr));
|
put_unaligned(np->remote_ip, &(iph->daddr));
|
||||||
iph->check = ip_fast_csum((unsigned char *)iph, iph->ihl);
|
iph->check = ip_fast_csum((unsigned char *)iph, iph->ihl);
|
||||||
|
|
||||||
eth = (struct ethhdr *) skb_push(skb, ETH_HLEN);
|
eth = (struct ethhdr *) skb_push(skb, ETH_HLEN);
|
||||||
@ -424,7 +424,7 @@ static void arp_reply(struct sk_buff *skb)
|
|||||||
memcpy(&tip, arp_ptr, 4);
|
memcpy(&tip, arp_ptr, 4);
|
||||||
|
|
||||||
/* Should we ignore arp? */
|
/* Should we ignore arp? */
|
||||||
if (tip != htonl(np->local_ip) ||
|
if (tip != np->local_ip ||
|
||||||
ipv4_is_loopback(tip) || ipv4_is_multicast(tip))
|
ipv4_is_loopback(tip) || ipv4_is_multicast(tip))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@ -533,9 +533,9 @@ int __netpoll_rx(struct sk_buff *skb)
|
|||||||
goto out;
|
goto out;
|
||||||
if (checksum_udp(skb, uh, ulen, iph->saddr, iph->daddr))
|
if (checksum_udp(skb, uh, ulen, iph->saddr, iph->daddr))
|
||||||
goto out;
|
goto out;
|
||||||
if (np->local_ip && np->local_ip != ntohl(iph->daddr))
|
if (np->local_ip && np->local_ip != iph->daddr)
|
||||||
goto out;
|
goto out;
|
||||||
if (np->remote_ip && np->remote_ip != ntohl(iph->saddr))
|
if (np->remote_ip && np->remote_ip != iph->saddr)
|
||||||
goto out;
|
goto out;
|
||||||
if (np->local_port && np->local_port != ntohs(uh->dest))
|
if (np->local_port && np->local_port != ntohs(uh->dest))
|
||||||
goto out;
|
goto out;
|
||||||
@ -560,14 +560,14 @@ void netpoll_print_options(struct netpoll *np)
|
|||||||
{
|
{
|
||||||
printk(KERN_INFO "%s: local port %d\n",
|
printk(KERN_INFO "%s: local port %d\n",
|
||||||
np->name, np->local_port);
|
np->name, np->local_port);
|
||||||
printk(KERN_INFO "%s: local IP %d.%d.%d.%d\n",
|
printk(KERN_INFO "%s: local IP %pI4\n",
|
||||||
np->name, HIPQUAD(np->local_ip));
|
np->name, &np->local_ip);
|
||||||
printk(KERN_INFO "%s: interface %s\n",
|
printk(KERN_INFO "%s: interface %s\n",
|
||||||
np->name, np->dev_name);
|
np->name, np->dev_name);
|
||||||
printk(KERN_INFO "%s: remote port %d\n",
|
printk(KERN_INFO "%s: remote port %d\n",
|
||||||
np->name, np->remote_port);
|
np->name, np->remote_port);
|
||||||
printk(KERN_INFO "%s: remote IP %d.%d.%d.%d\n",
|
printk(KERN_INFO "%s: remote IP %pI4\n",
|
||||||
np->name, HIPQUAD(np->remote_ip));
|
np->name, &np->remote_ip);
|
||||||
printk(KERN_INFO "%s: remote ethernet address %pM\n",
|
printk(KERN_INFO "%s: remote ethernet address %pM\n",
|
||||||
np->name, np->remote_mac);
|
np->name, np->remote_mac);
|
||||||
}
|
}
|
||||||
@ -589,7 +589,7 @@ int netpoll_parse_options(struct netpoll *np, char *opt)
|
|||||||
if ((delim = strchr(cur, '/')) == NULL)
|
if ((delim = strchr(cur, '/')) == NULL)
|
||||||
goto parse_failed;
|
goto parse_failed;
|
||||||
*delim = 0;
|
*delim = 0;
|
||||||
np->local_ip = ntohl(in_aton(cur));
|
np->local_ip = in_aton(cur);
|
||||||
cur = delim;
|
cur = delim;
|
||||||
}
|
}
|
||||||
cur++;
|
cur++;
|
||||||
@ -618,7 +618,7 @@ int netpoll_parse_options(struct netpoll *np, char *opt)
|
|||||||
if ((delim = strchr(cur, '/')) == NULL)
|
if ((delim = strchr(cur, '/')) == NULL)
|
||||||
goto parse_failed;
|
goto parse_failed;
|
||||||
*delim = 0;
|
*delim = 0;
|
||||||
np->remote_ip = ntohl(in_aton(cur));
|
np->remote_ip = in_aton(cur);
|
||||||
cur = delim + 1;
|
cur = delim + 1;
|
||||||
|
|
||||||
if (*cur != 0) {
|
if (*cur != 0) {
|
||||||
@ -759,10 +759,9 @@ int netpoll_setup(struct netpoll *np)
|
|||||||
goto release;
|
goto release;
|
||||||
}
|
}
|
||||||
|
|
||||||
np->local_ip = ntohl(in_dev->ifa_list->ifa_local);
|
np->local_ip = in_dev->ifa_list->ifa_local;
|
||||||
rcu_read_unlock();
|
rcu_read_unlock();
|
||||||
printk(KERN_INFO "%s: local IP %d.%d.%d.%d\n",
|
printk(KERN_INFO "%s: local IP %pI4\n", np->name, &np->local_ip);
|
||||||
np->name, HIPQUAD(np->local_ip));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (np->rx_hook) {
|
if (np->rx_hook) {
|
||||||
|
Loading…
Reference in New Issue
Block a user