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

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