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

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