This source file includes following definitions.
- arp_check_expire
- arp_release_entry
- arp_device_down
- arp_send
- arp_expire_request
- arp_send_q
- arp_destroy
- arp_rcv
- arp_find
- arp_get_info
- arp_lookup
- arp_req_set
- arp_req_get
- arp_ioctl
- arp_init
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40 #include <linux/types.h>
41 #include <linux/string.h>
42 #include <linux/kernel.h>
43 #include <linux/sched.h>
44 #include <linux/config.h>
45 #include <linux/socket.h>
46 #include <linux/sockios.h>
47 #include <linux/errno.h>
48 #include <linux/if_arp.h>
49 #include <linux/in.h>
50 #include <asm/system.h>
51 #include <asm/segment.h>
52 #include <stdarg.h>
53 #include <linux/inet.h>
54 #include <linux/netdevice.h>
55 #include <linux/etherdevice.h>
56 #include "ip.h"
57 #include "route.h"
58 #include "protocol.h"
59 #include "tcp.h"
60 #include <linux/skbuff.h>
61 #include "sock.h"
62 #include "arp.h"
63 #ifdef CONFIG_AX25
64 #include "ax25.h"
65 #endif
66
67
68
69
70
71
72
73
74
75 struct arp_table
76 {
77 struct arp_table *next;
78 unsigned long last_used;
79 unsigned int flags;
80 unsigned long ip;
81 unsigned long mask;
82 unsigned char ha[MAX_ADDR_LEN];
83 unsigned char hlen;
84 unsigned short htype;
85 struct device *dev;
86
87
88
89
90
91 struct timer_list timer;
92 int retries;
93 struct sk_buff_head skb;
94 };
95
96
97
98
99
100
101
102
103
104
105
106 #define ARP_RES_TIME (250*(HZ/10))
107
108
109
110
111
112
113 #define ARP_MAX_TRIES 3
114
115
116
117
118
119 #define ARP_TIMEOUT (600*HZ)
120
121
122
123
124
125
126
127 #define ARP_CHECK_INTERVAL (60 * HZ)
128
129
130 static void arp_check_expire (unsigned long);
131 static struct arp_table *arp_lookup(unsigned long paddr, int exact);
132
133
134 static struct timer_list arp_timer =
135 { NULL, NULL, ARP_CHECK_INTERVAL, 0L, &arp_check_expire };
136
137
138
139
140
141
142
143 #define DEF_ARP_NETMASK (~0)
144
145
146
147
148
149
150
151
152
153 #define ARP_TABLE_SIZE 16
154
155
156
157
158
159
160 #define FULL_ARP_TABLE_SIZE (ARP_TABLE_SIZE+1)
161
162 struct arp_table *arp_tables[FULL_ARP_TABLE_SIZE] =
163 {
164 NULL,
165 };
166
167
168
169
170
171
172
173 #define HASH(paddr) (htonl(paddr) & (ARP_TABLE_SIZE - 1))
174 #define PROXY_HASH ARP_TABLE_SIZE
175
176
177
178
179
180
181
182
183
184 static void arp_check_expire(unsigned long dummy)
185 {
186 int i;
187 unsigned long now = jiffies;
188 unsigned long flags;
189 save_flags(flags);
190 cli();
191
192 for (i = 0; i < FULL_ARP_TABLE_SIZE; i++)
193 {
194 struct arp_table *entry;
195 struct arp_table **pentry = &arp_tables[i];
196
197 while ((entry = *pentry) != NULL)
198 {
199 if ((now - entry->last_used) > ARP_TIMEOUT
200 && !(entry->flags & ATF_PERM))
201 {
202 *pentry = entry->next;
203 del_timer(&entry->timer);
204 kfree_s(entry, sizeof(struct arp_table));
205 }
206 else
207 pentry = &entry->next;
208 }
209 }
210 restore_flags(flags);
211
212
213
214
215
216 del_timer(&arp_timer);
217 arp_timer.expires = ARP_CHECK_INTERVAL;
218 add_timer(&arp_timer);
219 }
220
221
222
223
224
225
226 static void arp_release_entry(struct arp_table *entry)
227 {
228 struct sk_buff *skb;
229 unsigned long flags;
230
231 save_flags(flags);
232 cli();
233
234 while ((skb = skb_dequeue(&entry->skb)) != NULL)
235 {
236 skb_device_lock(skb);
237 restore_flags(flags);
238 dev_kfree_skb(skb, FREE_WRITE);
239 }
240 restore_flags(flags);
241 del_timer(&entry->timer);
242 kfree_s(entry, sizeof(struct arp_table));
243 return;
244 }
245
246
247
248
249
250 void arp_device_down(struct device *dev)
251 {
252 int i;
253 unsigned long flags;
254
255
256
257
258 save_flags(flags);
259 cli();
260 for (i = 0; i < FULL_ARP_TABLE_SIZE; i++)
261 {
262 struct arp_table *entry;
263 struct arp_table **pentry = &arp_tables[i];
264
265 while ((entry = *pentry) != NULL)
266 {
267 if(entry->dev==dev)
268 {
269 *pentry = entry->next;
270 del_timer(&entry->timer);
271 kfree_s(entry, sizeof(struct arp_table));
272 }
273 else
274 pentry = &entry->next;
275 }
276 }
277 restore_flags(flags);
278 }
279
280
281
282
283
284
285
286 void arp_send(int type, int ptype, unsigned long dest_ip,
287 struct device *dev, unsigned long src_ip,
288 unsigned char *dest_hw, unsigned char *src_hw)
289 {
290 struct sk_buff *skb;
291 struct arphdr *arp;
292 unsigned char *arp_ptr;
293
294
295
296
297
298 if(dev->flags&IFF_NOARP)
299 return;
300
301
302
303
304
305 skb = alloc_skb(sizeof(struct arphdr)+ 2*(dev->addr_len+4)
306 + dev->hard_header_len, GFP_ATOMIC);
307 if (skb == NULL)
308 {
309 printk("ARP: no memory to send an arp packet\n");
310 return;
311 }
312 skb->len = sizeof(struct arphdr) + dev->hard_header_len + 2*(dev->addr_len+4);
313 skb->arp = 1;
314 skb->dev = dev;
315 skb->free = 1;
316
317
318
319
320
321 dev->hard_header(skb->data,dev,ptype,dest_hw?dest_hw:dev->broadcast,src_hw?src_hw:NULL,skb->len,skb);
322
323
324 arp = (struct arphdr *) (skb->data + dev->hard_header_len);
325 arp->ar_hrd = htons(dev->type);
326 #ifdef CONFIG_AX25
327 arp->ar_pro = (dev->type != ARPHRD_AX25)? htons(ETH_P_IP) : htons(AX25_P_IP);
328 #else
329 arp->ar_pro = htons(ETH_P_IP);
330 #endif
331 arp->ar_hln = dev->addr_len;
332 arp->ar_pln = 4;
333 arp->ar_op = htons(type);
334
335 arp_ptr=(unsigned char *)(arp+1);
336
337 memcpy(arp_ptr, src_hw, dev->addr_len);
338 arp_ptr+=dev->addr_len;
339 memcpy(arp_ptr, &src_ip,4);
340 arp_ptr+=4;
341 if (dest_hw != NULL)
342 memcpy(arp_ptr, dest_hw, dev->addr_len);
343 else
344 memset(arp_ptr, 0, dev->addr_len);
345 arp_ptr+=dev->addr_len;
346 memcpy(arp_ptr, &dest_ip, 4);
347
348 dev_queue_xmit(skb, dev, 0);
349 }
350
351
352
353
354
355
356
357 static void arp_expire_request (unsigned long arg)
358 {
359 struct arp_table *entry = (struct arp_table *) arg;
360 struct arp_table **pentry;
361 unsigned long hash;
362 unsigned long flags;
363
364 save_flags(flags);
365 cli();
366
367
368
369
370
371
372
373 if (entry->flags & ATF_COM)
374 {
375 restore_flags(flags);
376 return;
377 }
378
379 if (--entry->retries > 0)
380 {
381 unsigned long ip = entry->ip;
382 struct device *dev = entry->dev;
383
384
385 del_timer(&entry->timer);
386 entry->timer.expires = ARP_RES_TIME;
387 add_timer(&entry->timer);
388 restore_flags(flags);
389 arp_send(ARPOP_REQUEST, ETH_P_ARP, ip, dev, dev->pa_addr,
390 NULL, dev->dev_addr);
391 return;
392 }
393
394
395
396
397
398
399
400
401 hash = HASH(entry->ip);
402
403
404
405
406 if (entry->flags & ATF_PUBL)
407 pentry = &arp_tables[PROXY_HASH];
408 else
409 pentry = &arp_tables[hash];
410 while (*pentry != NULL)
411 {
412 if (*pentry == entry)
413 {
414 *pentry = entry->next;
415 del_timer(&entry->timer);
416 restore_flags(flags);
417 arp_release_entry(entry);
418 return;
419 }
420 pentry = &(*pentry)->next;
421 }
422 restore_flags(flags);
423 printk("Possible ARP queue corruption.\n");
424
425
426
427 }
428
429
430
431
432
433
434 static void arp_send_q(struct arp_table *entry, unsigned char *hw_dest)
435 {
436 struct sk_buff *skb;
437
438 unsigned long flags;
439
440
441
442
443
444 if(!(entry->flags&ATF_COM))
445 {
446 printk("arp_send_q: incomplete entry for %s\n",
447 in_ntoa(entry->ip));
448 return;
449 }
450
451 save_flags(flags);
452
453 cli();
454 while((skb = skb_dequeue(&entry->skb)) != NULL)
455 {
456 IS_SKB(skb);
457 skb_device_lock(skb);
458 restore_flags(flags);
459 if(!skb->dev->rebuild_header(skb->data,skb->dev,skb->raddr,skb))
460 {
461 skb->arp = 1;
462 if(skb->sk==NULL)
463 dev_queue_xmit(skb, skb->dev, 0);
464 else
465 dev_queue_xmit(skb,skb->dev,skb->sk->priority);
466 }
467 else
468 {
469
470
471 printk("arp_send_q: The impossible occurred. Please notify Alan.\n");
472 printk("arp_send_q: active entity %s\n",in_ntoa(entry->ip));
473 printk("arp_send_q: failed to find %s\n",in_ntoa(skb->raddr));
474 }
475 }
476 restore_flags(flags);
477 }
478
479
480
481
482
483
484 void arp_destroy(unsigned long ip_addr, int force)
485 {
486 int checked_proxies = 0;
487 struct arp_table *entry;
488 struct arp_table **pentry;
489 unsigned long hash = HASH(ip_addr);
490
491 cli();
492 pentry = &arp_tables[hash];
493 if (! *pentry)
494 pentry = &arp_tables[PROXY_HASH];
495
496 while ((entry = *pentry) != NULL)
497 {
498 if (entry->ip == ip_addr)
499 {
500 if ((entry->flags & ATF_PERM) && !force)
501 return;
502 *pentry = entry->next;
503 del_timer(&entry->timer);
504 sti();
505 arp_release_entry(entry);
506 return;
507 }
508 pentry = &entry->next;
509 if (!checked_proxies && ! *pentry)
510 {
511
512 checked_proxies = 1;
513 pentry = &arp_tables[PROXY_HASH];
514 }
515 }
516 sti();
517 }
518
519
520
521
522
523
524
525
526 int arp_rcv(struct sk_buff *skb, struct device *dev, struct packet_type *pt)
527 {
528
529
530
531
532 struct arphdr *arp = (struct arphdr *)skb->h.raw;
533 unsigned char *arp_ptr= (unsigned char *)(arp+1);
534 struct arp_table *entry;
535 struct arp_table *proxy_entry;
536 int addr_hint,hlen,htype;
537 unsigned long hash;
538 unsigned char ha[MAX_ADDR_LEN];
539 long sip,tip;
540 unsigned char *sha,*tha;
541
542
543
544
545
546
547
548
549 if (arp->ar_hln != dev->addr_len ||
550 dev->type != ntohs(arp->ar_hrd) ||
551 dev->flags & IFF_NOARP ||
552 arp->ar_pln != 4)
553 {
554 kfree_skb(skb, FREE_READ);
555 return 0;
556 }
557
558
559
560
561
562
563
564 switch(dev->type)
565 {
566 #ifdef CONFIG_AX25
567 case ARPHRD_AX25:
568 if(arp->ar_pro != htons(AX25_P_IP))
569 {
570 kfree_skb(skb, FREE_READ);
571 return 0;
572 }
573 break;
574 #endif
575 case ARPHRD_ETHER:
576 case ARPHRD_ARCNET:
577 if(arp->ar_pro != htons(ETH_P_IP))
578 {
579 kfree_skb(skb, FREE_READ);
580 return 0;
581 }
582 break;
583
584 default:
585 printk("ARP: dev->type mangled!\n");
586 kfree_skb(skb, FREE_READ);
587 return 0;
588 }
589
590
591
592
593
594 hlen = dev->addr_len;
595 htype = dev->type;
596
597 sha=arp_ptr;
598 arp_ptr+=hlen;
599 memcpy(&sip,arp_ptr,4);
600 arp_ptr+=4;
601 tha=arp_ptr;
602 arp_ptr+=hlen;
603 memcpy(&tip,arp_ptr,4);
604
605
606
607
608 if(tip == INADDR_LOOPBACK)
609 {
610 kfree_skb(skb, FREE_READ);
611 return 0;
612 }
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631 addr_hint = ip_chk_addr(tip);
632
633 if(arp->ar_op == htons(ARPOP_REPLY))
634 {
635 if(addr_hint!=IS_MYADDR)
636 {
637
638
639
640 kfree_skb(skb, FREE_READ);
641 return 0;
642 }
643
644
645
646 }
647 else
648 {
649
650
651
652 if(addr_hint != IS_MYADDR)
653 {
654
655
656
657
658
659 cli();
660 for(proxy_entry=arp_tables[PROXY_HASH];
661 proxy_entry;
662 proxy_entry = proxy_entry->next)
663 {
664
665
666
667
668
669
670
671
672 if (proxy_entry->htype == htype &&
673 !((proxy_entry->ip^tip)&proxy_entry->mask))
674 break;
675
676 }
677 if (proxy_entry)
678 {
679 memcpy(ha, proxy_entry->ha, hlen);
680 sti();
681 arp_send(ARPOP_REPLY,ETH_P_ARP,sip,dev,tip,sha,ha);
682 kfree_skb(skb, FREE_READ);
683 return 0;
684 }
685 else
686 {
687 sti();
688 kfree_skb(skb, FREE_READ);
689 return 0;
690 }
691 }
692 else
693 {
694
695
696
697 arp_send(ARPOP_REPLY,ETH_P_ARP,sip,dev,tip,sha,dev->dev_addr);
698 }
699 }
700
701
702
703
704
705
706
707
708 hash = HASH(sip);
709 cli();
710 for(entry=arp_tables[hash];entry;entry=entry->next)
711 if(entry->ip==sip && entry->htype==htype)
712 break;
713
714 if(entry)
715 {
716
717
718
719 memcpy(entry->ha, sha, hlen);
720 entry->hlen = hlen;
721 entry->last_used = jiffies;
722 if (!(entry->flags & ATF_COM))
723 {
724
725
726
727
728 del_timer(&entry->timer);
729 entry->flags |= ATF_COM;
730 sti();
731
732
733
734
735
736 arp_send_q(entry, sha);
737 }
738 else
739 {
740 sti();
741 }
742 }
743 else
744 {
745
746
747
748 entry = (struct arp_table *)kmalloc(sizeof(struct arp_table),GFP_ATOMIC);
749 if(entry == NULL)
750 {
751 sti();
752 printk("ARP: no memory for new arp entry\n");
753
754 kfree_skb(skb, FREE_READ);
755 return 0;
756 }
757
758 entry->mask = DEF_ARP_NETMASK;
759 entry->ip = sip;
760 entry->hlen = hlen;
761 entry->htype = htype;
762 entry->flags = ATF_COM;
763 init_timer(&entry->timer);
764 memcpy(entry->ha, sha, hlen);
765 entry->last_used = jiffies;
766 entry->dev = skb->dev;
767 skb_queue_head_init(&entry->skb);
768 entry->next = arp_tables[hash];
769 arp_tables[hash] = entry;
770 sti();
771 }
772
773
774
775
776 kfree_skb(skb, FREE_READ);
777 return 0;
778 }
779
780
781
782
783
784
785 int arp_find(unsigned char *haddr, unsigned long paddr, struct device *dev,
786 unsigned long saddr, struct sk_buff *skb)
787 {
788 struct arp_table *entry;
789 unsigned long hash;
790 #ifdef CONFIG_IP_MULTICAST
791 unsigned long taddr;
792 #endif
793
794 switch (ip_chk_addr(paddr))
795 {
796 case IS_MYADDR:
797 printk("ARP: arp called for own IP address\n");
798 memcpy(haddr, dev->dev_addr, dev->addr_len);
799 skb->arp = 1;
800 return 0;
801 #ifdef CONFIG_IP_MULTICAST
802 case IS_MULTICAST:
803 if(dev->type==ARPHRD_ETHER || dev->type==ARPHRD_IEEE802)
804 {
805 haddr[0]=0x01;
806 haddr[1]=0x00;
807 haddr[2]=0x5e;
808 taddr=ntohl(paddr);
809 haddr[5]=taddr&0xff;
810 taddr=taddr>>8;
811 haddr[4]=taddr&0xff;
812 taddr=taddr>>8;
813 haddr[3]=taddr&0x7f;
814 return 0;
815 }
816
817
818
819 #endif
820
821 case IS_BROADCAST:
822 memcpy(haddr, dev->broadcast, dev->addr_len);
823 skb->arp = 1;
824 return 0;
825 }
826
827 hash = HASH(paddr);
828 cli();
829
830
831
832
833 entry = arp_lookup(paddr, 0);
834
835 if (entry != NULL)
836 {
837 if (!(entry->flags & ATF_COM))
838 {
839
840
841
842
843
844 if (skb != NULL)
845 {
846 skb_queue_tail(&entry->skb, skb);
847 skb_device_unlock(skb);
848 }
849 sti();
850 return 1;
851 }
852
853
854
855
856
857 entry->last_used = jiffies;
858 memcpy(haddr, entry->ha, dev->addr_len);
859 if (skb)
860 skb->arp = 1;
861 sti();
862 return 0;
863 }
864
865
866
867
868
869 entry = (struct arp_table *) kmalloc(sizeof(struct arp_table),
870 GFP_ATOMIC);
871 if (entry != NULL)
872 {
873 entry->mask = DEF_ARP_NETMASK;
874 entry->ip = paddr;
875 entry->hlen = dev->addr_len;
876 entry->htype = dev->type;
877 entry->flags = 0;
878 memset(entry->ha, 0, dev->addr_len);
879 entry->dev = dev;
880 entry->last_used = jiffies;
881 init_timer(&entry->timer);
882 entry->timer.function = arp_expire_request;
883 entry->timer.data = (unsigned long)entry;
884 entry->timer.expires = ARP_RES_TIME;
885 entry->next = arp_tables[hash];
886 arp_tables[hash] = entry;
887 add_timer(&entry->timer);
888 entry->retries = ARP_MAX_TRIES;
889 skb_queue_head_init(&entry->skb);
890 if (skb != NULL)
891 {
892 skb_queue_tail(&entry->skb, skb);
893 skb_device_unlock(skb);
894 }
895 }
896 else
897 {
898 if (skb != NULL && skb->free)
899 kfree_skb(skb, FREE_WRITE);
900 }
901 sti();
902
903
904
905
906
907 arp_send(ARPOP_REQUEST, ETH_P_ARP, paddr, dev, saddr, NULL,
908 dev->dev_addr);
909
910 return 1;
911 }
912
913
914
915
916
917
918 #define HBUFFERLEN 30
919
920 int arp_get_info(char *buffer, char **start, off_t offset, int length)
921 {
922 int len=0;
923 off_t begin=0;
924 off_t pos=0;
925 int size;
926 struct arp_table *entry;
927 char hbuffer[HBUFFERLEN];
928 int i,j,k;
929 const char hexbuf[] = "0123456789ABCDEF";
930
931 size = sprintf(buffer,"IP address HW type Flags HW address Mask\n");
932
933 pos+=size;
934 len+=size;
935
936 cli();
937 for(i=0; i<FULL_ARP_TABLE_SIZE; i++)
938 {
939 for(entry=arp_tables[i]; entry!=NULL; entry=entry->next)
940 {
941
942
943
944 #ifdef CONFIG_AX25
945
946 if(entry->htype==ARPHRD_AX25)
947 strcpy(hbuffer,ax2asc((ax25_address *)entry->ha));
948 else {
949 #endif
950
951 for(k=0,j=0;k<HBUFFERLEN-3 && j<entry->hlen;j++)
952 {
953 hbuffer[k++]=hexbuf[ (entry->ha[j]>>4)&15 ];
954 hbuffer[k++]=hexbuf[ entry->ha[j]&15 ];
955 hbuffer[k++]=':';
956 }
957 hbuffer[--k]=0;
958
959 #ifdef CONFIG_AX25
960 }
961 #endif
962 size = sprintf(buffer+len,
963 "%-17s0x%-10x0x%-10x%s",
964 in_ntoa(entry->ip),
965 (unsigned int)entry->htype,
966 entry->flags,
967 hbuffer);
968 size += sprintf(buffer+len+size,
969 " %-17s\n",
970 entry->mask==DEF_ARP_NETMASK?
971 "*":in_ntoa(entry->mask));
972
973 len+=size;
974 pos=begin+len;
975
976 if(pos<offset)
977 {
978 len=0;
979 begin=pos;
980 }
981 if(pos>offset+length)
982 break;
983 }
984 }
985 sti();
986
987 *start=buffer+(offset-begin);
988 len-=(offset-begin);
989 if(len>length)
990 len=length;
991 return len;
992 }
993
994
995
996
997
998
999
1000
1001 static struct arp_table *arp_lookup(unsigned long paddr, int exact)
1002 {
1003 struct arp_table *entry;
1004 unsigned long hash = HASH(paddr);
1005
1006 for (entry = arp_tables[hash]; entry != NULL; entry = entry->next)
1007 if (entry->ip == paddr) break;
1008
1009
1010 if (!entry)
1011 for (entry=arp_tables[PROXY_HASH]; entry != NULL; entry = entry->next)
1012 if (exact? (entry->ip==paddr) : !((entry->ip^paddr)&entry->mask))
1013 break;
1014
1015 return entry;
1016 }
1017
1018
1019
1020
1021
1022
1023 static int arp_req_set(struct arpreq *req)
1024 {
1025 struct arpreq r;
1026 struct arp_table *entry;
1027 struct sockaddr_in *si;
1028 int htype, hlen;
1029 unsigned long ip;
1030 struct rtable *rt;
1031
1032 memcpy_fromfs(&r, req, sizeof(r));
1033
1034
1035 if (r.arp_pa.sa_family != AF_INET)
1036 return -EPFNOSUPPORT;
1037
1038
1039
1040
1041
1042
1043
1044 switch (r.arp_ha.sa_family) {
1045 case ARPHRD_ETHER:
1046 htype = ARPHRD_ETHER;
1047 hlen = ETH_ALEN;
1048 break;
1049 case ARPHRD_ARCNET:
1050 htype = ARPHRD_ARCNET;
1051 hlen = 1;
1052 break;
1053 #ifdef CONFIG_AX25
1054 case ARPHRD_AX25:
1055 htype = ARPHRD_AX25;
1056 hlen = 7;
1057 break;
1058 #endif
1059 default:
1060 return -EPFNOSUPPORT;
1061 }
1062
1063 si = (struct sockaddr_in *) &r.arp_pa;
1064 ip = si->sin_addr.s_addr;
1065 if (ip == 0)
1066 {
1067 printk("ARP: SETARP: requested PA is 0.0.0.0 !\n");
1068 return -EINVAL;
1069 }
1070
1071
1072
1073
1074
1075 rt = ip_rt_route(ip, NULL, NULL);
1076 if (rt == NULL)
1077 return -ENETUNREACH;
1078
1079
1080
1081
1082
1083 cli();
1084
1085
1086
1087
1088 entry = arp_lookup(ip, 1);
1089
1090
1091
1092
1093
1094 if (entry == NULL)
1095 {
1096 unsigned long hash = HASH(ip);
1097 if (r.arp_flags & ATF_PUBL)
1098 hash = PROXY_HASH;
1099
1100 entry = (struct arp_table *) kmalloc(sizeof(struct arp_table),
1101 GFP_ATOMIC);
1102 if (entry == NULL)
1103 {
1104 sti();
1105 return -ENOMEM;
1106 }
1107 entry->ip = ip;
1108 entry->hlen = hlen;
1109 entry->htype = htype;
1110 init_timer(&entry->timer);
1111 entry->next = arp_tables[hash];
1112 arp_tables[hash] = entry;
1113 skb_queue_head_init(&entry->skb);
1114 }
1115
1116
1117
1118
1119 memcpy(&entry->ha, &r.arp_ha.sa_data, hlen);
1120 entry->last_used = jiffies;
1121 entry->flags = r.arp_flags | ATF_COM;
1122 if ((entry->flags & ATF_PUBL) && (entry->flags & ATF_NETMASK))
1123 {
1124 si = (struct sockaddr_in *) &r.arp_netmask;
1125 entry->mask = si->sin_addr.s_addr;
1126 }
1127 else
1128 entry->mask = DEF_ARP_NETMASK;
1129 entry->dev = rt->rt_dev;
1130 sti();
1131
1132 return 0;
1133 }
1134
1135
1136
1137
1138
1139
1140 static int arp_req_get(struct arpreq *req)
1141 {
1142 struct arpreq r;
1143 struct arp_table *entry;
1144 struct sockaddr_in *si;
1145
1146
1147
1148
1149
1150 memcpy_fromfs(&r, req, sizeof(r));
1151
1152 if (r.arp_pa.sa_family != AF_INET)
1153 return -EPFNOSUPPORT;
1154
1155
1156
1157
1158
1159 si = (struct sockaddr_in *) &r.arp_pa;
1160 cli();
1161 entry = arp_lookup(si->sin_addr.s_addr,0);
1162
1163 if (entry == NULL)
1164 {
1165 sti();
1166 return -ENXIO;
1167 }
1168
1169
1170
1171
1172
1173 memcpy(r.arp_ha.sa_data, &entry->ha, entry->hlen);
1174 r.arp_ha.sa_family = entry->htype;
1175 r.arp_flags = entry->flags;
1176 sti();
1177
1178
1179
1180
1181
1182 memcpy_tofs(req, &r, sizeof(r));
1183 return 0;
1184 }
1185
1186
1187
1188
1189
1190
1191 int arp_ioctl(unsigned int cmd, void *arg)
1192 {
1193 struct arpreq r;
1194 struct sockaddr_in *si;
1195 int err;
1196
1197 switch(cmd)
1198 {
1199 case SIOCDARP:
1200 if (!suser())
1201 return -EPERM;
1202 err = verify_area(VERIFY_READ, arg, sizeof(struct arpreq));
1203 if(err)
1204 return err;
1205 memcpy_fromfs(&r, arg, sizeof(r));
1206 if (r.arp_pa.sa_family != AF_INET)
1207 return -EPFNOSUPPORT;
1208 si = (struct sockaddr_in *) &r.arp_pa;
1209 arp_destroy(si->sin_addr.s_addr, 1);
1210 return 0;
1211 case SIOCGARP:
1212 err = verify_area(VERIFY_WRITE, arg, sizeof(struct arpreq));
1213 if(err)
1214 return err;
1215 return arp_req_get((struct arpreq *)arg);
1216 case SIOCSARP:
1217 if (!suser())
1218 return -EPERM;
1219 err = verify_area(VERIFY_READ, arg, sizeof(struct arpreq));
1220 if(err)
1221 return err;
1222 return arp_req_set((struct arpreq *)arg);
1223 default:
1224 return -EINVAL;
1225 }
1226
1227 return 0;
1228 }
1229
1230
1231
1232
1233
1234
1235 static struct packet_type arp_packet_type =
1236 {
1237 0,
1238 0,
1239 arp_rcv,
1240 NULL,
1241 NULL
1242 };
1243
1244 void arp_init (void)
1245 {
1246
1247 arp_packet_type.type=htons(ETH_P_ARP);
1248 dev_add_pack(&arp_packet_type);
1249
1250 add_timer(&arp_timer);
1251 }
1252