* [PATCH] Remove copied inet_aton code in bond_main.c
@ 2003-06-18 11:09 Andi Kleen
2003-06-20 2:07 ` Jeff Garzik
0 siblings, 1 reply; 2+ messages in thread
From: Andi Kleen @ 2003-06-18 11:09 UTC (permalink / raw)
To: netdev; +Cc: jgarzik
According to a report the my_inet_aton code in bond_main.c is copied
from 4.4BSD, but it doesn't carry a BSD copyright license. In addition
it is somewhat redundant with the standard in_aton. Convert it
to use the linux function.
Error handling is a bit worse than before, but not much.
Patch for 2.5 bonding. The 2.4 version has the same problem, but afaik
it is scheduled to be replaced by the 2.5 codebase anyways.
-Andi
--- linux/drivers/net/bonding/bond_main.c-o 2003-06-14 23:42:51.000000000 +0200
+++ linux/drivers/net/bonding/bond_main.c 2003-06-18 13:03:04.000000000 +0200
@@ -390,6 +390,7 @@
#include <linux/timer.h>
#include <linux/socket.h>
#include <linux/ctype.h>
+#include <linux/inet.h>
#include <asm/system.h>
#include <asm/bitops.h>
#include <asm/io.h>
@@ -2797,84 +2798,6 @@
mod_timer(&bond->arp_timer, next_timer);
}
-typedef uint32_t in_addr_t;
-
-int
-my_inet_aton(char *cp, unsigned long *the_addr) {
- static const in_addr_t max[4] = { 0xffffffff, 0xffffff, 0xffff, 0xff };
- in_addr_t val;
- char c;
- union iaddr {
- uint8_t bytes[4];
- uint32_t word;
- } res;
- uint8_t *pp = res.bytes;
- int digit,base;
-
- res.word = 0;
-
- c = *cp;
- for (;;) {
- /*
- * Collect number up to ``.''.
- * Values are specified as for C:
- * 0x=hex, 0=octal, isdigit=decimal.
- */
- if (!isdigit(c)) goto ret_0;
- val = 0; base = 10; digit = 0;
- for (;;) {
- if (isdigit(c)) {
- val = (val * base) + (c - '0');
- c = *++cp;
- digit = 1;
- } else {
- break;
- }
- }
- if (c == '.') {
- /*
- * Internet format:
- * a.b.c.d
- * a.b.c (with c treated as 16 bits)
- * a.b (with b treated as 24 bits)
- */
- if (pp > res.bytes + 2 || val > 0xff) {
- goto ret_0;
- }
- *pp++ = val;
- c = *++cp;
- } else
- break;
- }
- /*
- * Check for trailing characters.
- */
- if (c != '\0' && (!isascii(c) || !isspace(c))) {
- goto ret_0;
- }
- /*
- * Did we get a valid digit?
- */
- if (!digit) {
- goto ret_0;
- }
-
- /* Check whether the last part is in its limits depending on
- the number of parts in total. */
- if (val > max[pp - res.bytes]) {
- goto ret_0;
- }
-
- if (the_addr != NULL) {
- *the_addr = res.word | htonl (val);
- }
-
- return (1);
-
-ret_0:
- return (0);
-}
-
static int bond_sethwaddr(struct net_device *master, struct net_device *slave)
{
#ifdef BONDING_DEBUG
@@ -3958,15 +3881,18 @@
for (arp_ip_count=0 ;
(arp_ip_count < MAX_ARP_IP_TARGETS) && arp_ip_target[arp_ip_count];
arp_ip_count++ ) {
- /* TODO: check and log bad ip address */
- if (my_inet_aton(arp_ip_target[arp_ip_count],
- &arp_target[arp_ip_count]) == 0) {
+ /* not complete check, but should be good enough to
+ catch mistakes */
+ if (!isdigit(arp_ip_target[arp_ip_count][0])) {
printk(KERN_WARNING
"bonding_init(): bad arp_ip_target module "
"parameter (%s), ARP monitoring will not be "
"performed\n",
arp_ip_target[arp_ip_count]);
arp_interval = 0;
+ } else {
+ u32 ip = in_aton(arp_ip_target[arp_ip_count]);
+ *(u32 *)(arp_ip_target[arp_ip_count]) = ip;
}
}
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] Remove copied inet_aton code in bond_main.c
2003-06-18 11:09 [PATCH] Remove copied inet_aton code in bond_main.c Andi Kleen
@ 2003-06-20 2:07 ` Jeff Garzik
0 siblings, 0 replies; 2+ messages in thread
From: Jeff Garzik @ 2003-06-20 2:07 UTC (permalink / raw)
To: Andi Kleen; +Cc: netdev
thanks, applied to 2.4 and 2.5.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2003-06-20 2:07 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2003-06-18 11:09 [PATCH] Remove copied inet_aton code in bond_main.c Andi Kleen
2003-06-20 2:07 ` Jeff Garzik
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).