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