lkml.org 
[lkml]   [2000]   [Jul]   [7]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
Date
From
Subject[PATCH] Re: [RFC] solution for the inet_ntoa problem, buffer allocator
On Fri, 7 Jul 2000, Oliver Xymoron wrote:

> On Fri, 7 Jul 2000, Willy Tarreau wrote:
>
> > > Not threadsafe.
> >
> > Hmmm, I forgot that aspect :-/
>
> I'm gonna post a cleanup patch that kills in_ntoa entirely. The right way
> to do it is in_ntoa2 which and local buffers ala sprintf.

Ok, here's a completely untested but very straightforward patch that
removes in_ntoa and replaces all uses with in_ntoa2. In_ntoa wasn't
threadsafe so every use was a potential race and it was being called
multiple times for printk args. Alternatives discussed included hacking
printk to print IP addresses (doesn't fix all uses and compiler complains)
and adding some sort of allocator to in_ntoa (ugly, still not threadsafe).

I'd like to kill NIPQUAD (and definitely HIPQUAD) in favor of in_ntoa2 as
it looks like one argument in an argument list but is magically four. It
also doesn't have an obvious analog for IPv6, which is doing rather ugly
things currently.

--
"Love the dolphins," she advised him. "Write by W.A.S.T.E.." diff -ur linux/drivers/net/wan/sdla_chdlc.c linux-work/drivers/net/wan/sdla_chdlc.c
--- linux/drivers/net/wan/sdla_chdlc.c Thu May 4 13:31:21 2000
+++ linux-work/drivers/net/wan/sdla_chdlc.c Fri Jul 7 11:40:40 2000
@@ -2004,17 +2004,19 @@

if((chdlc_priv_area->route_status == ADD_ROUTE) &&
((chdlc_priv_area->IP_address & 0x000000FF) > 2)) {
+ char a[16];
+
printk(KERN_INFO "%s: Dynamic route failure.\n",card->devname);
if(card->u.c.slarp_timer) {
printk(KERN_INFO "%s: Bad IP address %s received\n",
card->devname,
- in_ntoa(ntohl(chdlc_priv_area->IP_address)));
+ in_ntoa2(ntohl(chdlc_priv_area->IP_address), a));
printk(KERN_INFO "%s: from remote station.\n",
card->devname);
}else{
printk(KERN_INFO "%s: Bad IP address %s issued\n",
card->devname,
- in_ntoa(ntohl(chdlc_priv_area->IP_address)));
+ in_ntoa2(ntohl(chdlc_priv_area->IP_address), a));
printk(KERN_INFO "%s: to remote station. Local\n",
card->devname);
printk(KERN_INFO "%s: IP address must be A.B.C.1\n",
@@ -2124,16 +2126,20 @@
}

if(err) {
- printk(KERN_INFO "%s: Add route %s failed (%d)\n",
- card->devname, in_ntoa(remote_IP_addr), err);
+ char a[16];
+ printk(KERN_INFO "%s: Add route %s failed (%d)\n",
+ card->devname,
+ in_ntoa2(remote_IP_addr, a), err);
} else {
+ char a[16];
+
((chdlc_private_area_t *)dev->priv)->route_status = ROUTE_ADDED;
printk(KERN_INFO "%s: Dynamic route added.\n",
card->devname);
printk(KERN_INFO "%s: Local IP addr : %s\n",
- card->devname, in_ntoa(local_IP_addr));
+ card->devname, in_ntoa2(local_IP_addr, a));
printk(KERN_INFO "%s: Remote IP addr: %s\n",
- card->devname, in_ntoa(remote_IP_addr));
+ card->devname, in_ntoa2(remote_IP_addr, a));
chdlc_priv_area->route_removed = 0;
}
break;
@@ -2163,15 +2169,18 @@
err = ip_rt_kill(&route);
#endif
if(err) {
+ char a[16];
printk(KERN_INFO
"%s: Remove route %s failed, (err %d)\n",
- card->devname, in_ntoa(remote_IP_addr),
- err);
+ card->devname,
+ in_ntoa2(remote_IP_addr, a), err);
} else {
+ char a[16];
((chdlc_private_area_t *)dev->priv)->route_status =
NO_ROUTE;
printk(KERN_INFO "%s: Dynamic route removed: %s\n",
- card->devname, in_ntoa(local_IP_addr));
+ card->devname,
+ in_ntoa2(local_IP_addr, a));
chdlc_priv_area->route_removed = 1;
}
break;
diff -ur linux/drivers/net/wan/sdla_fr.c linux-work/drivers/net/wan/sdla_fr.c
--- linux/drivers/net/wan/sdla_fr.c Thu May 4 13:31:21 2000
+++ linux-work/drivers/net/wan/sdla_fr.c Fri Jul 7 11:40:41 2000
@@ -122,7 +122,7 @@
#include <asm/io.h> /* for inb(), outb(), etc. */
#include <linux/time.h> /* for do_gettimeofday */
#include <linux/in.h> /* sockaddr_in */
-#include <linux/inet.h> /* in_ntoa(), etc... */
+#include <linux/inet.h> /* in_ntoa2(), etc... */
#include <asm/uaccess.h>
#include <linux/inetdevice.h>
#include <linux/ip.h>
@@ -2176,10 +2176,11 @@
set_fs(fs); /* restore old block */

