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  */
  44 
  45 /* RFC1122 Status:
  46    2.3.2.1 (ARP Cache Validation):
  47      MUST provide mechanism to flush stale cache entries (OK)
  48      SHOULD be able to configure cache timeout (NOT YET)
  49      MUST throttle ARP retransmits (OK)
  50    2.3.2.2 (ARP Packet Queue):
  51      SHOULD save at least one packet from each "conversation" with an
  52        unresolved IP address.  (OK)
  53    950727 -- MS
  54 */
  55       
  56 #include <linux/types.h>
  57 #include <linux/string.h>
  58 #include <linux/kernel.h>
  59 #include <linux/sched.h>
  60 #include <linux/config.h>
  61 #include <linux/socket.h>
  62 #include <linux/sockios.h>
  63 #include <linux/errno.h>
  64 #include <linux/if_arp.h>
  65 #include <linux/in.h>
  66 #include <linux/mm.h>
  67 #include <asm/system.h>
  68 #include <asm/segment.h>
  69 #include <stdarg.h>
  70 #include <linux/inet.h>
  71 #include <linux/netdevice.h>
  72 #include <linux/etherdevice.h>
  73 #include <linux/trdevice.h>
  74 #include <net/ip.h>
  75 #include <net/route.h>
  76 #include <net/protocol.h>
  77 #include <net/tcp.h>
  78 #include <linux/skbuff.h>
  79 #include <net/sock.h>
  80 #include <net/arp.h>
  81 #ifdef CONFIG_AX25
  82 #include <net/ax25.h>
  83 #ifdef CONFIG_NETROM
  84 #include <net/netrom.h>
  85 #endif
  86 #endif
  87 #include <linux/proc_fs.h>
  88 
  89 
  90 /*
  91  *      This structure defines the ARP mapping cache. As long as we make changes
  92  *      in this structure, we keep interrupts of. But normally we can copy the
  93  *      hardware address and the device pointer in a local variable and then make
  94  *      any "long calls" to send a packet out.
  95  */
  96 
  97 struct arp_table
  98 {
  99         struct arp_table                *next;                  /* Linked entry list            */
 100         unsigned long                   last_used;              /* For expiry                   */
 101         unsigned int                    flags;                  /* Control status               */
 102         u32                             ip;                     /* ip address of entry          */
 103         u32                             mask;                   /* netmask - used for generalised proxy arps (tridge)           */
 104         unsigned char                   ha[MAX_ADDR_LEN];       /* Hardware address             */
 105         unsigned char                   hlen;                   /* Length of hardware address   */
 106         unsigned short                  htype;                  /* Type of hardware in use      */
 107         struct device                   *dev;                   /* Device the entry is tied to  */
 108 
 109         /*
 110          *      The following entries are only used for unresolved hw addresses.
 111          */
 112         
 113         struct timer_list               timer;                  /* expire timer                 */
 114         int                             retries;                /* remaining retries            */
 115         struct sk_buff_head             skb;                    /* list of queued packets       */
 116 };
 117 
 118 
 119 /*
 120  *      Configurable Parameters (don't touch unless you know what you are doing
 121  */
 122 
 123 /*
 124  *      If an arp request is send, ARP_RES_TIME is the timeout value until the
 125  *      next request is send.
 126  */
 127 
 128 /* RFC1122: OK.  Throttles ARPing, as per 2.3.2.1. (MUST) */
 129 /* The recommended minimum timeout is 1 second per destination. */
 130 /* Is this a per-destination timeout? -- MS [YES AC]*/
 131 
 132 #define ARP_RES_TIME            (250*(HZ/10))
 133 
 134 /*
 135  *      The number of times an arp request is send, until the host is
 136  *      considered unreachable.
 137  */
 138 
 139 #define ARP_MAX_TRIES           3
 140 
 141 /*
 142  *      After that time, an unused entry is deleted from the arp table.
 143  */
 144 
 145 #define ARP_TIMEOUT             (600*HZ)
 146 
 147 /*
 148  *      How often is the function 'arp_check_retries' called.
 149  *      An entry is invalidated in the time between ARP_TIMEOUT and
 150  *      (ARP_TIMEOUT+ARP_CHECK_INTERVAL).
 151  */
 152 
 153 #define ARP_CHECK_INTERVAL      (60 * HZ)
 154 
 155 enum proxy {
 156    PROXY_EXACT=0,
 157    PROXY_ANY,
 158    PROXY_NONE,
 159 };
 160 
 161 /* Forward declarations. */
 162 static void arp_check_expire (unsigned long);  
 163 static struct arp_table *arp_lookup(u32 paddr, enum proxy proxy);
 164 
 165 
 166 static struct timer_list arp_timer =
 167         { NULL, NULL, ARP_CHECK_INTERVAL, 0L, &arp_check_expire };
 168 
 169 /*
 170  * The default arp netmask is just 255.255.255.255 which means it's
 171  * a single machine entry. Only proxy entries can have other netmasks
 172  *
 173 */
 174 
 175 #define DEF_ARP_NETMASK (~0)
 176 
 177 
 178 /*
 179  *      The size of the hash table. Must be a power of two.
 180  *      Maybe we should remove hashing in the future for arp and concentrate
 181  *      on Patrick Schaaf's Host-Cache-Lookup...
 182  */
 183 
 184 
 185 #define ARP_TABLE_SIZE  16
 186 
 187 /* The ugly +1 here is to cater for proxy entries. They are put in their 
 188    own list for efficiency of lookup. If you don't want to find a proxy
 189    entry then don't look in the last entry, otherwise do 
 190 */
 191 
 192 #define FULL_ARP_TABLE_SIZE (ARP_TABLE_SIZE+1)
 193 
 194 struct arp_table *arp_tables[FULL_ARP_TABLE_SIZE] =
 195 {
 196         NULL,
 197 };
 198 
 199 unsigned long arp_cache_stamp;
 200 
 201 
 202 /*
 203  *      The last bits in the IP address are used for the cache lookup.
 204  *      A special entry is used for proxy arp entries
 205  */
 206 
 207 #define HASH(paddr)             (htonl(paddr) & (ARP_TABLE_SIZE - 1))
 208 #define PROXY_HASH ARP_TABLE_SIZE
 209 
 210 /*
 211  *      Check if there are too old entries and remove them. If the ATF_PERM
 212  *      flag is set, they are always left in the arp cache (permanent entry).
 213  *      Note: Only fully resolved entries, which don't have any packets in
 214  *      the queue, can be deleted, since ARP_TIMEOUT is much greater than
 215  *      ARP_MAX_TRIES*ARP_RES_TIME.
 216  */
 217 
 218 /* RFC1122: Looks good.  Prevents stale ARP entries, as per 2.3.2.1. (MUST) */
 219 
 220 static void arp_check_expire(unsigned long dummy)
     /* [previous][next][first][last][top][bottom][index][help] */
 221 {
 222         int i;
 223         unsigned long now = jiffies;
 224         unsigned long flags;
 225         save_flags(flags);
 226         cli();
 227 
 228         for (i = 0; i < FULL_ARP_TABLE_SIZE; i++)
 229         {
 230                 struct arp_table *entry;
 231                 struct arp_table **pentry = &arp_tables[i];
 232 
 233                 while ((entry = *pentry) != NULL)
 234                 {
 235                         if ((now - entry->last_used) > ARP_TIMEOUT
 236                                 && !(entry->flags & ATF_PERM))
 237                         {
 238                                 *pentry = entry->next;  /* remove from list */
 239                                 arp_cache_stamp++;
 240                                 del_timer(&entry->timer);       /* Paranoia */
 241                                 kfree_s(entry, sizeof(struct arp_table)); 
 242                                 /* Don't have to remove packets in entry->skb. */
 243                                 /* See comments above. */
 244                         }
 245                         else
 246                                 pentry = &entry->next;  /* go to next entry */
 247                 }
 248         }
 249         restore_flags(flags);
 250 
 251         /*
 252          *      Set the timer again.
 253          */
 254 
 255         del_timer(&arp_timer);
 256         arp_timer.expires = jiffies + ARP_CHECK_INTERVAL;
 257         add_timer(&arp_timer);
 258 }
 259 
 260 
 261 /*
 262  *      Release all linked skb's and the memory for this entry.
 263  */
 264 
 265 static void arp_release_entry(struct arp_table *entry)
     /* [previous][next][first][last][top][bottom][index][help] */
 266 {
 267         struct sk_buff *skb;
 268         unsigned long flags;
 269 
 270         save_flags(flags);
 271         cli();
 272         /* Release the list of `skb' pointers. */
 273         while ((skb = skb_dequeue(&entry->skb)) != NULL)
 274         {
 275                 skb_device_lock(skb);
 276                 restore_flags(flags);
 277                 dev_kfree_skb(skb, FREE_WRITE);
 278         }
 279         restore_flags(flags);
 280         del_timer(&entry->timer);
 281         kfree_s(entry, sizeof(struct arp_table));
 282         return;
 283 }
 284 
 285 /*
 286  *      Purge a device from the ARP queue
 287  */
 288  
 289 int arp_device_event(unsigned long event, void *ptr)
     /* [previous][next][first][last][top][bottom][index][help] */
 290 {
 291         struct device *dev=ptr;
 292         int i;
 293         unsigned long flags;
 294         
 295         if(event!=NETDEV_DOWN)
 296                 return NOTIFY_DONE;
 297         /*
 298          *      This is a bit OTT - maybe we need some arp semaphores instead.
 299          */
 300          
 301         save_flags(flags);
 302         cli();
 303         for (i = 0; i < FULL_ARP_TABLE_SIZE; i++)
 304         {
 305                 struct arp_table *entry;
 306                 struct arp_table **pentry = &arp_tables[i];
 307 
 308                 while ((entry = *pentry) != NULL)
 309                 {
 310                         if(entry->dev==dev)
 311                         {
 312                                 *pentry = entry->next;  /* remove from list */
 313                                 del_timer(&entry->timer);       /* Paranoia */
 314                                 kfree_s(entry, sizeof(struct arp_table));
 315                         }
 316                         else
 317                                 pentry = &entry->next;  /* go to next entry */
 318                 }
 319         }
 320         arp_cache_stamp++;
 321         restore_flags(flags);
 322         return NOTIFY_DONE;
 323 }
 324 
 325 
 326 /*
 327  *      Create and send an arp packet. If (dest_hw == NULL), we create a broadcast
 328  *      message.
 329  */
 330 
 331 void arp_send(int type, int ptype, u32 dest_ip, 
     /* [previous][next][first][last][top][bottom][index][help] */
 332               struct device *dev, u32 src_ip, 
 333               unsigned char *dest_hw, unsigned char *src_hw)
 334 {
 335         struct sk_buff *skb;
 336         struct arphdr *arp;
 337         unsigned char *arp_ptr;
 338 
 339         /*
 340          *      No arp on this interface.
 341          */
 342         
 343         if(dev->flags&IFF_NOARP)
 344                 return;
 345 
 346         /*
 347          *      Allocate a buffer
 348          */
 349         
 350         skb = alloc_skb(sizeof(struct arphdr)+ 2*(dev->addr_len+4)
 351                                 + dev->hard_header_len, GFP_ATOMIC);
 352         if (skb == NULL)
 353         {
 354                 printk("ARP: no memory to send an arp packet\n");
 355                 return;
 356         }
 357         skb_reserve(skb, dev->hard_header_len);
 358         arp = (struct arphdr *) skb_put(skb,sizeof(struct arphdr) + 2*(dev->addr_len+4));
 359         skb->arp = 1;
 360         skb->dev = dev;
 361         skb->free = 1;
 362 
 363         /*
 364          *      Fill the device header for the ARP frame
 365          */
 366 
 367         dev->hard_header(skb,dev,ptype,dest_hw?dest_hw:dev->broadcast,src_hw?src_hw:NULL,skb->len);
 368 
 369         /* Fill out the arp protocol part. */
 370         arp->ar_hrd = htons(dev->type);
 371 #ifdef CONFIG_AX25
 372 #ifdef CONFIG_NETROM
 373         arp->ar_pro = (dev->type == ARPHRD_AX25 || dev->type == ARPHRD_NETROM) ? htons(AX25_P_IP) : htons(ETH_P_IP);
 374 #else
 375         arp->ar_pro = (dev->type != ARPHRD_AX25)? htons(ETH_P_IP) : htons(AX25_P_IP);
 376 #endif
 377 #else
 378         arp->ar_pro = htons(ETH_P_IP);
 379 #endif
 380         arp->ar_hln = dev->addr_len;
 381         arp->ar_pln = 4;
 382         arp->ar_op = htons(type);
 383 
 384         arp_ptr=(unsigned char *)(arp+1);
 385 
 386         memcpy(arp_ptr, src_hw, dev->addr_len);
 387         arp_ptr+=dev->addr_len;
 388         memcpy(arp_ptr, &src_ip,4);
 389         arp_ptr+=4;
 390         if (dest_hw != NULL)
 391                 memcpy(arp_ptr, dest_hw, dev->addr_len);
 392         else
 393                 memset(arp_ptr, 0, dev->addr_len);
 394         arp_ptr+=dev->addr_len;
 395         memcpy(arp_ptr, &dest_ip, 4);
 396 
 397         dev_queue_xmit(skb, dev, 0);
 398 }
 399 
 400 
 401 /*
 402  *      This function is called, if an entry is not resolved in ARP_RES_TIME.
 403  *      Either resend a request, or give it up and free the entry.
 404  */
 405 
 406 static void arp_expire_request (unsigned long arg)
     /* [previous][next][first][last][top][bottom][index][help] */
 407 {
 408         struct arp_table *entry = (struct arp_table *) arg;
 409         struct arp_table **pentry;
 410         unsigned long hash;
 411         unsigned long flags;
 412 
 413         save_flags(flags);
 414         cli();
 415 
 416         /*
 417          *      Since all timeouts are handled with interrupts enabled, there is a
 418          *      small chance, that this entry has just been resolved by an incoming
 419          *      packet. This is the only race condition, but it is handled...
 420          */
 421         
 422         if (entry->flags & ATF_COM)
 423         {
 424                 restore_flags(flags);
 425                 return;
 426         }
 427 
 428         if (--entry->retries > 0)
 429         {
 430                 u32 ip = entry->ip;
 431                 struct device *dev = entry->dev;
 432 
 433                 /* Set new timer. */
 434                 del_timer(&entry->timer);
 435                 entry->timer.expires = jiffies + ARP_RES_TIME;
 436                 add_timer(&entry->timer);
 437                 restore_flags(flags);
 438                 arp_send(ARPOP_REQUEST, ETH_P_ARP, ip, dev, dev->pa_addr, 
 439                          NULL, dev->dev_addr);
 440                 return;
 441         }
 442 
 443         /*
 444          *      Arp request timed out. Delete entry and all waiting packets.
 445          *      If we give each entry a pointer to itself, we don't have to
 446          *      loop through everything again. Maybe hash is good enough, but
 447          *      I will look at it later.
 448          */
 449 
 450         hash = HASH(entry->ip);
 451 
 452         /* proxy entries shouldn't really time out so this is really
 453            only here for completeness
 454         */
 455 
 456         /* RFC1122: They *can* be timed out, according to 2.3.2.1. */
 457         /* They recommend a minute. -- MS */
 458         /* The world doesn't work this way -- AC */
 459 
 460         if (entry->flags & ATF_PUBL)
 461           pentry = &arp_tables[PROXY_HASH];
 462         else
 463           pentry = &arp_tables[hash];
 464         while (*pentry != NULL)
 465         {
 466                 if (*pentry == entry)
 467                 {
 468                         *pentry = entry->next;  /* delete from linked list */
 469                         del_timer(&entry->timer);
 470                         restore_flags(flags);
 471                         arp_release_entry(entry);
 472                         arp_cache_stamp++;
 473                         return;
 474                 }
 475                 pentry = &(*pentry)->next;
 476         }
 477         restore_flags(flags);
 478         printk("Possible ARP queue corruption.\n");
 479         /*
 480          *      We should never arrive here.
 481          */
 482 
 483         /* Should we perhaps flush the ARP table (except the ones we're */
 484         /* publishing, if we can trust the queue that much) at this */
 485         /* point? -- MS */
 486 }
 487 
 488 
 489 /*
 490  *      This will try to retransmit everything on the queue.
 491  */
 492 
 493 static void arp_send_q(struct arp_table *entry, unsigned char *hw_dest)
     /* [previous][next][first][last][top][bottom][index][help] */
 494 {
 495         struct sk_buff *skb;
 496 
 497         unsigned long flags;
 498 
 499         /*
 500          *      Empty the entire queue, building its data up ready to send
 501          */
 502         
 503         if(!(entry->flags&ATF_COM))
 504         {
 505                 printk("arp_send_q: incomplete entry for %s\n",
 506                                 in_ntoa(entry->ip));
 507                 /* Can't flush the skb, because RFC1122 says to hang on to */
 508                 /* at least one from any unresolved entry.  --MS */
 509                 /* Whats happened is that someone has 'unresolved' the entry
 510                    as we got to use it - this 'can't happen' -- AC */
 511                 return;
 512         }
 513 
 514         save_flags(flags);
 515         
 516         cli();
 517         while((skb = skb_dequeue(&entry->skb)) != NULL)
 518         {
 519                 IS_SKB(skb);
 520                 skb_device_lock(skb);
 521                 restore_flags(flags);
 522                 if(!skb->dev->rebuild_header(skb->data,skb->dev,skb->raddr,skb))
 523                 {
 524                         skb->arp  = 1;
 525                         if(skb->sk==NULL)
 526                                 dev_queue_xmit(skb, skb->dev, 0);
 527                         else
 528                                 dev_queue_xmit(skb,skb->dev,skb->sk->priority);
 529                 }
 530         }
 531         restore_flags(flags);
 532 }
 533 
 534 
 535 /*
 536  *      Delete an ARP mapping entry in the cache.
 537  */
 538 
 539 void arp_destroy(u32 ip_addr, int force)
     /* [previous][next][first][last][top][bottom][index][help] */
 540 {
 541         int checked_proxies = 0;
 542         struct arp_table *entry;
 543         struct arp_table **pentry;
 544         unsigned long hash = HASH(ip_addr);
 545 
 546 ugly:
 547         cli();
 548         pentry = &arp_tables[hash];
 549         if (! *pentry) /* also check proxy entries */
 550           pentry = &arp_tables[PROXY_HASH];
 551 
 552         while ((entry = *pentry) != NULL)
 553         {
 554                 if (entry->ip == ip_addr)
 555                 {
 556                         if ((entry->flags & ATF_PERM) && !force)
 557                                 return;
 558                         *pentry = entry->next;
 559                         del_timer(&entry->timer);
 560                         sti();
 561                         arp_release_entry(entry);
 562                         /* this would have to be cleaned up */
 563                         goto ugly;
 564                         /* perhaps like this ?
 565                         cli();
 566                         entry = *pentry;
 567                         */
 568                 }
 569                 pentry = &entry->next;
 570                 if (!checked_proxies && ! *pentry)
 571                   { /* ugly. we have to make sure we check proxy
 572                        entries as well */
 573                     checked_proxies = 1;
 574                     pentry = &arp_tables[PROXY_HASH];
 575                   }
 576         }
 577         sti();
 578 }
 579 
 580 
 581 /*
 582  *      Receive an arp request by the device layer. Maybe I rewrite it, to
 583  *      use the incoming packet for the reply. The time for the current
 584  *      "overhead" isn't that high...
 585  */
 586 
 587 int arp_rcv(struct sk_buff *skb, struct device *dev, struct packet_type *pt)
     /* [previous][next][first][last][top][bottom][index][help] */
 588 {
 589 /*
 590  *      We shouldn't use this type conversion. Check later.
 591  */
 592         
 593         struct arphdr *arp = (struct arphdr *)skb->h.raw;
 594         unsigned char *arp_ptr= (unsigned char *)(arp+1);
 595         struct arp_table *entry;
 596         struct arp_table *proxy_entry;
 597         int addr_hint,hlen,htype;
 598         unsigned long hash;
 599         unsigned char ha[MAX_ADDR_LEN]; /* So we can enable ints again. */
 600         unsigned char *sha,*tha;
 601         u32 sip,tip;
 602         
 603 /*
 604  *      The hardware length of the packet should match the hardware length
 605  *      of the device.  Similarly, the hardware types should match.  The
 606  *      device should be ARP-able.  Also, if pln is not 4, then the lookup
 607  *      is not from an IP number.  We can't currently handle this, so toss
 608  *      it. 
 609  */  
 610         if (arp->ar_hln != dev->addr_len    || 
 611                 dev->type != ntohs(arp->ar_hrd) || 
 612                 dev->flags & IFF_NOARP          ||
 613                 arp->ar_pln != 4)
 614         {
 615                 kfree_skb(skb, FREE_READ);
 616                 return 0;
 617                 /* Should this be an error/printk?  Seems like something */
 618                 /* you'd want to know about. Unless it's just !IFF_NOARP. -- MS */
 619         }
 620 
 621 /*
 622  *      Another test.
 623  *      The logic here is that the protocol being looked up by arp should 
 624  *      match the protocol the device speaks.  If it doesn't, there is a
 625  *      problem, so toss the packet.
 626  */
 627 /* Again, should this be an error/printk? -- MS */
 628 
 629         switch(dev->type)
 630         {
 631 #ifdef CONFIG_AX25
 632                 case ARPHRD_AX25:
 633                         if(arp->ar_pro != htons(AX25_P_IP))
 634                         {
 635                                 kfree_skb(skb, FREE_READ);
 636                                 return 0;
 637                         }
 638                         break;
 639 #endif
 640 #ifdef CONFIG_NETROM
 641                 case ARPHRD_NETROM:
 642                         if(arp->ar_pro != htons(AX25_P_IP))
 643                         {
 644                                 kfree_skb(skb, FREE_READ);
 645                                 return 0;
 646                         }
 647                         break;
 648 #endif
 649                 case ARPHRD_ETHER:
 650                 case ARPHRD_ARCNET:
 651                         if(arp->ar_pro != htons(ETH_P_IP))
 652                         {
 653                                 kfree_skb(skb, FREE_READ);
 654                                 return 0;
 655                         }
 656                         break;
 657 
 658                 case ARPHRD_IEEE802:
 659                         if(arp->ar_pro != htons(ETH_P_IP))
 660                         {
 661                                 kfree_skb(skb, FREE_READ);
 662                                 return 0;
 663                         }
 664                         break;
 665 
 666                 default:
 667                         printk("ARP: dev->type mangled!\n");
 668                         kfree_skb(skb, FREE_READ);
 669                         return 0;
 670         }
 671 
 672 /*
 673  *      Extract fields
 674  */
 675 
 676         hlen  = dev->addr_len;
 677         htype = dev->type;
 678 
 679         sha=arp_ptr;
 680         arp_ptr+=hlen;
 681         memcpy(&sip,arp_ptr,4);
 682         arp_ptr+=4;
 683         tha=arp_ptr;
 684         arp_ptr+=hlen;
 685         memcpy(&tip,arp_ptr,4);
 686   
 687 /* 
 688  *      Check for bad requests for 127.0.0.1.  If this is one such, delete it.
 689  */
 690         if(tip == INADDR_LOOPBACK)
 691         {
 692                 kfree_skb(skb, FREE_READ);
 693                 return 0;
 694         }
 695 
 696 /*
 697  *  Process entry.  The idea here is we want to send a reply if it is a
 698  *  request for us or if it is a request for someone else that we hold
 699  *  a proxy for.  We want to add an entry to our cache if it is a reply
 700  *  to us or if it is a request for our address.  
 701  *  (The assumption for this last is that if someone is requesting our 
 702  *  address, they are probably intending to talk to us, so it saves time 
 703  *  if we cache their address.  Their address is also probably not in 
 704  *  our cache, since ours is not in their cache.)
 705  * 
 706  *  Putting this another way, we only care about replies if they are to
 707  *  us, in which case we add them to the cache.  For requests, we care
 708  *  about those for us and those for our proxies.  We reply to both,
 709  *  and in the case of requests for us we add the requester to the arp 
 710  *  cache.
 711  */
 712 
 713         addr_hint = ip_chk_addr(tip);
 714 
 715         if(arp->ar_op == htons(ARPOP_REPLY))
 716         {
 717                 if(addr_hint!=IS_MYADDR)
 718                 {
 719 /* 
 720  *      Replies to other machines get tossed. 
 721  */
 722 
 723  /* Should we reset the expiry timers for an entry that isn't for us, if we */
 724  /* have it in the cache? RFC1122 suggests it. -- MS */
 725 
 726                         kfree_skb(skb, FREE_READ);
 727                         return 0;
 728                 }
 729 /*
 730  *      Fall through to code below that adds sender to cache. 
 731  */
 732         }
 733         else
 734         { 
 735 /* 
 736  *      It is now an arp request 
 737  */
 738 /*
 739  * Only reply for the real device address or when it's in our proxy tables
 740  */
 741                 if(tip!=dev->pa_addr)
 742                 {
 743 /*
 744  *      To get in here, it is a request for someone else.  We need to
 745  *      check if that someone else is one of our proxies.  If it isn't,
 746  *      we can toss it.
 747  */
 748                         cli();
 749                         for(proxy_entry=arp_tables[PROXY_HASH];
 750                             proxy_entry;
 751                             proxy_entry = proxy_entry->next)
 752                         {
 753                           /* we will respond to a proxy arp request
 754                              if the masked arp table ip matches the masked
 755                              tip. This allows a single proxy arp table
 756                              entry to be used on a gateway machine to handle
 757                              all requests for a whole network, rather than
 758                              having to use a huge number of proxy arp entries
 759                              and having to keep them uptodate.
 760                              */
 761                           if (proxy_entry->dev != dev && proxy_entry->htype == htype &&
 762                               !((proxy_entry->ip^tip)&proxy_entry->mask))
 763                             break;
 764 
 765                         }
 766                         if (proxy_entry)
 767                         {
 768                                 memcpy(ha, proxy_entry->ha, hlen);
 769                                 sti();
 770                                 arp_send(ARPOP_REPLY,ETH_P_ARP,sip,dev,tip,sha,ha);
 771                                 kfree_skb(skb, FREE_READ);
 772                                 return 0;
 773                         }
 774                         else
 775                         {
 776                                 sti();
 777                                 kfree_skb(skb, FREE_READ);
 778                                 return 0;
 779                         }
 780                 }
 781                 else
 782                 {
 783 /*
 784  *      To get here, it must be an arp request for us.  We need to reply.
 785  */
 786                         arp_send(ARPOP_REPLY,ETH_P_ARP,sip,dev,tip,sha,dev->dev_addr);
 787                 }
 788         }
 789 
 790 
 791 /*
 792  * Now all replies are handled.  Next, anything that falls through to here
 793  * needs to be added to the arp cache, or have its entry updated if it is 
 794  * there.
 795  */
 796 
 797         hash = HASH(sip);
 798         cli();
 799         for(entry=arp_tables[hash];entry;entry=entry->next)
 800                 if(entry->ip==sip && entry->htype==htype)
 801                         break;
 802 
 803         if(entry)
 804         {
 805 /*
 806  *      Entry found; update it.
 807  */
 808                 memcpy(entry->ha, sha, hlen);
 809                 entry->hlen = hlen;
 810                 entry->last_used = jiffies;
 811                 if (!(entry->flags & ATF_COM))
 812                 {
 813 /*
 814  *      This entry was incomplete.  Delete the retransmit timer
 815  *      and switch to complete status.
 816  */
 817                         del_timer(&entry->timer);
 818                         entry->flags |= ATF_COM;
 819                         sti();
 820 /* 
 821  *      Send out waiting packets. We might have problems, if someone is 
 822  *      manually removing entries right now -- entry might become invalid 
 823  *      underneath us.
 824  */
 825                         arp_send_q(entry, sha);
 826                 }
 827                 else
 828                 {
 829                         sti();
 830                 }
 831         }
 832         else
 833         {
 834 /*
 835  *      No entry found.  Need to add a new entry to the arp table.
 836  */
 837                 entry = (struct arp_table *)kmalloc(sizeof(struct arp_table),GFP_ATOMIC);
 838                 if(entry == NULL)
 839                 {
 840                         sti();
 841                         printk("ARP: no memory for new arp entry\n");
 842 
 843                         kfree_skb(skb, FREE_READ);
 844                         return 0;
 845                 }
 846 
 847                 entry->mask = DEF_ARP_NETMASK;
 848                 entry->ip = sip;
 849                 entry->hlen = hlen;
 850                 entry->htype = htype;
 851                 entry->flags = ATF_COM;
 852                 init_timer(&entry->timer);
 853                 memcpy(entry->ha, sha, hlen);
 854                 entry->last_used = jiffies;
 855                 entry->dev = skb->dev;
 856                 skb_queue_head_init(&entry->skb);
 857                 entry->next = arp_tables[hash];
 858                 arp_tables[hash] = entry;
 859                 sti();
 860         }
 861 
 862 /*
 863  *      Replies have been sent, and entries have been added.  All done.
 864  */
 865         kfree_skb(skb, FREE_READ);
 866         return 0;
 867 }
 868 
 869 
 870 /*
 871  *      Find an arp mapping in the cache. If not found, return false.
 872  */
 873 
 874 int arp_query(unsigned char *haddr, u32 paddr, unsigned short type)
     /* [previous][next][first][last][top][bottom][index][help] */
 875 {
 876         struct arp_table *entry;
 877         unsigned long hash = HASH(paddr);
 878 
 879         /*
 880          *      Find an entry
 881          */
 882         cli();
 883 
 884         for (entry = arp_tables[hash]; entry != NULL; entry = entry->next)
 885                 if (entry->ip == paddr && entry->htype == type)
 886                         break;
 887 
 888         if (entry != NULL) {
 889                 /*
 890                  *      Update the record
 891                  */
 892                 
 893                 entry->last_used = jiffies;
 894                 memcpy(haddr, entry->ha, entry->hlen);
 895                 sti();
 896                 return 1;
 897         }
 898 
 899         sti();
 900         return 0;
 901 }
 902 
 903 /*
 904  *      Find an arp mapping in the cache. If not found, post a request.
 905  */
 906 
 907 int arp_find(unsigned char *haddr, u32 paddr, struct device *dev,
     /* [previous][next][first][last][top][bottom][index][help] */
 908            u32 saddr, struct sk_buff *skb)
 909 {
 910         struct arp_table *entry;
 911         unsigned long hash;
 912 #ifdef CONFIG_IP_MULTICAST
 913         u32 taddr;
 914 #endif  
 915 
 916         switch (ip_chk_addr(paddr))
 917         {
 918                 case IS_MYADDR:
 919                         printk("ARP: arp called for own IP address\n");
 920                         memcpy(haddr, dev->dev_addr, dev->addr_len);
 921                         skb->arp = 1;
 922                         return 0;
 923 #ifdef CONFIG_IP_MULTICAST
 924                 case IS_MULTICAST:
 925                         if(dev->type==ARPHRD_ETHER || dev->type==ARPHRD_IEEE802)
 926                         {
 927                                 /* What exactly does this do? -- MS */
 928                                 haddr[0]=0x01;
 929                                 haddr[1]=0x00;
 930                                 haddr[2]=0x5e;
 931                                 taddr=ntohl(paddr);
 932                                 haddr[5]=taddr&0xff;
 933                                 taddr=taddr>>8;
 934                                 haddr[4]=taddr&0xff;
 935                                 taddr=taddr>>8;
 936                                 haddr[3]=taddr&0x7f;
 937                                 return 0;
 938                         }
 939                 /*
 940                  *      If a device does not support multicast broadcast the stuff (eg AX.25 for now)
 941                  */
 942 #endif
 943                 
 944                 case IS_BROADCAST:
 945                         memcpy(haddr, dev->broadcast, dev->addr_len);
 946                         skb->arp = 1;
 947                         return 0;
 948         }
 949 
 950         hash = HASH(paddr);
 951         cli();
 952 
 953         /*
 954          *      Find an entry
 955          */
 956         entry = arp_lookup(paddr, PROXY_NONE);
 957 
 958         if (entry != NULL)      /* It exists */
 959         {
 960                 if (!(entry->flags & ATF_COM))
 961                 {
 962                         /*
 963                          *      A request was already send, but no reply yet. Thus
 964                          *      queue the packet with the previous attempt
 965                          */
 966                         
 967                         if (skb != NULL)
 968                         {
 969                                 skb_queue_tail(&entry->skb, skb);
 970                                 skb_device_unlock(skb);
 971                         }
 972                         sti();
 973                         return 1;
 974                 }
 975 
 976                 /*
 977                  *      Update the record
 978                  */
 979                 
 980                 entry->last_used = jiffies;
 981                 memcpy(haddr, entry->ha, dev->addr_len);
 982                 if (skb)
 983                         skb->arp = 1;
 984                 sti();
 985                 return 0;
 986         }
 987 
 988         /*
 989          *      Create a new unresolved entry.
 990          */
 991         
 992         entry = (struct arp_table *) kmalloc(sizeof(struct arp_table),
 993                                         GFP_ATOMIC);
 994         if (entry != NULL)
 995         {
 996                 entry->next = arp_tables[hash];
 997                 entry->last_used = jiffies;
 998                 entry->flags = 0;
 999                 entry->ip = paddr;
1000                 entry->mask = DEF_ARP_NETMASK;
1001                 memset(entry->ha, 0, dev->addr_len);
1002                 entry->hlen = dev->addr_len;
1003                 entry->htype = dev->type;
1004                 entry->dev = dev;
1005                 init_timer(&entry->timer);
1006                 entry->timer.function = arp_expire_request;
1007                 entry->timer.data = (unsigned long)entry;
1008                 entry->timer.expires = jiffies + ARP_RES_TIME;
1009                 arp_tables[hash] = entry;
1010                 add_timer(&entry->timer);
1011                 entry->retries = ARP_MAX_TRIES;
1012                 skb_queue_head_init(&entry->skb);
1013                 if (skb != NULL)
1014                 {
1015                         skb_queue_tail(&entry->skb, skb);
1016                         skb_device_unlock(skb);
1017                 }
1018         }
1019         else
1020         {
1021                 if (skb != NULL && skb->free)
1022                         kfree_skb(skb, FREE_WRITE);
1023         }
1024         sti();
1025 
1026         /*
1027          *      If we didn't find an entry, we will try to send an ARP packet.
1028          */
1029         
1030         arp_send(ARPOP_REQUEST, ETH_P_ARP, paddr, dev, saddr, NULL, 
1031                  dev->dev_addr);
1032 
1033         return 1;
1034 }
1035 
1036 
1037 /*
1038  *      Write the contents of the ARP cache to a PROCfs file.
1039  */
1040 
1041 #define HBUFFERLEN 30
1042 
1043 int arp_get_info(char *buffer, char **start, off_t offset, int length, int dummy)
     /* [previous][next][first][last][top][bottom][index][help] */
