root/net/ipv4/arp.c

/* [previous][next][first][last][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. arp_check_expire
  2. arp_release_entry
  3. arp_device_event
  4. arp_send
  5. arp_expire_request
  6. arp_send_q
  7. arp_destroy
  8. arp_rcv
  9. arp_query
  10. arp_find
  11. arp_get_info
  12. arp_lookup
  13. arp_find_cache
  14. arp_req_set
  15. arp_req_get
  16. arp_ioctl
  17. arp_init

   1 /* linux/net/inet/arp.c
   2  *
   3  * Copyright (C) 1994 by Florian  La Roche
   4  *
   5  * This module implements the Address Resolution Protocol ARP (RFC 826),
   6  * which is used to convert IP addresses (or in the future maybe other
   7  * high-level addresses into a low-level hardware address (like an Ethernet
   8  * address).
   9  *
  10  * FIXME:
  11  *      Experiment with better retransmit timers
  12  *      Clean up the timer deletions
  13  *      If you create a proxy entry set your interface address to the address
  14  *      and then delete it, proxies may get out of sync with reality - check this
  15  *
  16  * This program is free software; you can redistribute it and/or
  17  * modify it under the terms of the GNU General Public License
  18  * as published by the Free Software Foundation; either version
  19  * 2 of the License, or (at your option) any later version.
  20  *
  21  *
  22  * Fixes:
  23  *              Alan Cox        :       Removed the ethernet assumptions in Florian's code
  24  *              Alan Cox        :       Fixed some small errors in the ARP logic
  25  *              Alan Cox        :       Allow >4K in /proc
  26  *              Alan Cox        :       Make ARP add its own protocol entry
  27  *
  28  *              Ross Martin     :       Rewrote arp_rcv() and arp_get_info()
  29  *              Stephen Henson  :       Add AX25 support to arp_get_info()
  30  *              Alan Cox        :       Drop data when a device is downed.
  31  *              Alan Cox        :       Use init_timer().
  32  *              Alan Cox        :       Double lock fixes.
  33  *              Martin Seine    :       Move the arphdr structure
  34  *                                      to if_arp.h for compatibility.
  35  *                                      with BSD based programs.
  36  *              Andrew Tridgell :       Added ARP netmask code and
  37  *                                      re-arranged proxy handling.
  38  *              Alan Cox        :       Changed to use notifiers.
  39  *              Niibe Yutaka    :       Reply for this device or proxies only.
  40  *              Alan Cox        :       Don't proxy across hardware types!
  41  *              Jonathan Naylor :       Added support for NET/ROM.
  42  *              Mike Shaver     :       RFC1122 checks.
  43  *              Jonathan Naylor :       Only lookup the hardware address for
  44  *                                      the correct hardware type.
  45  *              Germano Caronni :       Assorted subtle races.
  46  *              Craig Schlenter :       Don't modify permanent entry 
  47  *                                      during arp_rcv.
  48  *              Russ Nelson     :       Tidied up a few bits.
  49  */
  50 
  51 /* RFC1122 Status:
  52    2.3.2.1 (ARP Cache Validation):
  53      MUST provide mechanism to flush stale cache entries (OK)
  54      SHOULD be able to configure cache timeout (NOT YET)
  55      MUST throttle ARP retransmits (OK)
  56    2.3.2.2 (ARP Packet Queue):
  57      SHOULD save at least one packet from each "conversation" with an
  58        unresolved IP address.  (OK)
  59    950727 -- MS
  60 */
  61       
  62 #include <linux/types.h>
  63 #include <linux/string.h>
  64 #include <linux/kernel.h>
  65 #include <linux/sched.h>
  66 #include <linux/config.h>
  67 #include <linux/socket.h>
  68 #include <linux/sockios.h>
  69 #include <linux/errno.h>
  70 #include <linux/if_arp.h>
  71 #include <linux/in.h>
  72 #include <linux/mm.h>
  73 #include <asm/system.h>
  74 #include <asm/segment.h>
  75 #include <stdarg.h>
  76 #include <linux/inet.h>
  77 #include <linux/netdevice.h>
  78 #include <linux/etherdevice.h>
  79 #include <linux/trdevice.h>
  80 #include <net/ip.h>
  81 #include <net/route.h>
  82 #include <net/protocol.h>
  83 #include <net/tcp.h>
  84 #include <linux/skbuff.h>
  85 #include <net/sock.h>
  86 #include <net/arp.h>
  87 #ifdef CONFIG_AX25
  88 #include <net/ax25.h>
  89 #ifdef CONFIG_NETROM
  90 #include <net/netrom.h>
  91 #endif
  92 #endif
  93 #include <linux/proc_fs.h>
  94 #include <linux/stat.h>
  95 
  96 
  97 /*
  98  *      This structure defines the ARP mapping cache. As long as we make changes
  99  *      in this structure, we keep interrupts off. But normally we can copy the
 100  *      hardware address and the device pointer in a local variable and then 
 101  *      make any "long calls" to send a packet out.
 102  */
 103 
 104 struct arp_table
 105 {
 106         struct arp_table                *next;                  /* Linked entry list            */
 107         unsigned long                   last_used;              /* For expiry                   */
 108         unsigned int                    flags;                  /* Control status               */
 109         u32                             ip;                     /* ip address of entry          */
 110         u32                             mask;                   /* netmask - used for generalised proxy arps (tridge)           */
 111         unsigned char                   ha[MAX_ADDR_LEN];       /* Hardware address             */
 112         unsigned char                   hlen;                   /* Length of hardware address   */
 113         unsigned short                  htype;                  /* Type of hardware in use      */
 114         struct device                   *dev;                   /* Device the entry is tied to  */
 115 
 116         /*
 117          *      The following entries are only used for unresolved hw addresses.
 118          */
 119         
 120         struct timer_list               timer;                  /* expire timer                 */
 121         int                             retries;                /* remaining retries            */
 122         struct sk_buff_head             skb;                    /* list of queued packets       */
 123 };
 124 
 125 
 126 /*
 127  *      Configurable Parameters (don't touch unless you know what you are doing
 128  */
 129 
 130 /*
 131  *      If an arp request is send, ARP_RES_TIME is the timeout value until the
 132  *      next request is send.
 133  */
 134 
 135 /* RFC1122: OK.  Throttles ARPing, as per 2.3.2.1. (MUST) */
 136 /* The recommended minimum timeout is 1 second per destination. */
 137 /* Is this a per-destination timeout? -- MS [YES AC]*/
 138 
 139 #define ARP_RES_TIME            (250*(HZ/10))
 140 
 141 /*
 142  *      The number of times an arp request is send, until the host is
 143  *      considered unreachable.
 144  */
 145 
 146 #define ARP_MAX_TRIES           3
 147 
 148 /*
 149  *      After that time, an unused entry is deleted from the arp table.
 150  */
 151 
 152 #define ARP_TIMEOUT             (600*HZ)
 153 
 154 /*
 155  *      How often is the function 'arp_check_retries' called.
 156  *      An entry is invalidated in the time between ARP_TIMEOUT and
 157  *      (ARP_TIMEOUT+ARP_CHECK_INTERVAL).
 158  */
 159 
 160 #define ARP_CHECK_INTERVAL      (60 * HZ)
 161 
 162 enum proxy {
 163    PROXY_EXACT=0,
 164    PROXY_ANY,
 165    PROXY_NONE,
 166 };
 167 
 168 /* Forward declarations. */
 169 static void arp_check_expire (unsigned long);  
 170 static struct arp_table *arp_lookup(u32 paddr, enum proxy proxy, unsigned short type);
 171 
 172 
 173 static struct timer_list arp_timer =
 174         { NULL, NULL, ARP_CHECK_INTERVAL, 0L, &arp_check_expire };
 175 
 176 /*
 177  * The default arp netmask is just 255.255.255.255 which means it's
 178  * a single machine entry. Only proxy entries can have other netmasks
 179  *
 180 */
 181 
 182 #define DEF_ARP_NETMASK (~0)
 183 
 184 
 185 /*
 186  *      The size of the hash table. Must be a power of two.
 187  *      Maybe we should remove hashing in the future for arp and concentrate
 188  *      on Patrick Schaaf's Host-Cache-Lookup...
 189  */
 190 
 191 
 192 #define ARP_TABLE_SIZE  16
 193 
 194 /* The ugly +1 here is to cater for proxy entries. They are put in their 
 195    own list for efficiency of lookup. If you don't want to find a proxy
 196    entry then don't look in the last entry, otherwise do 
 197 */
 198 
 199 #define FULL_ARP_TABLE_SIZE (ARP_TABLE_SIZE+1)
 200 
 201 struct arp_table *arp_tables[FULL_ARP_TABLE_SIZE] =
 202 {
 203         NULL,
 204 };
 205 
 206 unsigned long arp_cache_stamp;
 207 
 208 
 209 /*
 210  *      The last bits in the IP address are used for the cache lookup.
 211  *      A special entry is used for proxy arp entries
 212  */
 213 
 214 #define HASH(paddr)             (htonl(paddr) & (ARP_TABLE_SIZE - 1))
 215 #define PROXY_HASH ARP_TABLE_SIZE
 216 
 217 /*
 218  *      Check if there are too old entries and remove them. If the ATF_PERM
 219  *      flag is set, they are always left in the arp cache (permanent entry).
 220  *      Note: Only fully resolved entries, which don't have any packets in
 221  *      the queue, can be deleted, since ARP_TIMEOUT is much greater than
 222  *      ARP_MAX_TRIES*ARP_RES_TIME.
 223  */
 224 
 225 /* RFC1122: Looks good.  Prevents stale ARP entries, as per 2.3.2.1. (MUST) */
 226 
 227 static void arp_check_expire(unsigned long dummy)
     /* [previous][next][first][last][top][bottom][index][help] */
 228 {
 229         int i;
 230         unsigned long now = jiffies;
 231         unsigned long flags;
 232         save_flags(flags);
 233         cli();
 234 
 235         for (i = 0; i < FULL_ARP_TABLE_SIZE; i++)
 236         {
 237                 struct arp_table *entry;
 238                 struct arp_table **pentry = &arp_tables[i];
 239 
 240                 while ((entry = *pentry) != NULL)
 241                 {
 242                         if ((now - entry->last_used) > ARP_TIMEOUT
 243                                 && !(entry->flags & ATF_PERM))
 244                         {
 245                                 *pentry = entry->next;  /* remove from list */
 246                                 arp_cache_stamp++;
 247                                 del_timer(&entry->timer);       /* Paranoia */
 248                                 kfree_s(entry, sizeof(struct arp_table)); 
 249                                 /* Don't have to remove packets in entry->skb. */
 250                                 /* See comments above. */
 251                         }
 252                         else
 253                                 pentry = &entry->next;  /* go to next entry */
 254                 }
 255         }
 256         restore_flags(flags);
 257 
 258         /*
 259          *      Set the timer again.
 260          */
 261 
 262         del_timer(&arp_timer);
 263         arp_timer.expires = jiffies + ARP_CHECK_INTERVAL;
 264         add_timer(&arp_timer);
 265 }
 266 
 267 
 268 /*
 269  *      Release all linked skb's and the memory for this entry.
 270  */
 271 
 272 static void arp_release_entry(struct arp_table *entry)
     /* [previous][next][first][last][top][bottom][index][help] */
 273 {
 274         struct sk_buff *skb;
 275         unsigned long flags;
 276 
 277         save_flags(flags);
 278         cli();
 279         /* Release the list of `skb' pointers. */
 280         while ((skb = skb_dequeue(&entry->skb)) != NULL)
 281         {
 282                 skb_device_lock(skb);
 283                 restore_flags(flags);
 284                 dev_kfree_skb(skb, FREE_WRITE);
 285                 cli();
 286         }
 287         restore_flags(flags);
 288         del_timer(&entry->timer);
 289         kfree_s(entry, sizeof(struct arp_table));
 290         return;
 291 }
 292 
 293 /*
 294  *      Purge a device from the ARP queue
 295  */
 296  
 297 int arp_device_event(struct notifier_block *this, unsigned long event, void *ptr)
     /* [previous][next][first][last][top][bottom][index][help] */
 298 {
 299         struct device *dev=ptr;
 300         int i;
 301         unsigned long flags;
 302         
 303         if(event!=NETDEV_DOWN)
 304                 return NOTIFY_DONE;
 305         /*
 306          *      This is a bit OTT - maybe we need some arp semaphores instead.
 307          */
 308          
 309         save_flags(flags);
 310         cli();
 311         for (i = 0; i < FULL_ARP_TABLE_SIZE; i++)
 312         {
 313                 struct arp_table *entry;
 314                 struct arp_table **pentry = &arp_tables[i];
 315 
 316                 while ((entry = *pentry) != NULL)
 317                 {
 318                         if(entry->dev==dev)
 319                         {
 320                                 *pentry = entry->next;  /* remove from list */
 321                                 del_timer(&entry->timer);       /* Paranoia */
 322                                 kfree_s(entry, sizeof(struct arp_table));
 323                         }
 324                         else
 325                                 pentry = &entry->next;  /* go to next entry */
 326                 }
 327         }
 328         arp_cache_stamp++;
 329         restore_flags(flags);
 330         return NOTIFY_DONE;
 331 }
 332 
 333 
 334 /*
 335  *      Create and send an arp packet. If (dest_hw == NULL), we create a broadcast
 336  *      message.
 337  */
 338 
 339 void arp_send(int type, int ptype, u32 dest_ip, 
     /* [previous][next][first][last][top][bottom][index][help] */
 340               struct device *dev, u32 src_ip, 
 341               unsigned char *dest_hw, unsigned char *src_hw)
 342 {
 343         struct sk_buff *skb;
 344         struct arphdr *arp;
 345         unsigned char *arp_ptr;
 346 
 347         /*
 348          *      No arp on this interface.
 349          */
 350         
 351         if(dev->flags&IFF_NOARP)
 352                 return;
 353 
 354         /*
 355          *      Allocate a buffer
 356          */
 357         
 358         skb = alloc_skb(sizeof(struct arphdr)+ 2*(dev->addr_len+4)
 359                                 + dev->hard_header_len, GFP_ATOMIC);
 360         if (skb == NULL)
 361         {
 362                 printk("ARP: no memory to send an arp packet\n");
 363                 return;
 364         }
 365         skb_reserve(skb, dev->hard_header_len);
 366         arp = (struct arphdr *) skb_put(skb,sizeof(struct arphdr) + 2*(dev->addr_len+4));
 367         skb->arp = 1;
 368         skb->dev = dev;
 369         skb->free = 1;
 370 
 371         /*
 372          *      Fill the device header for the ARP frame
 373          */
 374 
 375         dev->hard_header(skb,dev,ptype,dest_hw?dest_hw:dev->broadcast,src_hw?src_hw:NULL,skb->len);
 376 
 377         /* Fill out the arp protocol part. */
 378         arp->ar_hrd = htons(dev->type);
 379 #ifdef CONFIG_AX25
 380 #ifdef CONFIG_NETROM
 381         arp->ar_pro = (dev->type == ARPHRD_AX25 || dev->type == ARPHRD_NETROM) ? htons(AX25_P_IP) : htons(ETH_P_IP);
 382 #else
 383         arp->ar_pro = (dev->type != ARPHRD_AX25)? htons(ETH_P_IP) : htons(AX25_P_IP);
 384 #endif
 385 #else
 386         arp->ar_pro = htons(ETH_P_IP);
 387 #endif
 388         arp->ar_hln = dev->addr_len;
 389         arp->ar_pln = 4;
 390         arp->ar_op = htons(type);
 391 
 392         arp_ptr=(unsigned char *)(arp+1);
 393 
 394         memcpy(arp_ptr, src_hw, dev->addr_len);
 395         arp_ptr+=dev->addr_len;
 396         memcpy(arp_ptr, &src_ip,4);
 397         arp_ptr+=4;
 398         if (dest_hw != NULL)
 399                 memcpy(arp_ptr, dest_hw, dev->addr_len);
 400         else
 401                 memset(arp_ptr, 0, dev->addr_len);
 402         arp_ptr+=dev->addr_len;
 403         memcpy(arp_ptr, &dest_ip, 4);
 404 
 405         dev_queue_xmit(skb, dev, 0);
 406 }
 407 
 408 
 409 /*
 410  *      This function is called, if an entry is not resolved in ARP_RES_TIME.
 411  *      Either resend a request, or give it up and free the entry.
 412  */
 413 
 414 static void arp_expire_request (unsigned long arg)
     /* [previous][next][first][last][top][bottom][index][help] */
 415 {
 416         struct arp_table *entry = (struct arp_table *) arg;
 417         struct arp_table **pentry;
 418         unsigned long hash;
 419         unsigned long flags;
 420 
 421         save_flags(flags);
 422         cli();
 423 
 424         /*
 425          *      Since all timeouts are handled with interrupts enabled, there is a
 426          *      small chance, that this entry has just been resolved by an incoming
 427          *      packet. This is the only race condition, but it is handled...
 428          */
 429         
 430         if (entry->flags & ATF_COM)
 431         {
 432                 restore_flags(flags);
 433                 return;
 434         }
 435 
 436         if (--entry->retries > 0)
 437         {
 438                 u32 ip = entry->ip;
 439                 struct device *dev = entry->dev;
 440 
 441                 /* Set new timer. */
 442                 del_timer(&entry->timer);
 443                 entry->timer.expires = jiffies + ARP_RES_TIME;
 444                 add_timer(&entry->timer);
 445                 restore_flags(flags);
 446                 arp_send(ARPOP_REQUEST, ETH_P_ARP, ip, dev, dev->pa_addr, 
 447                          NULL, dev->dev_addr);
 448                 return;
 449         }
 450 
 451         /*
 452          *      Arp request timed out. Delete entry and all waiting packets.
 453          *      If we give each entry a pointer to itself, we don't have to
 454          *      loop through everything again. Maybe hash is good enough, but
 455          *      I will look at it later.
 456          */
 457 
 458         hash = HASH(entry->ip);
 459 
 460         /* proxy entries shouldn't really time out so this is really
 461            only here for completeness
 462         */
 463 
 464         /* RFC1122: They *can* be timed out, according to 2.3.2.1. */
 465         /* They recommend a minute. -- MS */
 466         /* The world doesn't work this way -- AC */
 467 
 468         if (entry->flags & ATF_PUBL)
 469           pentry = &arp_tables[PROXY_HASH];
 470         else
 471           pentry = &arp_tables[hash];
 472         while (*pentry != NULL)
 473         {
 474                 if (*pentry == entry)
 475                 {
 476                         *pentry = entry->next;  /* delete from linked list */
 477                         del_timer(&entry->timer);
 478                         restore_flags(flags);
 479                         arp_release_entry(entry);
 480                         arp_cache_stamp++;
 481                         return;
 482                 }
 483                 pentry = &(*pentry)->next;
 484         }
 485         restore_flags(flags);
 486         printk("Possible ARP queue corruption.\n");
 487         /*
 488          *      We should never arrive here.
 489          */
 490 
 491         /* Should we perhaps flush the ARP table (except the ones we're */
 492         /* publishing, if we can trust the queue that much) at this */
 493         /* point? -- MS */
 494 }
 495 
 496 
 497 /*
 498  *      This will try to retransmit everything on the queue.
 499  */
 500 
 501 static void arp_send_q(struct arp_table *entry, unsigned char *hw_dest)
     /* [previous][next][first][last][top][bottom][index][help] */
 502 {
 503         struct sk_buff *skb;
 504 
 505         unsigned long flags;
 506 
 507         /*
 508          *      Empty the entire queue, building its data up ready to send
 509          */
 510         
 511         if(!(entry->flags&ATF_COM))
 512         {
 513                 printk("arp_send_q: incomplete entry for %s\n",
 514                                 in_ntoa(entry->ip));
 515                 /* Can't flush the skb, because RFC1122 says to hang on to */
 516                 /* at least one from any unresolved entry.  --MS */
 517                 /* Whats happened is that someone has 'unresolved' the entry
 518                    as we got to use it - this 'can't happen' -- AC */
 519                 return;
 520         }
 521 
 522         save_flags(flags);
 523         
 524         cli();
 525         while((skb = skb_dequeue(&entry->skb)) != NULL)
 526         {
 527                 IS_SKB(skb);
 528                 skb_device_lock(skb);
 529                 restore_flags(flags);
 530                 if(!skb->dev->rebuild_header(skb->data,skb->dev,skb->raddr,skb))
 531                 {
 532                         skb->arp  = 1;
 533                         if(skb->sk==NULL)
 534                                 dev_queue_xmit(skb, skb->dev, 0);
 535                         else
 536                                 dev_queue_xmit(skb,skb->dev,skb->sk->priority);
 537                 }
 538         }
 539         restore_flags(flags);
 540 }
 541 
 542 
 543 /*
 544  *      Delete an ARP mapping entry in the cache.
 545  */
 546 
 547 void arp_destroy(u32 ip_addr, int force)
     /* [previous][next][first][last][top][bottom][index][help] */
 548 {
 549         int checked_proxies = 0;
 550         struct arp_table *entry;
 551         struct arp_table **pentry;
 552         unsigned long hash = HASH(ip_addr);
 553 
 554 ugly:
 555         cli();
 556         pentry = &arp_tables[hash];
 557         if (! *pentry) /* also check proxy entries */
 558           pentry = &arp_tables[PROXY_HASH];
 559 
 560         while ((entry = *pentry) != NULL)
 561         {
 562                 if (entry->ip == ip_addr)
 563                 {
 564                         if ((entry->flags & ATF_PERM) && !force) {
 565                                 sti();
 566                                 return;
 567                         }
 568                         *pentry = entry->next;
 569                         del_timer(&entry->timer);
 570                         sti();
 571                         arp_release_entry(entry);
 572                         /* this would have to be cleaned up */
 573                         goto ugly;
 574                         /* perhaps like this ?
 575                         cli();
 576                         entry = *pentry;
 577                         */
 578                 }
 579                 pentry = &entry->next;
 580                 if (!checked_proxies && ! *pentry)
 581                   { /* ugly. we have to make sure we check proxy
 582                        entries as well */
 583                     checked_proxies = 1;
 584                     pentry = &arp_tables[PROXY_HASH];
 585                   }
 586         }
 587         sti();
 588 }
 589 
 590 
 591 /*
 592  *      Receive an arp request by the device layer. Maybe I rewrite it, to
 593  *      use the incoming packet for the reply. The time for the current
 594  *      "overhead" isn't that high...
 595  */
 596 
 597 int arp_rcv(struct sk_buff *skb, struct device *dev, struct packet_type *pt)
     /* [previous][next][first][last][top][bottom][index][help] */
 598 {
 599 /*
 600  *      We shouldn't use this type conversion. Check later.
 601  */
 602         
 603         struct arphdr *arp = (struct arphdr *)skb->h.raw;
 604         unsigned char *arp_ptr= (unsigned char *)(arp+1);
 605         struct arp_table *entry;
 606         struct arp_table *proxy_entry;
 607         int hlen,htype;
 608         unsigned long hash;
 609         unsigned char ha[MAX_ADDR_LEN]; /* So we can enable ints again. */
 610         unsigned char *sha,*tha;
 611         u32 sip,tip;
 612         
 613 /*
 614  *      The hardware length of the packet should match the hardware length
 615  *      of the device.  Similarly, the hardware types should match.  The
 616  *      device should be ARP-able.  Also, if pln is not 4, then the lookup
 617  *      is not from an IP number.  We can't currently handle this, so toss
 618  *      it. 
 619  */  
 620         if (arp->ar_hln != dev->addr_len    || 
 621                 dev->type != ntohs(arp->ar_hrd) || 
 622                 dev->flags & IFF_NOARP          ||
 623                 arp->ar_pln != 4)
 624         {
 625                 kfree_skb(skb, FREE_READ);
 626                 return 0;
 627                 /* Should this be an error/printk?  Seems like something */
 628                 /* you'd want to know about. Unless it's just !IFF_NOARP. -- MS */
 629         }
 630 
 631 /*
 632  *      Another test.
 633  *      The logic here is that the protocol being looked up by arp should 
 634  *      match the protocol the device speaks.  If it doesn't, there is a
 635  *      problem, so toss the packet.
 636  */
 637 /* Again, should this be an error/printk? -- MS */
 638 
 639         switch(dev->type)
 640         {
 641 #ifdef CONFIG_AX25
 642                 case ARPHRD_AX25:
 643                         if(arp->ar_pro != htons(AX25_P_IP))
 644                         {
 645                                 kfree_skb(skb, FREE_READ);
 646                                 return 0;
 647                         }
 648                         break;
 649 #endif
 650 #ifdef CONFIG_NETROM
 651                 case ARPHRD_NETROM:
 652                         if(arp->ar_pro != htons(AX25_P_IP))
 653                         {
 654                                 kfree_skb(skb, FREE_READ);
 655                                 return 0;
 656                         }
 657                         break;
 658 #endif
 659                 case ARPHRD_ETHER:
 660                 case ARPHRD_ARCNET:
 661                         if(arp->ar_pro != htons(ETH_P_IP))
 662                         {
 663                                 kfree_skb(skb, FREE_READ);
 664                                 return 0;
 665                         }
 666                         break;
 667 
 668                 case ARPHRD_IEEE802:
 669                         if(arp->ar_pro != htons(ETH_P_IP))
 670                         {
 671                                 kfree_skb(skb, FREE_READ);
 672                                 return 0;
 673                         }
 674                         break;
 675 
 676                 default:
 677                         printk("ARP: dev->type mangled!\n");
 678                         kfree_skb(skb, FREE_READ);
 679                         return 0;
 680         }
 681 
 682 /*
 683  *      Extract fields
 684  */
 685 
 686         hlen  = dev->addr_len;
 687         htype = dev->type;
 688 
 689         sha=arp_ptr;
 690         arp_ptr+=hlen;
 691         memcpy(&sip,arp_ptr,4);
 692         arp_ptr+=4;
 693         tha=arp_ptr;
 694         arp_ptr+=hlen;
 695         memcpy(&tip,arp_ptr,4);
 696   
 697 /* 
 698  *      Check for bad requests for 127.x.x.x and requests for multicast
 699  *      addresses.  If this is one such, delete it.
 700  */
 701         if (LOOPBACK(tip) || MULTICAST(tip))
 702         {
 703                 kfree_skb(skb, FREE_READ);
 704                 return 0;
 705         }
 706 
 707 /*
 708  *  Process entry.  The idea here is we want to send a reply if it is a
 709  *  request for us or if it is a request for someone else that we hold
 710  *  a proxy for.  We want to add an entry to our cache if it is a reply
 711  *  to us or if it is a request for our address.  
 712  *  (The assumption for this last is that if someone is requesting our 
 713  *  address, they are probably intending to talk to us, so it saves time 
 714  *  if we cache their address.  Their address is also probably not in 
 715  *  our cache, since ours is not in their cache.)
 716  * 
 717  *  Putting this another way, we only care about replies if they are to
 718  *  us, in which case we add them to the cache.  For requests, we care
 719  *  about those for us and those for our proxies.  We reply to both,
 720  *  and in the case of requests for us we add the requester to the arp 
 721  *  cache.
 722  */
 723 
 724         if(arp->ar_op == htons(ARPOP_REQUEST))
 725         { 
 726 /*
 727  * Only reply for the real device address or when it's in our proxy tables
 728  */
 729                 if(tip!=dev->pa_addr)
 730                 {
 731 /*
 732  *      To get in here, it is a request for someone else.  We need to
 733  *      check if that someone else is one of our proxies.  If it isn't,
 734  *      we can toss it.
 735  */
 736                         cli();
 737                         for(proxy_entry=arp_tables[PROXY_HASH];
 738                             proxy_entry;
 739                             proxy_entry = proxy_entry->next)
 740                         {
 741                           /* we will respond to a proxy arp request
 742                              if the masked arp table ip matches the masked
 743                              tip. This allows a single proxy arp table
 744                              entry to be used on a gateway machine to handle
 745                              all requests for a whole network, rather than
 746                              having to use a huge number of proxy arp entries
 747                              and having to keep them uptodate.
 748                              */
 749                           if (proxy_entry->dev != dev && proxy_entry->htype == htype &&
 750                               !((proxy_entry->ip^tip)&proxy_entry->mask))
 751                             break;
 752 
 753                         }
 754                         if (proxy_entry)
 755                         {
 756                                 memcpy(ha, proxy_entry->ha, hlen);
 757                                 sti();
 758                                 arp_send(ARPOP_REPLY,ETH_P_ARP,sip,dev,tip,sha,ha);
 759                                 kfree_skb(skb, FREE_READ);
 760                                 return 0;
 761                         }
 762                         else
 763                         {
 764                                 sti();
 765                                 kfree_skb(skb, FREE_READ);
 766                                 return 0;
 767                         }
 768                 }
 769                 else
 770                 {
 771 /*
 772  *      To get here, it must be an arp request for us.  We need to reply.
 773  */
 774                         arp_send(ARPOP_REPLY,ETH_P_ARP,sip,dev,tip,sha,dev->dev_addr);
 775                 }
 776         }
 777 /*
 778  *      It is now an arp reply.
 779  */
 780         if(ip_chk_addr(tip)!=IS_MYADDR)
 781         {
 782 /*
 783  *      Replies to other machines get tossed.
 784  */
 785                 kfree_skb(skb, FREE_READ);
 786                 return 0;
 787         }
 788 /*
 789  * Now all replies are handled.  Next, anything that falls through to here
 790  * needs to be added to the arp cache, or have its entry updated if it is 
 791  * there.
 792  */
 793 
 794         hash = HASH(sip);
 795         cli();
 796         for(entry=arp_tables[hash];entry;entry=entry->next)
 797                 if(entry->ip==sip && entry->htype==htype)
 798                         break;
 799 
 800         if(entry)
 801         {
 802 /*
 803  *      Entry found; update it only if it is not a permanent entry.
 804  */
 805                 if (!(entry->flags & ATF_PERM)) {
 806                         memcpy(entry->ha, sha, hlen);
 807                         entry->hlen = hlen;
 808                         entry->last_used = jiffies;
 809                 }
 810                 if (!(entry->flags & ATF_COM))
 811                 {
 812 /*
 813  *      This entry was incomplete.  Delete the retransmit timer
 814  *      and switch to complete status.
 815  */
 816                         del_timer(&entry->timer);
 817                         entry->flags |= ATF_COM;
 818                         sti();
 819 /* 
 820  *      Send out waiting packets. We might have problems, if someone is 
 821  *      manually removing entries right now -- entry might become invalid 
 822  *      underneath us.
 823  */
 824                         arp_send_q(entry, sha);
 825                 }
 826                 else
 827                 {
 828                         sti();
 829                 }
 830         }
 831         else
 832         {
 833 /*
 834  *      No entry found.  Need to add a new entry to the arp table.
 835  */
 836                 entry = (struct arp_table *)kmalloc(sizeof(struct arp_table),GFP_ATOMIC);
 837                 if(entry == NULL)
 838                 {
 839                         sti();
 840                         printk("ARP: no memory for new arp entry\n");
 841 
 842                         kfree_skb(skb, FREE_READ);
 843                         return 0;
 844                 }
 845 
 846                 entry->mask = DEF_ARP_NETMASK;
 847                 entry->ip = sip;
 848                 entry->hlen = hlen;
 849                 entry->htype = htype;
 850                 entry->flags = ATF_COM;
 851                 init_timer(&entry->timer);
 852                 memcpy(entry->ha, sha, hlen);
 853                 entry->last_used = jiffies;
 854                 entry->dev = skb->dev;
 855                 skb_queue_head_init(&entry->skb);
 856                 entry->next = arp_tables[hash];
 857                 arp_tables[hash] = entry;
 858                 sti();
 859         }
 860 
 861 /*
 862  *      Replies have been sent, and entries have been added.  All done.
 863  */
 864         kfree_skb(skb, FREE_READ);
 865         return 0;
 866 }
 867 
 868 
 869 /*
 870  *      Find an arp mapping in the cache. If not found, return false.
 871  */
 872 
 873 int arp_query(unsigned char *haddr, u32 paddr, unsigned short type)
     /* [previous][next][first][last][top][bottom][index][help] */
 874 {
 875         struct arp_table *entry;
 876         unsigned long hash = HASH(paddr);
 877 
 878         /*
 879          *      Find an entry
 880          */
 881         cli();
 882 
 883         for (entry = arp_tables[hash]; entry != NULL; entry = entry->next)
 884                 if (entry->ip == paddr && entry->htype == type)
 885                         break;
 886 
 887         if (entry != NULL) {
 888                 /*
 889                  *      Update the record
 890                  */
 891                 
 892                 entry->last_used = jiffies;
 893                 memcpy(haddr, entry->ha, entry->hlen);
 894                 sti();
 895                 return 1;
 896         }
 897 
 898         sti();
 899         return 0;
 900 }
 901 
 902 /*
 903  *      Find an arp mapping in the cache. If not found, post a request.
 904  */
 905 
 906 int arp_find(unsigned char *haddr, u32 paddr, struct device *dev,
     /* [previous][next][first][last][top][bottom][index][help] */
 907            u32 saddr, struct sk_buff *skb)
 908 {
 909         struct arp_table *entry;
 910         unsigned long hash;
 911 #ifdef CONFIG_IP_MULTICAST
 912         u32 taddr;
 913 #endif  
 914 
 915         switch (ip_chk_addr(paddr))
 916         {
 917                 case IS_MYADDR:
 918                         printk("ARP: arp called for own IP address\n");
 919                         memcpy(haddr, dev->dev_addr, dev->addr_len);
 920                         skb->arp = 1;
 921                         return 0;
 922 #ifdef CONFIG_IP_MULTICAST
 923                 case IS_MULTICAST:
 924                         if(dev->type==ARPHRD_ETHER || dev->type==ARPHRD_IEEE802)
 925                         {
 926                                 /* What exactly does this do? -- MS */
 927                                 haddr[0]=0x01;
 928                                 haddr[1]=0x00;
 929                                 haddr[2]=0x5e;
 930                                 taddr=ntohl(paddr);
 931                                 haddr[5]=taddr&0xff;
 932                                 taddr=taddr>>8;
 933                                 haddr[4]=taddr&0xff;
 934                                 taddr=taddr>>8;
 935                                 haddr[3]=taddr&0x7f;
 936                                 return 0;
 937                         }
 938                 /*
 939                  *      If a device does not support multicast broadcast the stuff (eg AX.25 for now)
 940                  */
 941 #endif
 942                 
 943                 case IS_BROADCAST:
 944                         memcpy(haddr, dev->broadcast, dev->addr_len);
 945                         skb->arp = 1;
 946                         return 0;
 947         }
 948 
 949         hash = HASH(paddr);
 950         cli();
 951 
 952         /*
 953          *      Find an entry
 954          */
 955         entry = arp_lookup(paddr, PROXY_NONE, dev->type);
 956 
 957         if (entry != NULL)      /* It exists */
 958         {
 959                 if (!(entry->flags & ATF_COM))
 960                 {
 961                         /*
 962                          *      A request was already send, but no reply yet. Thus
 963                          *      queue the packet with the previous attempt
 964                          */
 965                         
 966                         if (skb != NULL)
 967                         {
 968                                 skb_queue_tail(&entry->skb, skb);
 969                                 skb_device_unlock(skb);
 970                         }
 971                         sti();
 972                         return 1;
 973                 }
 974 
 975                 /*
 976                  *      Update the record
 977                  */
 978                 
 979                 entry->last_used = jiffies;
 980                 memcpy(haddr, entry->ha, dev->addr_len);
 981                 if (skb)
 982                         skb->arp = 1;
 983                 sti();
 984                 return 0;
 985         }
 986 
 987         /*
 988          *      Create a new unresolved entry.
 989          */
 990         
 991         entry = (struct arp_table *) kmalloc(sizeof(struct arp_table),
 992                                         GFP_ATOMIC);
 993         if (entry != NULL)
 994         {
 995                 entry->next = arp_tables[hash];
 996                 entry->last_used = jiffies;
 997                 entry->flags = 0;
 998                 entry->ip = paddr;
 999                 entry->mask = DEF_ARP_NETMASK;
1000                 memset(entry->ha, 0, dev->addr_len);
1001                 entry->hlen = dev->addr_len;
1002                 entry->htype = dev->type;
1003                 entry->dev = dev;
1004                 init_timer(&entry->timer);
1005                 entry->timer.function = arp_expire_request;
1006                 entry->timer.data = (unsigned long)entry;
1007                 entry->timer.expires = jiffies + ARP_RES_TIME;
1008                 arp_tables[hash] = entry;
1009                 add_timer(&entry->timer);
1010                 entry->retries = ARP_MAX_TRIES;
1011                 skb_queue_head_init(&entry->skb);
1012                 if (skb != NULL)
1013                 {
1014                         skb_queue_tail(&entry->skb, skb);
1015                         skb_device_unlock(skb);
1016                 }
1017         }
1018         else
1019         {
1020                 if (skb != NULL && skb->free)
1021                         kfree_skb(skb, FREE_WRITE);
1022         }
1023         sti();
1024 
1025         /*
1026          *      If we didn't find an entry, we will try to send an ARP packet.
1027          */
1028         
1029         arp_send(ARPOP_REQUEST, ETH_P_ARP, paddr, dev, saddr, NULL, 
1030                  dev->dev_addr);
1031 
1032         return 1;
1033 }
1034 
1035 
1036 /*
1037  *      Write the contents of the ARP cache to a PROCfs file.
1038  */
1039 
1040 #define HBUFFERLEN 30
1041 
1042 int arp_get_info(char *buffer, char **start, off_t offset, int length, int dummy)
     /* [previous][next][first][last][top][bottom][index][help] */
