Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id ; Sun, 13 Oct 2002 02:51:21 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id ; Sun, 13 Oct 2002 02:51:21 -0400 Received: from orion.netbank.com.br ([200.203.199.90]:29445 "EHLO orion.netbank.com.br") by vger.kernel.org with ESMTP id ; Sun, 13 Oct 2002 02:51:15 -0400 Date: Sun, 13 Oct 2002 04:56:56 -0200 From: Arnaldo Carvalho de Melo To: "David S. Miller" Cc: Linux Kernel Mailing List Subject: [PATCH] ipv4: convert /proc/net/arp to seq_file Message-ID: <20021013065656.GC7898@conectiva.com.br> Mail-Followup-To: Arnaldo Carvalho de Melo , "David S. Miller" , Linux Kernel Mailing List Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.4i X-Url: http://advogato.org/person/acme Sender: linux-kernel-owner@vger.kernel.org X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 13990 Lines: 504 David, Please consider pulling from: master.kernel.org:/home/acme/BK/ip-2.5 Now there is only this changeset outstanding there. Best Regards, - Arnaldo PS.: Any feedback from the pppoe maintainer about seq_file patch? You can import this changeset into BK by piping this whole message to: '| bk receive [path to repository]' or apply the patch as usual. =================================================================== ChangeSet@1.833, 2002-10-13 04:47:51-02:00, acme@conectiva.com.br o ipv4: convert /proc/net/arp to seq_file include/net/arp.h | 1 net/ipv4/arp.c | 155 +-------------------------------------------------- net/ipv4/ip_proc.c | 161 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 167 insertions(+), 150 deletions(-) diff -Nru a/include/net/arp.h b/include/net/arp.h --- a/include/net/arp.h Sun Oct 13 04:52:41 2002 +++ b/include/net/arp.h Sun Oct 13 04:52:41 2002 @@ -18,6 +18,7 @@ extern int arp_bind_neighbour(struct dst_entry *dst); extern int arp_mc_map(u32 addr, u8 *haddr, struct net_device *dev, int dir); extern void arp_ifdown(struct net_device *dev); +extern unsigned arp_state_to_flags(struct neighbour *neigh); extern struct neigh_ops arp_broken_ops; diff -Nru a/net/ipv4/arp.c b/net/ipv4/arp.c --- a/net/ipv4/arp.c Sun Oct 13 04:52:41 2002 +++ b/net/ipv4/arp.c Sun Oct 13 04:52:41 2002 @@ -66,6 +66,8 @@ * Alexey Kuznetsov: new arp state machine; * now it is in net/core/neighbour.c. * Krzysztof Halasa: Added Frame Relay ARP support. + * Arnaldo C. Melo : move proc stuff to seq_file and + * net/ipv4/ip_proc.c */ #include @@ -85,7 +87,6 @@ #include #include #include -#include #include #include #ifdef CONFIG_SYSCTL @@ -851,7 +852,7 @@ } /* - * User level interface (ioctl, /proc) + * User level interface (ioctl) */ /* @@ -918,7 +919,7 @@ return err; } -static unsigned arp_state_to_flags(struct neighbour *neigh) +unsigned arp_state_to_flags(struct neighbour *neigh) { unsigned flags = 0; if (neigh->nud_state&NUD_PERMANENT) @@ -1066,111 +1067,6 @@ return err; } -/* - * Write the contents of the ARP cache to a PROCfs file. - */ -#ifndef CONFIG_PROC_FS -static int arp_get_info(char *buffer, char **start, off_t offset, int length) -{ - return 0; -} -#else -#if defined(CONFIG_AX25) || defined(CONFIG_AX25_MODULE) -static char *ax2asc2(ax25_address *a, char *buf); -#endif -#define HBUFFERLEN 30 - -static int arp_get_info(char *buffer, char **start, off_t offset, int length) -{ - char hbuffer[HBUFFERLEN]; - int i,j,k; - const char hexbuf[] = "0123456789ABCDEF"; - int size = sprintf(buffer, "IP address HW type Flags " - "HW address Mask Device\n"); - int len = size; - off_t pos = size; - - for (i = 0; i <= NEIGH_HASHMASK; i++) { - struct neighbour *n; - read_lock_bh(&arp_tbl.lock); - for (n = arp_tbl.hash_buckets[i]; n; n = n->next) { - char tbuf[16]; - struct net_device *dev = n->dev; - int hatype = dev->type; - - /* Do not confuse users "arp -a" with magic entries */ - if (!(n->nud_state & ~NUD_NOARP)) - continue; - - read_lock(&n->lock); - /* Convert hardware address to XX:XX:XX:XX ... form. */ -#if defined(CONFIG_AX25) || defined(CONFIG_AX25_MODULE) - if (hatype == ARPHRD_AX25 || hatype == ARPHRD_NETROM) - ax2asc2((ax25_address *)n->ha, hbuffer); - else { -#endif - for (k = 0, j = 0; k < HBUFFERLEN - 3 && - j < dev->addr_len; j++) { - hbuffer[k++] = hexbuf[(n->ha[j] >> 4) & 15]; - hbuffer[k++] = hexbuf[n->ha[j] & 15]; - hbuffer[k++] = ':'; - } - hbuffer[--k] = 0; -#if defined(CONFIG_AX25) || defined(CONFIG_AX25_MODULE) - } -#endif - sprintf(tbuf, "%u.%u.%u.%u", - NIPQUAD(*(u32*)n->primary_key)); - size = sprintf(buffer + len, "%-16s 0x%-10x0x%-10x%s" - " * %s\n", - tbuf, hatype, arp_state_to_flags(n), - hbuffer, dev->name); - read_unlock(&n->lock); - - len += size; - pos += size; - - if (pos <= offset) - len = 0; - if (pos >= offset + length) { - read_unlock_bh(&arp_tbl.lock); - goto done; - } - } - read_unlock_bh(&arp_tbl.lock); - } - - for (i = 0; i <= PNEIGH_HASHMASK; i++) { - struct pneigh_entry *n; - for (n = arp_tbl.phash_buckets[i]; n; n = n->next) { - struct net_device *dev = n->dev; - int hatype = dev ? dev->type : 0; - char tbuf[16]; - sprintf(tbuf, "%u.%u.%u.%u", NIPQUAD(*(u32*)n->key)); - size = sprintf(buffer + len, "%-16s 0x%-10x0x%-10x%s" - " * %s\n", - tbuf, hatype, ATF_PUBL | ATF_PERM, - "00:00:00:00:00:00", - dev ? dev->name : "*"); - len += size; - pos += size; - - if (pos <= offset) - len = 0; - if (pos >= offset+length) - goto done; - } - } -done: *start = buffer + len - (pos - offset); /* Start of wanted data */ - len = pos - offset; /* Start slop */ - if (len > length) - len = length; /* Ending slop */ - if (len < 0) - len = 0; - return len; -} -#endif - /* Note, that it is not on notifier chain. It is necessary, that this routine was called after route cache will be flushed. @@ -1191,54 +1087,13 @@ .data = (void*) 1, /* understand shared skbs */ }; -void __init arp_init (void) +void __init arp_init(void) { neigh_table_init(&arp_tbl); dev_add_pack(&arp_packet_type); - - proc_net_create ("arp", 0, arp_get_info); - #ifdef CONFIG_SYSCTL neigh_sysctl_register(NULL, &arp_tbl.parms, NET_IPV4, NET_IPV4_NEIGH, "ipv4"); #endif } - - -#ifdef CONFIG_PROC_FS -#if defined(CONFIG_AX25) || defined(CONFIG_AX25_MODULE) - -/* - * ax25 -> ASCII conversion - */ -char *ax2asc2(ax25_address *a, char *buf) -{ - char c, *s; - int n; - - for (n = 0, s = buf; n < 6; n++) { - c = (a->ax25_call[n] >> 1) & 0x7F; - - if (c != ' ') *s++ = c; - } - - *s++ = '-'; - - if ((n = ((a->ax25_call[6] >> 1) & 0x0F)) > 9) { - *s++ = '1'; - n -= 10; - } - - *s++ = n + '0'; - *s++ = '\0'; - - if (*buf == '\0' || *buf == '-') - return "*"; - - return buf; - -} - -#endif -#endif diff -Nru a/net/ipv4/ip_proc.c b/net/ipv4/ip_proc.c --- a/net/ipv4/ip_proc.c Sun Oct 13 04:52:41 2002 +++ b/net/ipv4/ip_proc.c Sun Oct 13 04:52:41 2002 @@ -15,6 +15,10 @@ #include #include +#include +#include +#include +#include #include extern int raw_get_info(char *, char **, off_t, int); @@ -25,8 +29,158 @@ extern int udp_get_info(char *, char **, off_t, int); #ifdef CONFIG_PROC_FS +#ifdef CONFIG_AX25 +/* + * ax25 -> ASCII conversion + */ +char *ax2asc2(ax25_address *a, char *buf) +{ + char c, *s; + int n; + + for (n = 0, s = buf; n < 6; n++) { + c = (a->ax25_call[n] >> 1) & 0x7F; + + if (c != ' ') *s++ = c; + } + + *s++ = '-'; + + if ((n = ((a->ax25_call[6] >> 1) & 0x0F)) > 9) { + *s++ = '1'; + n -= 10; + } + + *s++ = n + '0'; + *s++ = '\0'; + + if (*buf == '\0' || *buf == '-') + return "*"; + + return buf; + +} +#endif /* CONFIG_AX25 */ + +static void *arp_seq_start(struct seq_file *seq, loff_t *pos) +{ + return (void *)(unsigned long)++*pos; +} + +static void *arp_seq_next(struct seq_file *seq, void *v, loff_t *pos) +{ + return (void *)(unsigned long)((++*pos) >= + (NEIGH_HASHMASK + + PNEIGH_HASHMASK - 1) ? 0 : *pos); +} + +static void arp_seq_stop(struct seq_file *seq, void *v) +{ +} + +#define HBUFFERLEN 30 + +static __inline__ void arp_format_neigh_table(struct seq_file *seq, int entry) +{ + char hbuffer[HBUFFERLEN]; + const char hexbuf[] = "0123456789ABCDEF"; + struct neighbour *n; + int k, j; + + read_lock_bh(&arp_tbl.lock); + for (n = arp_tbl.hash_buckets[entry]; n; n = n->next) { + char tbuf[16]; + struct net_device *dev = n->dev; + int hatype = dev->type; + + /* Do not confuse users "arp -a" with magic entries */ + if (!(n->nud_state & ~NUD_NOARP)) + continue; + + read_lock(&n->lock); + /* Convert hardware address to XX:XX:XX:XX ... form. */ +#ifdef CONFIG_AX25 + if (hatype == ARPHRD_AX25 || hatype == ARPHRD_NETROM) + ax2asc2((ax25_address *)n->ha, hbuffer); + else { +#endif + for (k = 0, j = 0; k < HBUFFERLEN - 3 && + j < dev->addr_len; j++) { + hbuffer[k++] = hexbuf[(n->ha[j] >> 4) & 15]; + hbuffer[k++] = hexbuf[n->ha[j] & 15]; + hbuffer[k++] = ':'; + } + hbuffer[--k] = 0; +#ifdef CONFIG_AX25 + } +#endif + sprintf(tbuf, "%u.%u.%u.%u", + NIPQUAD(*(u32*)n->primary_key)); + seq_printf(seq, "%-16s 0x%-10x0x%-10x%s" + " * %s\n", + tbuf, hatype, arp_state_to_flags(n), + hbuffer, dev->name); + read_unlock(&n->lock); + } + read_unlock_bh(&arp_tbl.lock); +} + +static __inline__ void arp_format_pneigh_table(struct seq_file *seq, int entry) +{ + struct pneigh_entry *n; + + for (n = arp_tbl.phash_buckets[entry]; n; n = n->next) { + struct net_device *dev = n->dev; + int hatype = dev ? dev->type : 0; + char tbuf[16]; + + sprintf(tbuf, "%u.%u.%u.%u", NIPQUAD(*(u32*)n->key)); + seq_printf(seq, "%-16s 0x%-10x0x%-10x%s" + " * %s\n", + tbuf, hatype, ATF_PUBL | ATF_PERM, + "00:00:00:00:00:00", + dev ? dev->name : "*"); + } +} + +static int arp_seq_show(struct seq_file *seq, void *v) +{ + unsigned long l = (unsigned long)v - 1; + + if (!l) + seq_puts(seq, "IP address HW type Flags " + "HW address Mask Device\n"); + + if (l <= NEIGH_HASHMASK) + arp_format_neigh_table(seq, l); + else + arp_format_pneigh_table(seq, l - NEIGH_HASHMASK); + + return 0; +} + +struct seq_operations arp_seq_ops = { + .start = arp_seq_start, + .next = arp_seq_next, + .stop = arp_seq_stop, + .show = arp_seq_show, +}; + +static int arp_seq_open(struct inode *inode, struct file *file) +{ + return seq_open(file, &arp_seq_ops); +} + +static struct file_operations arp_seq_fops = { + .open = arp_seq_open, + .read = seq_read, + .llseek = seq_lseek, + .release = seq_release, +}; + int __init ipv4_proc_init(void) { + struct proc_dir_entry *p; int rc = 0; if (!proc_net_create("raw", 0, raw_get_info)) @@ -46,8 +200,15 @@ if (!proc_net_create("udp", 0, udp_get_info)) goto out_udp; + + p = create_proc_entry("arp", S_IRUGO, proc_net); + if (!p) + goto out_arp; + p->proc_fops = &arp_seq_fops; out: return rc; +out_arp: + proc_net_remove("udp"); out_udp: proc_net_remove("tcp"); out_tcp: =================================================================== This BitKeeper patch contains the following changesets: 1.833 ## Wrapped with gzip_uu ## begin 664 bkpatch30585 M'XL(`#D8J3T``\U9>W/:2!+_6_H4'5*QQ7OT`H&#-XZQ8RJQXW/6=:F*4RHA M!J,@)*TDB%.+[[-?]TB\#%YO?'M5(9B1IGNZ>_KQFT=>PG7"X[;DN!,NOX2S M,$G;DAL&W$V]F5-SPTFM'R/A*@R14!^%$UY_^[[N156M9LI(N'12=P0S'B=M M2:WIRY[T1\3;TM7)N^L/1U>RW.G`\<@);ODGGD*G(Z=A/'/\0?+&24=^&-32 MV`F2"4^%ROF2=:XQIN$_4VWJS&S,U08SFG-7':BJ8ZA\P#3#:AARWPU]WPN2 M-P/>]YR@%L:W#V2H3-7QUS"-N:GKABYW0:U9N@Y,JZNLKN*#T3::;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RN4:KZG(W\\(O+EPS39/< M,;W+)29FG[-_BY.^>#ZE/,_["_)R22\@S^8@\3EWDK%XZ(HD0"\6E[I]>-V! MS16?C'ELQ14;'G(10>(F7[3-B+-\('I]-\86U;1T9QCQ&'V.Z_+2XV%$NUGT M:4WLP2"O@^6F#&-9HX2'=0IU5,20,(+-(6$D"!C'30)V5.3[@]UA1[N"1=B] M(,0S0$DTN-7..K,\H-_U_=AR*!$JL+._$]?C#WS MSN%_D]J:,\.TFL\\U/\*1_KL[N3!D7YKUL\YT6L,,Q`+FV-E+=%TQ^J_8Z]. MCWDF;-Z./9T&S[F8DP?.C$_>!`CFM<`+Q@XB5/K(O1P>-A@&8&[J+8N)N*L_ M'7@3JJKY"X1>7"T^=ILC9OVBNT#[2B];-FA!W&>+PK6%NC8:JP) =NK7ZOP!WQ-UQ,IUT5,?554=5Y?\"V$&N&648```` ` end - To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/