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

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