if (err) {
+ char a[16];
printk(KERN_INFO "%s: Adding of route failed. Error: %d\n", card->devname,err);
printk(KERN_INFO "%s: Address: %s\n",
chan->name,
- in_ntoa(in_dev->ifa_list->ifa_address) );
+ in_ntoa2(in_dev->ifa_list->ifa_address), a);
} else {
chan->route_flag = ROUTE_ADDED;
}
@@ -2191,9 +2192,10 @@
set_fs(fs); /* restore old block */

if (err) {
+ char a[16];
printk(KERN_INFO "%s: Deleting of route failed. Error: %d\n", card->devname,err);
printk(KERN_INFO "%s: Address: %s\n",
- dev->name,in_ntoa(in_dev->ifa_list->ifa_address) );
+ dev->name,in_ntoa2(in_dev->ifa_list->ifa_address), a);
} else {
printk(KERN_INFO "%s: Removed route.\n",
chan->name);
@@ -3436,14 +3438,20 @@

in_dev = dev->ip_ptr;
if( in_dev != NULL && in_dev->ifa_list != NULL) {
+ char a[16];
+
switch (ntohs(arphdr->ar_op)) {

case 0x08: // Inverse ARP request -- Send Reply, add route.

/* Check for valid Address */
- printk(KERN_INFO "%s: Recvd PtP addr %s -InArp Req\n", ((fr_channel_t *)dev->priv)->name, in_ntoa(arphdr->ar_sip));
-
- if ((in_dev->ifa_list->ifa_mask & arphdr->ar_sip) != (in_dev->ifa_list->ifa_mask & in_dev->ifa_list->ifa_local)) {
+ printk(KERN_INFO "%s: Recvd PtP addr %s -InArp Req\n",
+ ((fr_channel_t *)dev->priv)->name,
+ in_ntoa2(arphdr->ar_sip, a));
+
+ if ((in_dev->ifa_list->ifa_mask & arphdr->ar_sip) !=
+ (in_dev->ifa_list->ifa_mask &
+ in_dev->ifa_list->ifa_local)) {
printk(KERN_INFO "%s: Invalid PtP address. InARP ignored.\n", card->devname);
printk(KERN_INFO "mask %X\n", in_dev->ifa_list->ifa_mask);
printk(KERN_INFO "local %X\n", in_dev->ifa_list->ifa_local);
@@ -3496,7 +3504,7 @@
case 0x09: // Inverse ARP reply

/* Check for valid Address */
- printk(KERN_INFO "%s: Recvd PtP addr %s -InArp Reply\n", ((fr_channel_t *)dev->priv)->name, in_ntoa(arphdr->ar_sip));
+ printk(KERN_INFO "%s: Recvd PtP addr %s -InArp Reply\n", ((fr_channel_t *)dev->priv)->name, in_ntoa2(arphdr->ar_sip, a));

if ((in_dev->ifa_list->ifa_mask & arphdr->ar_sip) != (in_dev->ifa_list->ifa_mask & in_dev->ifa_list->ifa_local)) {
printk(KERN_INFO "%s: Invalid PtP address. InARP ignored.\n", card->devname);
diff -ur linux/drivers/net/wan/sdla_ppp.c linux-work/drivers/net/wan/sdla_ppp.c
--- linux/drivers/net/wan/sdla_ppp.c Thu May 4 13:31:21 2000
+++ linux-work/drivers/net/wan/sdla_ppp.c Fri Jul 7 11:36:38 2000
@@ -86,7 +86,7 @@
#include <linux/if_arp.h> /* ARPHRD_* defines */
#include <asm/byteorder.h> /* htons(), etc. */
#include <linux/in.h> /* sockaddr_in */
-#include <linux/inet.h> /* in_aton(), in_ntoa() prototypes */
+#include <linux/inet.h> /* in_aton(), in_ntoa2() prototypes */

#include <linux/inetdevice.h>
#include <asm/uaccess.h>
@@ -1985,11 +1985,14 @@
"%s: An error occurred in IP assignment.\n",
card->devname);
} else {
+ char a[16];
struct in_ifaddr *ifa = in_dev->ifa_list;
printk(KERN_INFO "%s: Assigned Lcl. Addr: %s\n",
- card->devname, in_ntoa(ifa->ifa_local));
+ card->devname,
+ in_ntoa2(ifa->ifa_local, a));
printk(KERN_INFO "%s: Assigned Rmt. Addr: %s\n",
- card->devname, in_ntoa(ifa->ifa_address));
+ card->devname,
+ in_ntoa2(ifa->ifa_address, a));
}
Read_connection_info = 0;
}
@@ -2032,7 +2035,8 @@
ppp508_conf_t cfg;
struct net_device *dev = card->wandev.dev;
struct in_device *in_dev = dev->ip_ptr;
-
+ char a1[16], a2[16];
+
/* Prepare PPP configuration structure */
memset(&cfg, 0, sizeof(ppp508_conf_t));

@@ -2092,8 +2096,8 @@
cfg.ip_local = in_dev->ifa_list->ifa_local;
cfg.ip_remote = in_dev->ifa_list->ifa_address;
NEX_PRINTK(KERN_INFO "Local %s Remote %s Name %s\n",
- in_ntoa(cfg.ip_local),
- in_ntoa(cfg.ip_remote),
+ in_ntoa2(cfg.ip_local, a1),
+ in_ntoa2(cfg.ip_remote, a2),
dev->name);
break;

@@ -2697,12 +2701,13 @@


if (err) {
+ char a[16];
printk (KERN_INFO "%s: Adding of route failed:\n",
card->devname);
printk (KERN_INFO "%s: Local : %s\n",
- card->devname,in_ntoa(ppp_priv_area->ip_local));
+ card->devname,in_ntoa2(ppp_priv_area->ip_local, a));
printk (KERN_INFO "%s: Remote: %s\n",
- card->devname,in_ntoa(ppp_priv_area->ip_remote));
+ card->devname,in_ntoa2(ppp_priv_area->ip_remote, a));
}
return err;
}
@@ -2752,10 +2757,11 @@
printk (KERN_INFO "%s: Deleting dynamic route failed %d!\n",
card->devname, err);
return err;
- }else
+ } else {
+ char a[16];
printk (KERN_INFO "%s: PPP Deleting dynamic route %s successfuly\n",
- card->devname, in_ntoa(ip_addr));
-
+ card->devname, in_ntoa2(ip_addr, a));
+ }

