2002-10-13 06:51:21

by Arnaldo Carvalho de Melo

[permalink] [raw]
Subject: [PATCH] ipv4: convert /proc/net/arp to seq_file

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.

===================================================================


[email protected], 2002-10-13 04:47:51-02:00, [email protected]
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 <linux/types.h>
@@ -85,7 +87,6 @@
#include <linux/if_arp.h>
#include <linux/trdevice.h>
#include <linux/skbuff.h>
-#include <linux/proc_fs.h>
#include <linux/stat.h>
#include <linux/init.h>
#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 <linux/config.h>
#include <linux/init.h>
+#include <linux/netdevice.h>
+#include <net/neighbour.h>
+#include <net/arp.h>
+#include <linux/seq_file.h>
#include <linux/proc_fs.h>

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=:X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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+<VITTD69.RRP?#E1-(W%ID.QLFTLP(
MOC88B$B=1/0Q:'S\@"CZLJ$^=Q(N+<:(M]PI/:T%Z@JF\%AF#[QX`531@=PS
M+#`IN!&=%5`A`K)@$RP*[2X0&3[9O:OK=Q\KF03$)4HE40(19=UMB,M_.$UM
MY$9"1*L(\N7SWUOW!VHT&6ARSMU&[EPD6CX)9UPI3`<1)3J=X[>._$]?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^=ILC9OV<N#<L+',H2=)1'.#D0CBNP3GW0VA+5.<"2A!!
M<9^W;@\XP4",PL^.&Z6N96$V=2W3P*:7-<A--_3@\QGW"?]Y/'1PSZ1XH9OB
M$MUM:2IQ9\US4E#NJJR!0,I,?%);0G?>BNT#[2B];-FA!W&>+PK6%NC8:JP)
=NK7ZOP!WQ-UQ,IUT5,?554=5Y?\"V$&N&648````
`
end


2002-10-13 06:58:54

by David Miller

[permalink] [raw]
Subject: Re: [PATCH] ipv4: convert /proc/net/arp to seq_file

From: Arnaldo Carvalho de Melo <[email protected]>
Date: Sun, 13 Oct 2002 04:56:56 -0200

Please consider pulling from:

master.kernel.org:/home/acme/BK/ip-2.5

Pulled, thanks.

PS.: Any feedback from the pppoe maintainer about seq_file patch?

None that I've seen :(

We should just put the changes in, if the maintainer really
cares he can revert them later after making his case.

Can you repost the changes in question?

2002-10-13 07:05:17

by Arnaldo Carvalho de Melo

[permalink] [raw]
Subject: Re: [PATCH] ipv4: convert /proc/net/arp to seq_file

Em Sat, Oct 12, 2002 at 11:57:56PM -0700, David S. Miller escreveu:
> PS.: Any feedback from the pppoe maintainer about seq_file patch?
>
> None that I've seen :(
>
> We should just put the changes in, if the maintainer really
> cares he can revert them later after making his case.
>
> Can you repost the changes in question?

Sure, here it is, and it is available for pulling at:

master.kernel.org:/home/acme/BK/llc-2.5

- Arnaldo

You can import this changeset into BK by piping this whole message to:
'| bk receive [path to repository]' or apply the patch as usual.

===================================================================


[email protected], 2002-10-09 02:03:34-03:00, [email protected]
o pppoe: use seq_file for proc stuff

Also make it conditional on CONFIG_PROC_FS


pppoe.c | 156 +++++++++++++++++++++++++++++++++++++++++++---------------------
1 files changed, 106 insertions(+), 50 deletions(-)


diff -Nru a/drivers/net/pppoe.c b/drivers/net/pppoe.c
--- a/drivers/net/pppoe.c Sun Oct 13 05:09:55 2002
+++ b/drivers/net/pppoe.c Sun Oct 13 05:09:55 2002
@@ -5,7 +5,7 @@
* PPPoE --- PPP over Ethernet (RFC 2516)
*
*
- * Version: 0.6.10
+ * Version: 0.6.11
*
* 220102 : Fix module use count on failure in pppoe_create, pppox_sk -acme
* 030700 : Fixed connect logic to allow for disconnect.
@@ -35,6 +35,7 @@
* 121301 : New ppp channels interface; cannot unregister a channel
* from interrupts. Thus, we mark the socket as a ZOMBIE
* and do the unregistration later.
+ * 081002 : seq_file support for proc stuff -acme
*
* Author: Michal Ostrowski <[email protected]>
* Contributors:
@@ -75,6 +76,7 @@
#include <linux/notifier.h>
#include <linux/file.h>
#include <linux/proc_fs.h>
+#include <linux/seq_file.h>



@@ -974,63 +976,102 @@
return error;
}

-int pppoe_proc_info(char *buffer, char **start, off_t offset, int length)
+#ifdef CONFIG_PROC_FS
+static int pppoe_seq_show(struct seq_file *seq, void *v)
{
struct pppox_opt *po;
- int len = 0;
- off_t pos = 0;
- off_t begin = 0;
- int size;
- int i;
+ char *dev_name;

- len += sprintf(buffer,
- "Id Address Device\n");
- pos = len;
+ if (v == (void *)1) {
+ seq_puts(seq, "Id Address Device\n");
+ goto out;
+ }

- write_lock_bh(&pppoe_hash_lock);
+ po = v;
+ dev_name = po->pppoe_pa.dev;
+
+ seq_printf(seq, "%08X %02X:%02X:%02X:%02X:%02X:%02X %8s\n",
+ po->pppoe_pa.sid,
+ po->pppoe_pa.remote[0], po->pppoe_pa.remote[1],
+ po->pppoe_pa.remote[2], po->pppoe_pa.remote[3],
+ po->pppoe_pa.remote[4], po->pppoe_pa.remote[5], dev_name);
+out:
+ return 0;
+}

- for (i = 0; i < PPPOE_HASH_SIZE; i++) {
+static __inline__ struct pppox_opt *pppoe_get_idx(loff_t pos)
+{
+ struct pppox_opt *po = NULL;
+ int i = 0;
+
+ for (; i < PPPOE_HASH_SIZE; i++) {
po = item_hash_table[i];
while (po) {
- char *dev = po->pppoe_pa.dev;
+ if (!pos--)
+ goto out;
+ po = po->next;
+ }
+ }
+out:
+ return po;
+}

- size = sprintf(buffer + len,
- "%08X %02X:%02X:%02X:%02X:%02X:%02X %8s\n",
- po->pppoe_pa.sid,
- po->pppoe_pa.remote[0],
- po->pppoe_pa.remote[1],
- po->pppoe_pa.remote[2],
- po->pppoe_pa.remote[3],
- po->pppoe_pa.remote[4],
- po->pppoe_pa.remote[5],
- dev);
- len += size;
- pos += size;
- if (pos < offset) {
- len = 0;
- begin = pos;
- }
+static void *pppoe_seq_start(struct seq_file *seq, loff_t *pos)
+{
+ loff_t l = *pos;

- if (pos > offset + length)
- break;
+ read_lock_bh(&pppoe_hash_lock);
+ return l ? pppoe_get_idx(--l) : (void *)1;
+}

- po = po->next;
+static void *pppoe_seq_next(struct seq_file *seq, void *v, loff_t *pos)
+{
+ struct pppox_opt *po;
+
+ ++*pos;
+ if (v == (void *)1) {
+ po = pppoe_get_idx(0);
+ goto out;
+ }
+ po = v;
+ po = po->next;
+ if (!po) {
+ int hash = hash_item(po->pppoe_pa.sid, po->pppoe_pa.remote);
+
+ while (++hash < PPPOE_HASH_SIZE) {
+ po = item_hash_table[hash];
+ if (po)
+ break;
}
+ }
+out:
+ return po;
+}

- if (po)
- break;
- }
- write_unlock_bh(&pppoe_hash_lock);
+static void pppoe_seq_stop(struct seq_file *seq, void *v)
+{
+ read_unlock_bh(&pppoe_hash_lock);
+}
+
+struct seq_operations pppoe_seq_ops = {
+ .start = pppoe_seq_start,
+ .next = pppoe_seq_next,
+ .stop = pppoe_seq_stop,
+ .show = pppoe_seq_show,
+};

- *start = buffer + (offset - begin);
- len -= (offset - begin);
- if (len > length)
- len = length;
- if (len < 0)
- len = 0;
- return len;
+static int pppoe_seq_open(struct inode *inode, struct file *file)
+{
+ return seq_open(file, &pppoe_seq_ops);
}

+static struct file_operations pppoe_seq_fops = {
+ .open = pppoe_seq_open,
+ .read = seq_read,
+ .llseek = seq_lseek,
+ .release = seq_release,
+};
+#endif /* CONFIG_PROC_FS */

struct proto_ops pppoe_ops = {
.family = AF_PPPOX,
@@ -1061,13 +1102,28 @@
{
int err = register_pppox_proto(PX_PROTO_OE, &pppoe_proto);

- if (err == 0) {
- dev_add_pack(&pppoes_ptype);
- dev_add_pack(&pppoed_ptype);
- register_netdevice_notifier(&pppoe_notifier);
- proc_net_create("pppoe", 0, pppoe_proc_info);
- }
+ if (err)
+ goto out;
+#ifdef CONFIG_PROC_FS
+{
+ struct proc_dir_entry *p = create_proc_entry("pppoe", S_IRUGO,
+ proc_net);
+ err = -ENOMEM;
+ if (!p)
+ goto out_unregister;
+
+ p->proc_fops = &pppoe_seq_fops;
+ err = 0;
+}
+#endif /* CONFIG_PROC_FS */
+ dev_add_pack(&pppoes_ptype);
+ dev_add_pack(&pppoed_ptype);
+ register_netdevice_notifier(&pppoe_notifier);
+out:
return err;
+out_unregister:
+ unregister_pppox_proto(PX_PROTO_OE);
+ goto out;
}

void __exit pppoe_exit(void)
@@ -1076,7 +1132,7 @@
dev_remove_pack(&pppoes_ptype);
dev_remove_pack(&pppoed_ptype);
unregister_netdevice_notifier(&pppoe_notifier);
- proc_net_remove("pppoe");
+ remove_proc_entry("pppoe", proc_net);
}

module_init(pppoe_init);

===================================================================


This BitKeeper patch contains the following changesets:
1.637
## Wrapped with gzip_uu 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OW;?#;M
1!YV.[X1C3?T'+AM][3$/````
`
end

2002-10-13 07:48:20

by David Miller

[permalink] [raw]
Subject: Re: [PATCH] ipv4: convert /proc/net/arp to seq_file

From: Arnaldo Carvalho de Melo <[email protected]>
Date: Sun, 13 Oct 2002 05:10:59 -0200

Sure, here it is, and it is available for pulling at:

master.kernel.org:/home/acme/BK/llc-2.5

Pulled, thanks.