1043 {
1044         int len=0;
1045         off_t begin=0;
1046         off_t pos=0;
1047         int size;
1048         struct arp_table *entry;
1049         char hbuffer[HBUFFERLEN];
1050         int i,j,k;
1051         const char hexbuf[] =  "0123456789ABCDEF";
1052 
1053         size = sprintf(buffer,"IP address       HW type     Flags       HW address            Mask\n");
1054 
1055         pos+=size;
1056         len+=size;
1057           
1058         cli();
1059         for(i=0; i<FULL_ARP_TABLE_SIZE; i++)
1060         {
1061                 for(entry=arp_tables[i]; entry!=NULL; entry=entry->next)
1062                 {
1063 /*
1064  *      Convert hardware address to XX:XX:XX:XX ... form.
1065  */
1066 #ifdef CONFIG_AX25
1067 #ifdef CONFIG_NETROM
1068                         if (entry->htype == ARPHRD_AX25 || entry->htype == ARPHRD_NETROM)
1069                              strcpy(hbuffer,ax2asc((ax25_address *)entry->ha));
1070                         else {
1071 #else
1072                         if(entry->htype==ARPHRD_AX25)
1073                              strcpy(hbuffer,ax2asc((ax25_address *)entry->ha));
1074                         else {
1075 #endif
1076 #endif
1077 
1078                         for(k=0,j=0;k<HBUFFERLEN-3 && j<entry->hlen;j++)
1079                         {
1080                                 hbuffer[k++]=hexbuf[ (entry->ha[j]>>4)&15 ];
1081                                 hbuffer[k++]=hexbuf[  entry->ha[j]&15     ];
1082                                 hbuffer[k++]=':';
1083                         }
1084                         hbuffer[--k]=0;
1085         
1086 #ifdef CONFIG_AX25
1087                         }
1088 #endif
1089                         size = sprintf(buffer+len,
1090                                 "%-17s0x%-10x0x%-10x%s",
1091                                 in_ntoa(entry->ip),
1092                                 (unsigned int)entry->htype,
1093                                 entry->flags,
1094                                 hbuffer);
1095                         size += sprintf(buffer+len+size,
1096                                  "     %-17s\n",
1097                                   entry->mask==DEF_ARP_NETMASK?
1098                                    "*":in_ntoa(entry->mask));
1099         
1100                         len+=size;
1101                         pos=begin+len;
1102                   
1103                         if(pos<offset)
1104                         {
1105                                 len=0;
1106                                 begin=pos;
1107                         }
1108                         if(pos>offset+length)
1109                                 break;
1110                 }
1111         }
1112         sti();
1113   
1114         *start=buffer+(offset-begin);   /* Start of wanted data */
1115         len-=(offset-begin);            /* Start slop */
1116         if(len>length)
1117                 len=length;                     /* Ending slop */
1118         return len;
1119 }
1120 
1121 
1122 /*
1123  *      This will find an entry in the ARP table by looking at the IP address.
1124  *      If proxy is PROXY_EXACT then only exact IP matches will be allowed
1125  *      for proxy entries, otherwise the netmask will be used
1126  */
1127 
1128 static struct arp_table *arp_lookup(u32 paddr, enum proxy proxy, unsigned short type)
     /* [previous][next][first][last][top][bottom][index][help] */
1129 {
1130         struct arp_table *entry;
1131         unsigned long hash = HASH(paddr);
1132         
1133         for (entry = arp_tables[hash]; entry != NULL; entry = entry->next)
1134                 if (entry->ip == paddr && entry->htype == type)
1135                         break;
1136 
1137         /* it's possibly a proxy entry (with a netmask) */
1138         if (!entry && proxy != PROXY_NONE)
1139         for (entry=arp_tables[PROXY_HASH]; entry != NULL; entry = entry->next)
1140           if ((proxy==PROXY_EXACT) ? (entry->ip==paddr)
1141                                    : !((entry->ip^paddr)&entry->mask)) 
1142             break;        
1143 
1144         return entry;
1145 }
1146 
1147 
1148 int arp_find_cache(unsigned char *dp, u32 daddr, struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
1149 {       
1150         /* 
1151          *      We need the broadcast/multicast awareness here and the find routine split up.
1152          */
1153         struct arp_table *entry;
1154 #ifdef CONFIG_IP_MULTICAST
1155         u32 taddr;
1156 #endif  
1157 
1158         switch (ip_chk_addr(daddr))
1159         {
1160                 case IS_MYADDR:
1161                         printk("ARP: arp called for own IP address\n");
1162                         memcpy(dp, dev->dev_addr, dev->addr_len);
1163                         return 1;
1164 #ifdef CONFIG_IP_MULTICAST
1165                 case IS_MULTICAST:
1166                         if(dev->type==ARPHRD_ETHER || dev->type==ARPHRD_IEEE802)
1167                         {
1168                                 dp[0]=0x01;
1169                                 dp[1]=0x00;
1170                                 dp[2]=0x5e;
1171                                 taddr=ntohl(daddr);
1172                                 dp[5]=taddr&0xff;
1173                                 taddr=taddr>>8;
1174                                 dp[4]=taddr&0xff;
1175                                 taddr=taddr>>8;
1176                                 dp[3]=taddr&0x7f;
1177                                 return 1;
1178                         }
1179                 /*
1180                  *      If a device does not support multicast broadcast the stuff (eg AX.25 for now)
1181                  */
1182 #endif
1183                 
1184                 case IS_BROADCAST:
1185                         memcpy(dp, dev->broadcast, dev->addr_len);
1186                         return 1;
1187                         
1188                 default:
1189                         entry=arp_lookup(daddr, PROXY_NONE, dev->type);
1190                         if(entry)
1191                         {
1192                                 memcpy(dp,entry->ha, ETH_ALEN);
1193                                 return 1;
1194                         }
1195         }
1196         return 0;
1197 }
1198 
1199 /*
1200  *      Set (create) an ARP cache entry.
1201  */
1202 
1203 static int arp_req_set(struct arpreq *req)
     /* [previous][next][first][last][top][bottom][index][help] */
1204 {
1205         struct arpreq r;
1206         struct arp_table *entry;
1207         struct sockaddr_in *si;
1208         int htype, hlen;
1209         struct rtable *rt;
1210         u32 ip;
1211 
1212         memcpy_fromfs(&r, req, sizeof(r));
1213 
1214         /* We only understand about IP addresses... */
1215         if (r.arp_pa.sa_family != AF_INET)
1216                 return -EPFNOSUPPORT;
1217 
1218         /*
1219          * Find out about the hardware type.
1220          * We have to be compatible with BSD UNIX, so we have to
1221          * assume that a "not set" value (i.e. 0) means Ethernet.
1222          */
1223         
1224         switch (r.arp_ha.sa_family) {
1225                 case ARPHRD_ETHER:
1226                         htype = ARPHRD_ETHER;
1227                         hlen = ETH_ALEN;
1228                         break;
1229 
1230                 case ARPHRD_ARCNET:
1231                         htype = ARPHRD_ARCNET;
1232                         hlen = 1;       /* length of arcnet addresses */
1233                         break;
1234 
1235 #ifdef CONFIG_AX25
1236                 case ARPHRD_AX25:
1237                         htype = ARPHRD_AX25;
1238                         hlen = AX25_ADDR_LEN;
1239                         break;
1240 #endif
1241 #ifdef CONFIG_NETROM
1242                 case ARPHRD_NETROM:
1243                         htype = ARPHRD_NETROM;
1244                         hlen = AX25_ADDR_LEN;
1245                         break;
1246 #endif
1247                 case ARPHRD_IEEE802:
1248                         htype = ARPHRD_IEEE802;
1249                         hlen = TR_ALEN;
1250                         break;
1251                 default:
1252                         return -EPFNOSUPPORT;
1253         }
1254 
1255         si = (struct sockaddr_in *) &r.arp_pa;
1256         ip = si->sin_addr.s_addr;
1257         if (ip == 0)
1258         {
1259                 printk("ARP: SETARP: requested PA is 0.0.0.0 !\n");
1260                 return -EINVAL;
1261         }
1262 
1263         /*
1264          *      Is it reachable directly ?
1265          */
1266 
1267         rt = ip_rt_route(ip, NULL, NULL);
1268         if (rt == NULL)
1269                 return -ENETUNREACH;
1270 
1271         /*
1272          *      Is there an existing entry for this address?
1273          */
1274         
1275         cli();
1276 
1277         /*
1278          *      Find the entry
1279          */
1280         entry = arp_lookup(ip, PROXY_EXACT, htype);
1281         if (entry && (entry->flags & ATF_PUBL) != (r.arp_flags & ATF_PUBL))
1282         {
1283                 sti();
1284                 arp_destroy(ip,1);
1285                 cli();
1286                 entry = NULL;
1287         }
1288 
1289         /*
1290          *      Do we need to create a new entry
1291          */
1292         
1293         if (entry == NULL)
1294         {
1295                 unsigned long hash = HASH(ip);
1296                 if (r.arp_flags & ATF_PUBL)
1297                   hash = PROXY_HASH;
1298 
1299                 entry = (struct arp_table *) kmalloc(sizeof(struct arp_table),
1300                                         GFP_ATOMIC);
1301                 if (entry == NULL)
1302                 {
1303                         sti();
1304                         return -ENOMEM;
1305                 }
1306                 entry->ip = ip;
1307                 entry->hlen = hlen;
1308                 entry->htype = htype;
1309                 init_timer(&entry->timer);
1310                 entry->next = arp_tables[hash];
1311                 arp_tables[hash] = entry;
1312                 skb_queue_head_init(&entry->skb);
1313         }
1314         /*
1315          *      We now have a pointer to an ARP entry.  Update it!
1316          */
1317         
1318         memcpy(&entry->ha, &r.arp_ha.sa_data, hlen);
1319         entry->last_used = jiffies;
1320         entry->flags = r.arp_flags | ATF_COM;
1321         if ((entry->flags & ATF_PUBL) && (entry->flags & ATF_NETMASK))
1322           {
1323             si = (struct sockaddr_in *) &r.arp_netmask;
1324             entry->mask = si->sin_addr.s_addr;
1325           }
1326         else
1327           entry->mask = DEF_ARP_NETMASK;
1328         entry->dev = rt->rt_dev;
1329         arp_cache_stamp++;
1330         sti();
1331 
1332         return 0;
1333 }
1334 
1335 
1336 /*
1337  *      Get an ARP cache entry.
1338  */
1339 
1340 static int arp_req_get(struct arpreq *req)
     /* [previous][next][first][last][top][bottom][index][help] */
1341 {
1342         struct arpreq r;
1343         struct arp_table *entry;
1344         struct sockaddr_in *si;
1345 
1346         /*
1347          *      We only understand about IP addresses...
1348          */
1349         
1350         memcpy_fromfs(&r, req, sizeof(r));
1351 
1352         if (r.arp_pa.sa_family != AF_INET)
1353                 return -EPFNOSUPPORT;
1354 
1355         /*
1356          *      Is there an existing entry for this address?
1357          */
1358         
1359         si = (struct sockaddr_in *) &r.arp_pa;
1360         cli();
1361         entry = arp_lookup(si->sin_addr.s_addr, PROXY_ANY, r.arp_ha.sa_family);
1362 
1363         if (entry == NULL)
1364         {
1365                 sti();
1366                 return -ENXIO;
1367         }
1368 
1369         /*
1370          *      We found it; copy into structure.
1371          */
1372         
1373         memcpy(r.arp_ha.sa_data, &entry->ha, entry->hlen);
1374         r.arp_ha.sa_family = entry->htype;
1375         r.arp_flags = entry->flags;
1376         sti();
1377 
1378         /*
1379          *      Copy the information back
1380          */
1381         
1382         memcpy_tofs(req, &r, sizeof(r));
1383         return 0;
1384 }
1385 
1386 
1387 /*
1388  *      Handle an ARP layer I/O control request.
1389  */
1390 
1391 int arp_ioctl(unsigned int cmd, void *arg)
     /* [previous][next][first][last][top][bottom][index][help] */
1392 {
1393         struct arpreq r;
1394         struct sockaddr_in *si;
1395         int err;
1396 
1397         switch(cmd)
1398         {
1399                 case SIOCDARP:
1400                         if (!suser())
1401                                 return -EPERM;
1402                         err = verify_area(VERIFY_READ, arg, sizeof(struct arpreq));
1403                         if(err)
1404                                 return err;
1405                         memcpy_fromfs(&r, arg, sizeof(r));
1406                         if (r.arp_pa.sa_family != AF_INET)
1407                                 return -EPFNOSUPPORT;
1408                         si = (struct sockaddr_in *) &r.arp_pa;
1409                         arp_destroy(si->sin_addr.s_addr, 1);
1410                         return 0;
1411                 case SIOCGARP:
1412                         err = verify_area(VERIFY_WRITE, arg, sizeof(struct arpreq));
1413                         if(err)
1414                                 return err;
1415                         return arp_req_get((struct arpreq *)arg);
1416                 case SIOCSARP:
1417                         if (!suser())
1418                                 return -EPERM;
1419                         err = verify_area(VERIFY_READ, arg, sizeof(struct arpreq));
1420                         if(err)
1421                                 return err;
1422                         return arp_req_set((struct arpreq *)arg);
1423                 default:
1424                         return -EINVAL;
1425         }
1426         /*NOTREACHED*/
1427         return 0;
1428 }
1429 
1430 
1431 /*
1432  *      Called once on startup.
1433  */
1434 
1435 static struct packet_type arp_packet_type =
1436 {
1437         0,      /* Should be: __constant_htons(ETH_P_ARP) - but this _doesn't_ come out constant! */
1438         NULL,           /* All devices */
1439         arp_rcv,
1440         NULL,
1441         NULL
1442 };
1443 
1444 static struct notifier_block arp_dev_notifier={
1445         arp_device_event,
1446         NULL,
1447         0
1448 };
1449 
1450 void arp_init (void)
     /* [previous][next][first][last][top][bottom][index][help] */
1451 {
1452         /* Register the packet type */
1453         arp_packet_type.type=htons(ETH_P_ARP);
1454         dev_add_pack(&arp_packet_type);
1455         /* Start with the regular checks for expired arp entries. */
1456         add_timer(&arp_timer);
1457         /* Register for device down reports */
1458         register_netdevice_notifier(&arp_dev_notifier);
1459 
1460         proc_net_register(&(struct proc_dir_entry) {
1461                 PROC_NET_ARP, 3, "arp",
1462                 S_IFREG | S_IRUGO, 1, 0, 0,
1463                 0, &proc_net_inode_operations,
1464                 arp_get_info
1465         });
1466 }
1467 

/* [previous][next][first][last][top][bottom][index][help] */