return 0;
}
diff -ur linux/fs/nfs/mount_clnt.c linux-work/fs/nfs/mount_clnt.c
--- linux/fs/nfs/mount_clnt.c Thu Apr 13 09:54:19 2000
+++ linux-work/fs/nfs/mount_clnt.c Fri Jul 7 11:27:24 2000
@@ -67,7 +67,7 @@
dprintk("NFS: nfs_mount(%08x:%s)\n",
(unsigned)ntohl(addr->sin_addr.s_addr), path);

- strcpy(hostname, in_ntoa(addr->sin_addr.s_addr));
+ in_ntoa2(addr->sin_addr.s_addr, hostname);
if (!(mnt_clnt = mnt_create(hostname, addr, version)))
return -EACCES;

diff -ur linux/fs/nfs/nfsroot.c linux-work/fs/nfs/nfsroot.c
--- linux/fs/nfs/nfsroot.c Fri Apr 21 15:36:40 2000
+++ linux-work/fs/nfs/nfsroot.c Fri Jul 7 11:40:38 2000
@@ -280,7 +280,8 @@
return -1;
}

- strncpy(nfs_data.hostname, in_ntoa(servaddr), sizeof(nfs_data.hostname)-1);
+ in_ntoa2(servaddr, nfs_data.hostname);
+
return 0;
}

@@ -372,9 +373,10 @@
static int __init root_nfs_getport(int program, int version, int proto)
{
struct sockaddr_in sin;
+ char a[16];

printk(KERN_NOTICE "Looking up port of RPC %d/%d on %s\n",
- program, version, in_ntoa(servaddr));
+ program, version, in_ntoa2(servaddr, a));
set_sockaddr(&sin, servaddr, 0);
return rpc_getport_external(&sin, program, version, proto);
}
diff -ur linux/include/linux/inet.h linux-work/include/linux/inet.h
--- linux/include/linux/inet.h Wed Jun 9 16:45:36 1999
+++ linux-work/include/linux/inet.h Fri Jul 7 11:27:27 2000
@@ -45,7 +45,6 @@
#ifdef __KERNEL__

