root/net/appletalk/aarp.c

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

DEFINITIONS

This source file includes following definitions.
  1. aarp_expire
  2. aarp_send_query
  3. aarp_send_reply
  4. aarp_send_probe
  5. aarp_expire_timer
  6. aarp_kick
  7. aarp_expire_device
  8. aarp_expire_timeout
  9. aarp_device_event
  10. aarp_alloc
  11. aarp_find_entry
  12. aarp_send_ddp
  13. aarp_resolved
  14. aarp_rcv
  15. aarp_proto_init

   1 /*
   2  *      AARP:           An implementation of the Appletalk aarp protocol for
   3  *                      ethernet 'ELAP'.
   4  *
   5  *              Alan Cox  <Alan.Cox@linux.org>
   6  *                        <alan@cymru.net>
   7  *
   8  *      This doesn't fit cleanly with the IP arp. This isn't a problem as
   9  *      the IP arp wants extracting from the device layer in 1.3.x anyway.
  10  *      [see the pre-1.3 test code for details 8)]
  11  *
  12  *      FIXME:
  13  *              We ought to handle the retransmits with a single list and a 
  14  *      seperate fast timer for when it is needed.
  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  *      References:
  23  *              Inside Appletalk (2nd Ed).
  24  */
  25  
  26 #include <asm/segment.h>
  27 #include <asm/system.h>
  28 #include <asm/bitops.h>
  29 #include <linux/config.h>
  30 #include <linux/types.h>
  31 #include <linux/kernel.h>
  32 #include <linux/sched.h>
  33 #include <linux/string.h>
  34 #include <linux/mm.h>
  35 #include <linux/socket.h>
  36 #include <linux/sockios.h>
  37 #include <linux/in.h>
  38 #include <linux/errno.h>
  39 #include <linux/interrupt.h>
  40 #include <linux/if_ether.h>
  41 #include <linux/if_arp.h>
  42 #include <linux/inet.h>
  43 #include <linux/notifier.h>
  44 #include <linux/netdevice.h>
  45 #include <linux/etherdevice.h>
  46 #include <linux/skbuff.h>
  47 #include <net/sock.h>
  48 #include <net/datalink.h>
  49 #include <net/psnap.h>
  50 #include <linux/atalk.h>
  51 
  52 #ifdef CONFIG_ATALK
  53 /*
  54  *      Lists of aarp entries
  55  */
  56  
  57 struct aarp_entry
  58 {
  59         /* These first two are only used for unresolved entries */
  60         unsigned long last_sent;                /* Last time we xmitted the aarp request */
  61         struct sk_buff_head packet_queue;       /* Queue of frames wait for resolution */
  62         unsigned long expires_at;               /* Entry expiry time */
  63         struct at_addr target_addr;             /* DDP Address */
  64         struct device *dev;                     /* Device to use */
  65         char hwaddr[6];                         /* Physical i/f address of target/router */
  66         unsigned short xmit_count;              /* When this hits 10 we give up */
  67         struct aarp_entry *next;                /* Next entry in chain */
  68 };
  69 
  70 
  71 /*
  72  *      Hashed list of resolved and unresolved entries
  73  */
  74 
  75 static struct aarp_entry *resolved[AARP_HASH_SIZE], *unresolved[AARP_HASH_SIZE];
  76 static int unresolved_count=0;
  77 
  78 /*
  79  *      Used to walk the list and purge/kick entries.
  80  */
  81  
  82 static struct timer_list aarp_timer;
  83 
  84 /*
  85  *      Delete an aarp queue
  86  */
  87 
  88 static void aarp_expire(struct aarp_entry *a)
     /* [previous][next][first][last][top][bottom][index][help] */
  89 {
  90         struct sk_buff *skb;
  91         
  92         while((skb=skb_dequeue(&a->packet_queue))!=NULL)
  93                 kfree_skb(skb, FREE_WRITE);
  94         kfree_s(a,sizeof(*a));
  95 }
  96 
  97 /*
  98  *      Send an aarp queue entry request
  99  */
 100  
 101 static void aarp_send_query(struct aarp_entry *a)
     /* [previous][next][first][last][top][bottom][index][help] */
 102 {
 103         static char aarp_eth_multicast[ETH_ALEN]={ 0x09, 0x00, 0x07, 0xFF, 0xFF, 0xFF };
 104         struct device *dev=a->dev;
 105         int len=dev->hard_header_len+sizeof(struct elapaarp)+aarp_dl->header_length;
 106         struct sk_buff *skb=alloc_skb(len, GFP_ATOMIC);
 107         struct elapaarp *eah;
 108         struct at_addr *sat=atalk_find_dev_addr(dev);
 109         
 110         if(skb==NULL || sat==NULL)
 111                 return;
 112         
 113         /*
 114          *      Set up the buffer.
 115          */             
 116 
 117         skb_reserve(skb,dev->hard_header_len+aarp_dl->header_length);
 118         eah             =       (struct elapaarp *)skb_put(skb,sizeof(struct elapaarp));
 119         skb->arp        =       1;
 120         skb->free       =       1;
 121         skb->dev        =       a->dev;
 122         
 123         /*
 124          *      Set up the ARP.
 125          */
 126          
 127         eah->hw_type    =       htons(AARP_HW_TYPE_ETHERNET);
 128         eah->pa_type    =       htons(ETH_P_ATALK);
 129         eah->hw_len     =       ETH_ALEN;       
 130         eah->pa_len     =       AARP_PA_ALEN;
 131         eah->function   =       htons(AARP_REQUEST);
 132         
 133         memcpy(eah->hw_src, dev->dev_addr, ETH_ALEN);
 134         
 135         eah->pa_src_zero=       0;
 136         eah->pa_src_net =       sat->s_net;
 137         eah->pa_src_node=       sat->s_node;
 138         
 139         memset(eah->hw_dst, '\0', ETH_ALEN);
 140         
 141         eah->pa_dst_zero=       0;
 142         eah->pa_dst_net =       a->target_addr.s_net;
 143         eah->pa_dst_node=       a->target_addr.s_node;
 144         
 145         /*
 146          *      Add ELAP headers and set target to the AARP multicast.
 147          */
 148          
 149         aarp_dl->datalink_header(aarp_dl, skb, aarp_eth_multicast);     
 150 
 151         /*
 152          *      Send it.
 153          */     
 154          
 155         dev_queue_xmit(skb, dev, SOPRI_NORMAL);
 156         
 157         /*
 158          *      Update the sending count
 159          */
 160          
 161         a->xmit_count++;
 162 }
 163 
 164 static void aarp_send_reply(struct device *dev, struct at_addr *us, struct at_addr *them, unsigned char *sha)
     /* [previous][next][first][last][top][bottom][index][help] */
 165 {
 166         int len=dev->hard_header_len+sizeof(struct elapaarp)+aarp_dl->header_length;
 167         struct sk_buff *skb=alloc_skb(len, GFP_ATOMIC);
 168         struct elapaarp *eah;
 169         
 170         if(skb==NULL)
 171                 return;
 172         
 173         /*
 174          *      Set up the buffer.
 175          */             
 176 
 177         skb_reserve(skb,dev->hard_header_len+aarp_dl->header_length);
 178         eah             =       (struct elapaarp *)skb_put(skb,sizeof(struct elapaarp));         
 179         skb->arp        =       1;
 180         skb->free       =       1;
 181         skb->dev        =       dev;
 182         
 183         /*
 184          *      Set up the ARP.
 185          */
 186          
 187         eah->hw_type    =       htons(AARP_HW_TYPE_ETHERNET);
 188         eah->pa_type    =       htons(ETH_P_ATALK);
 189         eah->hw_len     =       ETH_ALEN;       
 190         eah->pa_len     =       AARP_PA_ALEN;
 191         eah->function   =       htons(AARP_REPLY);
 192         
 193         memcpy(eah->hw_src, dev->dev_addr, ETH_ALEN);
 194         
 195         eah->pa_src_zero=       0;
 196         eah->pa_src_net =       us->s_net;
 197         eah->pa_src_node=       us->s_node;
 198         
 199         if(sha==NULL)
 200                 memset(eah->hw_dst, '\0', ETH_ALEN);
 201         else
 202                 memcpy(eah->hw_dst, sha, ETH_ALEN);
 203         
 204         eah->pa_dst_zero=       0;
 205         eah->pa_dst_net =       them->s_net;
 206         eah->pa_dst_node=       them->s_node;
 207         
 208         /*
 209          *      Add ELAP headers and set target to the AARP multicast.
 210          */
 211          
 212         aarp_dl->datalink_header(aarp_dl, skb, sha);    
 213 
 214         /*
 215          *      Send it.
 216          */     
 217          
 218         dev_queue_xmit(skb, dev, SOPRI_NORMAL);
 219         
 220 }
 221 
 222 /*
 223  *      Send probe frames. Called from atif_probe_device.
 224  */
 225  
 226 void aarp_send_probe(struct device *dev, struct at_addr *us)
     /* [previous][next][first][last][top][bottom][index][help] */
 227 {
 228         int len=dev->hard_header_len+sizeof(struct elapaarp)+aarp_dl->header_length;
 229         struct sk_buff *skb=alloc_skb(len, GFP_ATOMIC);
 230         struct elapaarp *eah;
 231         static char aarp_eth_multicast[ETH_ALEN]={ 0x09, 0x00, 0x07, 0xFF, 0xFF, 0xFF };
 232         
 233         if(skb==NULL)
 234                 return;
 235         
 236         /*
 237          *      Set up the buffer.
 238          */             
 239 
 240         skb_reserve(skb,dev->hard_header_len+aarp_dl->header_length);
 241         eah             =       (struct elapaarp *)skb_put(skb,sizeof(struct elapaarp));
 242         
 243         skb->arp        =       1;
 244         skb->free       =       1;
 245         skb->dev        =       dev;
 246         
 247         /*
 248          *      Set up the ARP.
 249          */
 250          
 251         eah->hw_type    =       htons(AARP_HW_TYPE_ETHERNET);
 252         eah->pa_type    =       htons(ETH_P_ATALK);
 253         eah->hw_len     =       ETH_ALEN;       
 254         eah->pa_len     =       AARP_PA_ALEN;
 255         eah->function   =       htons(AARP_PROBE);
 256         
 257         memcpy(eah->hw_src, dev->dev_addr, ETH_ALEN);
 258         
 259         eah->pa_src_zero=       0;
 260         eah->pa_src_net =       us->s_net;
 261         eah->pa_src_node=       us->s_node;
 262         
 263         memset(eah->hw_dst, '\0', ETH_ALEN);
 264         
 265         eah->pa_dst_zero=       0;
 266         eah->pa_dst_net =       us->s_net;
 267         eah->pa_dst_node=       us->s_node;
 268         
 269         /*
 270          *      Add ELAP headers and set target to the AARP multicast.
 271          */
 272          
 273         aarp_dl->datalink_header(aarp_dl, skb, aarp_eth_multicast);     
 274 
 275         /*
 276          *      Send it.
 277          */     
 278          
 279         dev_queue_xmit(skb, dev, SOPRI_NORMAL);
 280         
 281 }
 282         
 283 /*
 284  *      Handle an aarp timer expire
 285  */
 286 
 287 static void aarp_expire_timer(struct aarp_entry **n)
     /* [previous][next][first][last][top][bottom][index][help] */
 288 {
 289         struct aarp_entry *t;
 290         while((*n)!=NULL)
 291         {
 292                 /* Expired ? */
 293                 if((*n)->expires_at < jiffies)
 294                 {
 295                         t= *n;
 296                         *n=(*n)->next;
 297                         aarp_expire(t);
 298                 }
 299                 else
 300                         n=&((*n)->next);
 301         }
 302 }
 303 
 304 /*
 305  *      Kick all pending requests 5 times a second.
 306  */
 307  
 308 static void aarp_kick(struct aarp_entry **n)
     /* [previous][next][first][last][top][bottom][index][help] */
 309 {
 310         struct aarp_entry *t;
 311         while((*n)!=NULL)
 312         {
 313                 /* Expired - if this will be the 11th transmit, we delete
 314                    instead */
 315                 if((*n)->xmit_count>=AARP_RETRANSMIT_LIMIT)
 316                 {
 317                         t= *n;
 318                         *n=(*n)->next;
 319                         aarp_expire(t);
 320                 }
 321                 else
 322                 {
 323                         aarp_send_query(*n);
 324                         n=&((*n)->next);
 325                 }
 326         }
 327 }
 328 
 329 /*
 330  *      A device has gone down. Take all entries referring to the device
 331  *      and remove them.
 332  */
 333  
 334 static void aarp_expire_device(struct aarp_entry **n, struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 335 {
 336         struct aarp_entry *t;
 337         while((*n)!=NULL)
 338         {
 339                 if((*n)->dev==dev)
 340                 {
 341                         t= *n;
 342                         *n=(*n)->next;
 343                         aarp_expire(t);
 344                 }
 345                 else
 346                         n=&((*n)->next);
 347         }
 348 }
 349                 
 350 /*
 351  *      Handle the timer event 
 352  */
 353  
 354 static void aarp_expire_timeout(unsigned long unused)
     /* [previous][next][first][last][top][bottom][index][help] */
 355 {
 356         int ct=0;
 357         for(ct=0;ct<AARP_HASH_SIZE;ct++)
 358         {
 359                 aarp_expire_timer(&resolved[ct]);
 360                 aarp_kick(&unresolved[ct]);
 361                 aarp_expire_timer(&unresolved[ct]);
 362         }
 363         del_timer(&aarp_timer);
 364         if(unresolved_count==0)
 365                 aarp_timer.expires=jiffies+AARP_EXPIRY_TIME;
 366         else
 367                 aarp_timer.expires=jiffies+AARP_TICK_TIME;
 368         add_timer(&aarp_timer);
 369 }
 370 
 371 /*
 372  *      Network device notifier chain handler.
 373  */
 374  
 375 static int aarp_device_event(struct notifier_block *this, unsigned long event, void *ptr)
     /* [previous][next][first][last][top][bottom][index][help] */
 376 {
 377         int ct=0;
 378         if(event==NETDEV_DOWN)
 379         {
 380                 for(ct=0;ct<AARP_HASH_SIZE;ct++)
 381                 {
 382                         aarp_expire_device(&resolved[ct],ptr);
 383                         aarp_expire_device(&unresolved[ct],ptr);
 384                 }
 385         }
 386         return NOTIFY_DONE;
 387 }
 388 
 389 /*
 390  *      Create a new aarp entry.
 391  */
 392  
 393 static struct aarp_entry *aarp_alloc(void)
     /* [previous][next][first][last][top][bottom][index][help] */
 394 {
 395         struct aarp_entry *a=kmalloc(sizeof(struct aarp_entry), GFP_ATOMIC);
 396         if(a==NULL)
 397                 return NULL;
 398         skb_queue_head_init(&a->packet_queue);
 399         return a;
 400 }
 401 
 402 /*
 403  *      Find an entry. We might return an expired but not yet purged entry. We
 404  *      don't care as it will do no harm.
 405  */
 406  
 407 static struct aarp_entry *aarp_find_entry(struct aarp_entry *list, struct device *dev, struct at_addr *sat)
     /* [previous][next][first][last][top][bottom][index][help] */
 408 {
 409         unsigned long flags;
 410         save_flags(flags);
 411         cli();
 412         while(list)
 413         {
 414                 if(list->target_addr.s_net==sat->s_net &&
 415                    list->target_addr.s_node==sat->s_node && list->dev==dev)
 416                         break;
 417                 list=list->next;
 418         }
 419         restore_flags(flags);
 420         return list;
 421 }
 422 
 423 /*
 424  *      Send a DDP frame
 425  */
 426  
 427 int aarp_send_ddp(struct device *dev,struct sk_buff *skb, struct at_addr *sa, void *hwaddr)
     /* [previous][next][first][last][top][bottom][index][help] */
 428 {
 429         static char ddp_eth_multicast[ETH_ALEN]={ 0x09, 0x00, 0x07, 0xFF, 0xFF, 0xFF };
 430         int hash;
 431         struct aarp_entry *a;
 432         unsigned long flags;
 433         
 434         /*
 435          *      Check for localtalk first
 436          */
 437          
 438         if(dev->type==ARPHRD_LOCALTLK)
 439         {
 440                 struct at_addr *at=atalk_find_dev_addr(dev);
 441                 int ft=2;
 442                 
 443                 /*
 444                  *      Compressable ?
 445                  */
 446                  
 447                 if(at->s_net==sa->s_net)
 448                 {
 449                         skb_pull(skb,sizeof(struct ddpehdr)-4);
 450                         /*
 451                          *      The uper two remaining bytes are the port 
 452                          *      numbers we just happen to need. Now put the 
 453                          *      length in the lower two.
 454                          */
 455                         *((__u16 *)skb->data)=htons(skb->len);
 456                         ft=1;
 457                 }
 458                 /*
 459                  *      Nice and easy. No AARP type protocols occur here
 460                  *      so we can just shovel it out with a 3 byte LLAP header
 461                  */
 462                  
 463                 skb_push(skb,3);
 464                 skb->data[0]=sa->s_node;
 465                 skb->data[1]=at->s_node;
 466                 skb->data[2]=ft;
 467                  
 468                 if(skb->sk==NULL)
 469                         dev_queue_xmit(skb, skb->dev, SOPRI_NORMAL);
 470                 else
 471                         dev_queue_xmit(skb, skb->dev, skb->sk->priority);
 472                 return 1;
 473         }       
 474          
 475         /*
 476          *      Non ELAP we cannot do.
 477          */
 478 
 479         if(dev->type!=ARPHRD_ETHER)
 480         {
 481                 return -1;
 482         }
 483 
 484         skb->dev = dev;
 485         skb->protocol = htons(ETH_P_ATALK);
 486                         
 487         hash=sa->s_node%(AARP_HASH_SIZE-1);
 488         save_flags(flags);
 489         cli();
 490         
 491         /*
 492          *      Do we have a resolved entry ?
 493          */
 494          
 495         if(sa->s_node==ATADDR_BCAST)
 496         {
 497                 ddp_dl->datalink_header(ddp_dl, skb, ddp_eth_multicast);
 498                 if(skb->sk==NULL)
 499                         dev_queue_xmit(skb, skb->dev, SOPRI_NORMAL);
 500                 else
 501                         dev_queue_xmit(skb, skb->dev, skb->sk->priority);
 502                 restore_flags(flags);
 503                 return 1;
 504         }
 505         a=aarp_find_entry(resolved[hash],dev,sa);
 506         if(a!=NULL)
 507         {
 508                 /*
 509                  *      Return 1 and fill in the address
 510                  */
 511 
 512                 a->expires_at=jiffies+AARP_EXPIRY_TIME*10;
 513                 ddp_dl->datalink_header(ddp_dl, skb, a->hwaddr);
 514                 if(skb->sk==NULL)
 515                         dev_queue_xmit(skb, skb->dev, SOPRI_NORMAL);
 516                 else
 517                         dev_queue_xmit(skb, skb->dev, skb->sk->priority);
 518                 restore_flags(flags);
 519                 return 1;
 520         }
 521 
 522         /*
 523          *      Do we have an unresolved entry: This is the less common path
 524          */
 525 
 526         a=aarp_find_entry(unresolved[hash],dev,sa);
 527         if(a!=NULL)
 528         {
 529                 /*
 530                  *      Queue onto the unresolved queue
 531                  */
 532 
 533                 skb_queue_tail(&a->packet_queue, skb);
 534                 restore_flags(flags);
 535                 return 0;
 536         }
 537 
 538         /*
 539          *      Allocate a new entry
 540          */
 541 
 542         a=aarp_alloc();
 543         if(a==NULL)
 544         {
 545                 /*
 546                  *      Whoops slipped... good job it's an unreliable 
 547                  *      protocol 8)     
 548                  */
 549                 restore_flags(flags);
 550                 return -1;
 551         }
 552 
 553         /*
 554          *      Set up the queue
 555          */
 556 
 557         skb_queue_tail(&a->packet_queue, skb);
 558         a->expires_at=jiffies+AARP_RESOLVE_TIME;
 559         a->dev=dev;
 560         a->next=unresolved[hash];
 561         a->target_addr= *sa;
 562         a->xmit_count=0;
 563         unresolved[hash]=a;
 564         unresolved_count++;
 565         restore_flags(flags);
 566 
 567         /*
 568          *      Send an initial request for the address
 569          */
 570 
 571         aarp_send_query(a);
 572 
 573         /*
 574          *      Switch to fast timer if needed (That is if this is the
 575          *      first unresolved entry to get added)
 576          */
 577 
 578         if(unresolved_count==1)
 579         {
 580                 del_timer(&aarp_timer);
 581                 aarp_timer.expires=jiffies+AARP_TICK_TIME;
 582                 add_timer(&aarp_timer);
 583         }
 584 
 585         /*
 586          *      Tell the ddp layer we have taken over for this frame.
 587          */
 588 
 589         return 0;
 590 }
 591 
 592 /*
 593  *      An entry in the aarp unresolved queue has become resolved. Send
 594  *      all the frames queued under it.
 595  */
 596  
 597 static void aarp_resolved(struct aarp_entry **list, struct aarp_entry *a, int hash)
     /* [previous][next][first][last][top][bottom][index][help] */
 598 {
 599         struct sk_buff *skb;
 600         while(*list!=NULL)
 601         {
 602                 if(*list==a)
 603                 {
 604                         unresolved_count--;
 605                         *list=a->next;
 606                         
 607                         /* 
 608                          *      Move into the resolved list 
 609                          */
 610                          
 611                         a->next=resolved[hash];
 612                         resolved[hash]=a;
 613                         
 614                         /*
 615                          *      Kick frames off 
 616                          */
 617                          
 618                         while((skb=skb_dequeue(&a->packet_queue))!=NULL)
 619                         {
 620                                 a->expires_at=jiffies+AARP_EXPIRY_TIME*10;
 621                                 ddp_dl->datalink_header(ddp_dl,skb,a->hwaddr);
 622                                 if(skb->sk==NULL)
 623                                         dev_queue_xmit(skb, skb->dev, SOPRI_NORMAL);
 624                                 else
 625                                         dev_queue_xmit(skb, skb->dev, skb->sk->priority);
 626                         }
 627                 }
 628                 else
 629                         list=&((*list)->next);
 630         }
 631 }
 632 
 633 /*
 634  *      This is called by the SNAP driver whenever we see an AARP SNAP
 635  *      frame. We currently only support ethernet.
 636  */
 637  
 638 static int aarp_rcv(struct sk_buff *skb, struct device *dev, struct packet_type *pt)
     /* [previous][next][first][last][top][bottom][index][help] */
 639 {
 640         struct elapaarp *ea=(struct elapaarp *)skb->h.raw;
 641         struct aarp_entry *a;
 642         struct at_addr sa, *ma;
 643         unsigned long flags;
 644         int hash;
 645         struct atalk_iface *ifa;
 646         
 647         
 648         /*
 649          *      We only do ethernet SNAP AARP
 650          */
 651          
 652         if(dev->type!=ARPHRD_ETHER)
 653         {
 654                 kfree_skb(skb, FREE_READ);
 655                 return 0;
 656         }
 657         
 658         /*
 659          *      Frame size ok ?
 660          */
 661          
 662         if(!skb_pull(skb,sizeof(*ea)))
 663         {
 664                 kfree_skb(skb, FREE_READ);
 665                 return 0;
 666         }
 667 
 668         ea->function=ntohs(ea->function);
 669         
 670         /*
 671          *      Sanity check fields.
 672          */
 673          
 674         if(ea->function<AARP_REQUEST || ea->function > AARP_PROBE || ea->hw_len != ETH_ALEN || ea->pa_len != AARP_PA_ALEN ||
 675                 ea->pa_src_zero != 0 || ea->pa_dst_zero != 0)
 676         {
 677                 kfree_skb(skb, FREE_READ);
 678                 return 0;
 679         }
 680         
 681         /*
 682          *      Looks good
 683          */
 684         
 685         hash=ea->pa_src_node%(AARP_HASH_SIZE-1);
 686 
 687         /*
 688          *      Build an address
 689          */
 690          
 691         sa.s_node=ea->pa_src_node;
 692         sa.s_net=ea->pa_src_net;
 693         
 694         /*
 695          *      Process the packet
 696          */
 697          
 698         save_flags(flags);
 699 
 700         /*
 701          *      Check for replies of me
 702          */
 703                         
 704         ifa=atalk_find_dev(dev);
 705         if(ifa==NULL)
 706         {
 707                 restore_flags(flags);
 708                 kfree_skb(skb, FREE_READ);
 709                 return 1;               
 710         }
 711         if(ifa->status&ATIF_PROBE)
 712         {                       
 713                 if(ifa->address.s_node==ea->pa_dst_node && ifa->address.s_net==ea->pa_dst_net)
 714                 {
 715                         /*
 716                          *      Fail the probe (in use)
 717                          */
 718                          
 719                         ifa->status|=ATIF_PROBE_FAIL;
 720                         restore_flags(flags);
 721                         kfree_skb(skb, FREE_READ);
 722                         return 1;               
 723                 }
 724         }                                
 725         
 726         switch(ea->function)
 727         {
 728                 case AARP_REPLY:        
 729                         if(unresolved_count==0) /* Speed up */
 730                                 break;
 731                         /*
 732                          *      Find the entry  
 733                          */
 734                          
 735                         cli();
 736                         if((a=aarp_find_entry(unresolved[hash],dev,&sa))==NULL || dev != a->dev)
 737                                 break;
 738                         /*
 739                          *      We can fill one in - this is good
 740                          */
 741                          
 742                         memcpy(a->hwaddr,ea->hw_src,ETH_ALEN);
 743                         aarp_resolved(&unresolved[hash],a,hash);
 744                         if(unresolved_count==0)
 745                         {
 746                                 del_timer(&aarp_timer);
 747                                 aarp_timer.expires=jiffies+AARP_EXPIRY_TIME;
 748                                 add_timer(&aarp_timer);
 749                         }
 750                         break;
 751                         
 752                 case AARP_REQUEST:
 753                 case AARP_PROBE:
 754                         /*
 755                          *      If it is my address set ma to my address and reply. We can treat probe and
 756                          *      request the same. Probe simply means we shouldn't cache the querying host, 
 757                          *      as in a probe they are proposing an address not using one.
 758                          */
 759                          
 760                         ma=&ifa->address;
 761                         sa.s_node=ea->pa_dst_node;
 762                         sa.s_net=ea->pa_dst_net;
 763                         
 764                         if(sa.s_node!=ma->s_node)
 765                                 break;
 766                         if(sa.s_net && ma->s_net && sa.s_net!=ma->s_net)
 767                                 break;
 768 
 769                         sa.s_node=ea->pa_src_node;
 770                         sa.s_net=ea->pa_src_net;
 771                         
 772                         /*
 773                          *      aarp_my_address has found the address to use for us.
 774                          */
 775                          
 776                         aarp_send_reply(dev,ma,&sa,ea->hw_src);
 777                         break;
 778         }
 779         restore_flags(flags);
 780         kfree_skb(skb, FREE_READ);
 781         return 1;               
 782 }
 783 
 784 static struct notifier_block aarp_notifier={
 785         aarp_device_event,
 786         NULL,
 787         0
 788 };
 789 
 790 
 791 void aarp_proto_init(void)
     /* [previous][next][first][last][top][bottom][index][help] */
 792 {
 793         static char aarp_snap_id[]={0x00,0x00,0x00,0x80,0xF3};
 794         if((aarp_dl=register_snap_client(aarp_snap_id, aarp_rcv))==NULL)
 795                 printk("Unable to register AARP with SNAP.\n");
 796         init_timer(&aarp_timer);
 797         aarp_timer.function=aarp_expire_timeout;
 798         aarp_timer.data=0;
 799         aarp_timer.expires=jiffies+AARP_EXPIRY_TIME;
 800         add_timer(&aarp_timer);
 801         register_netdevice_notifier(&aarp_notifier);
 802 }
 803 #endif

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