1044 {
1045         int len=0;
1046         off_t begin=0;
1047         off_t pos=0;
1048         int size;
1049         struct arp_table *entry;
1050         char hbuffer[HBUFFERLEN];
1051         int i,j,k;
1052         const char hexbuf[] =  "0123456789ABCDEF";
1053 
1054         size = sprintf(buffer,"IP address       HW type     Flags       HW address            Mask\n");
1055 
1056         pos+=size;
1057         len+=size;
1058           
1059         cli();
1060         for(i=0; i<FULL_ARP_TABLE_SIZE; i++)
1061         {
1062                 for(entry=arp_tables[i]; entry!=NULL; entry=entry->next)
1063                 {
1064 /*
1065  *      Convert hardware address to XX:XX:XX:XX ... form.
1066  */
1067 #ifdef CONFIG_AX25
1068 #ifdef CONFIG_NETROM
1069                         if (entry->htype == ARPHRD_AX25 || entry->htype == ARPHRD_NETROM)
1070                              strcpy(hbuffer,ax2asc((ax25_address *)entry->ha));
1071                         else {
1072 #else
1073                         if(entry->htype==ARPHRD_AX25)
1074                              strcpy(hbuffer,ax2asc((ax25_address *)entry->ha));
1075                         else {
1076 #endif
1077 #endif
1078 
1079                         for(k=0,j=0;k<HBUFFERLEN-3 && j<entry->hlen;j++)
1080                         {
1081                                 hbuffer[k++]=hexbuf[ (entry->ha[j]>>4)&15 ];
1082                                 hbuffer[k++]=hexbuf[  entry->ha[j]&15     ];
1083                                 hbuffer[k++]=':';
1084                         }
1085                         hbuffer[--k]=0;
1086         
1087 #ifdef CONFIG_AX25
1088                         }
1089 #endif
1090                         size = sprintf(buffer+len,
1091                                 "%-17s0x%-10x0x%-10x%s",
1092                                 in_ntoa(entry->ip),
1093                                 (unsigned int)entry->htype,
1094                                 entry->flags,
1095                                 hbuffer);
1096                         size += sprintf(buffer+len+size,
1097                                  "     %-17s\n",
1098                                   entry->mask==DEF_ARP_NETMASK?
1099                                    "*":in_ntoa(entry->mask));
1100         
1101                         len+=size;
1102                         pos=begin+len;
1103                   
1104                         if(pos<offset)
1105                         {
1106                                 len=0;
1107                                 begin=pos;
1108                         }
1109                         if(pos>offset+length)
1110                                 break;
1111                 }
1112         }
1113         sti();
1114   
1115         *start=buffer+(offset-begin);   /* Start of wanted data */
1116         len-=(offset-begin);            /* Start slop */
1117         if(len>length)
1118                 len=length;                     /* Ending slop */
1119         return len;
1120 }
1121 
1122 
1123 /*
1124  *      This will find an entry in the ARP table by looking at the IP address.
1125  *      If proxy is PROXY_EXACT then only exact IP matches will be allowed
1126  *      for proxy entries, otherwise the netmask will be used
1127  */
1128 
1129 static struct arp_table *arp_lookup(u32 paddr, enum proxy proxy)
     /* [previous][next][first][last][top][bottom][index][help] */
1130 {
1131         struct arp_table *entry;
1132         unsigned long hash = HASH(paddr);
1133         
1134         for (entry = arp_tables[hash]; entry != NULL; entry = entry->next)
1135                 if (entry->ip == paddr) 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);
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 = 7;
1239                         break;
1240 #endif
1241 #ifdef CONFIG_NETROM
1242                 case ARPHRD_NETROM:
1243                         htype = ARPHRD_NETROM;
1244                         hlen = 7;
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);
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);
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,         arp_get_info,   3, "arp" });
1462 }
1463 

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