extern void inet_proto_init(struct net_proto *pro);
-extern char *in_ntoa(__u32 in);
extern char *in_ntoa2(__u32 in, char *buf);
extern __u32 in_aton(const char *str);

diff -ur linux/include/linux/wanrouter.h linux-work/include/linux/wanrouter.h
--- linux/include/linux/wanrouter.h Fri Jun 23 23:33:40 2000
+++ linux-work/include/linux/wanrouter.h Fri Jul 7 11:27:25 2000
@@ -402,7 +402,7 @@

#include <linux/fs.h> /* support for device drivers */
#include <linux/proc_fs.h> /* proc filesystem pragmatics */
-#include <linux/inet.h> /* in_aton(), in_ntoa() prototypes */
+#include <linux/inet.h> /* in_aton(), in_ntoa2() prototypes */
#include <linux/netdevice.h> /* support for network drivers */
/*----------------------------------------------------------------------------
* WAN device data space.
diff -ur linux/net/ipv4/ipconfig.c linux-work/net/ipv4/ipconfig.c
--- linux/net/ipv4/ipconfig.c Thu Jun 22 09:23:26 2000
+++ linux-work/net/ipv4/ipconfig.c Fri Jul 7 11:27:23 2000
@@ -282,7 +282,7 @@
*/

if (!ic_host_name_set)
- strcpy(system_utsname.nodename, in_ntoa(ic_myaddr));
+ in_ntoa2(ic_myaddr, system_utsname.nodename);

if (root_server_addr == INADDR_NONE)
root_server_addr = ic_servaddr;
diff -ur linux/net/ipv4/utils.c linux-work/net/ipv4/utils.c
--- linux/net/ipv4/utils.c Wed Jun 9 16:45:37 1999
+++ linux-work/net/ipv4/utils.c Fri Jul 7 11:27:23 2000
@@ -46,17 +46,6 @@
* Display an IP address in readable format.
*/

-char *in_ntoa(__u32 in)
-{
- static char buff[18];
- char *p;
-
- p = (char *) &in;
- sprintf(buff, "%d.%d.%d.%d",
- (p[0] & 255), (p[1] & 255), (p[2] & 255), (p[3] & 255));
- return(buff);
-}
-
char *in_ntoa2(__u32 in, char *buff)
{
sprintf(buff, "%d.%d.%d.%d", NIPQUAD(in));
diff -ur linux/net/netsyms.c linux-work/net/netsyms.c
--- linux/net/netsyms.c Fri Jul 7 11:54:46 2000
+++ linux-work/net/netsyms.c Fri Jul 7 11:27:23 2000
@@ -427,7 +427,7 @@
EXPORT_SYMBOL(dev_open);

/* Used by other modules */
-EXPORT_SYMBOL(in_ntoa);
+EXPORT_SYMBOL(in_ntoa2);

EXPORT_SYMBOL(ip_rcv);
EXPORT_SYMBOL(arp_rcv);
diff -ur linux/net/sunrpc/pmap_clnt.c linux-work/net/sunrpc/pmap_clnt.c
--- linux/net/sunrpc/pmap_clnt.c Wed Jun 21 14:43:37 2000
+++ linux-work/net/sunrpc/pmap_clnt.c Fri Jul 7 11:27:22 2000
@@ -87,7 +87,7 @@
}

#ifdef CONFIG_ROOT_NFS
-char *in_ntoa(__u32 in);
+char *in_ntoa2(__u32 in, char *buff);

int
rpc_getport_external(struct sockaddr_in *sin, __u32 prog, __u32 vers, int prot)
@@ -100,7 +100,7 @@
dprintk("RPC: rpc_getport_external(%u.%u.%u.%u, %d, %d, %d)\n",
NIPQUAD(sin->sin_addr.s_addr), prog, vers, prot);

- strcpy(hostname, in_ntoa(sin->sin_addr.s_addr));
+ in_ntoa2(sin->sin_addr.s_addr, hostname);
if (!(pmap_clnt = pmap_create(hostname, sin, prot)))
return -EACCES;

Only in linux: ntoa-purge.patch
\
 
 \ /
  Last update: 2005-03-22 13:57    [from the cache]
©2003-2011 Jasper Spaans