This source file includes following definitions.
- unk_print
- eth_aprint
- arp_print
- arp_send_q
- arp_response
- arp_lookup
- arp_lookup_proxy
- arp_destructor
- arp_destroy
- arp_destroy_maybe
- arp_create
- arp_rcv
- arp_send
- arp_find
- arp_add
- arp_add_broad
- arp_queue
- arp_get_info
- arp_req_set
- arp_req_get
- arp_req_del
- arp_ioctl
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56 #include <linux/types.h>
57 #include <linux/string.h>
58 #include <linux/kernel.h>
59 #include <linux/sched.h>
60 #include <linux/config.h>
61 #include <linux/socket.h>
62 #include <linux/sockios.h>
63 #include <linux/errno.h>
64 #include <linux/if_arp.h>
65 #include <linux/in.h>
66 #include <asm/system.h>
67 #include <asm/segment.h>
68 #include <stdarg.h>
69 #include "inet.h"
70 #include "dev.h"
71 #include "eth.h"
72 #include "ip.h"
73 #include "route.h"
74 #include "protocol.h"
75 #include "tcp.h"
76 #include "skbuff.h"
77 #include "sock.h"
78 #include "arp.h"
79
80
81 #define ARP_MAX_TRIES 3
82
83
84 static char *unk_print(unsigned char *, int);
85 static char *eth_aprint(unsigned char *, int);
86
87
88 static char *arp_cmds[] = {
89 "0x%04X",
90 "REQUEST",
91 "REPLY",
92 "REVERSE REQUEST",
93 "REVERSE REPLY",
94 NULL
95 };
96 #define ARP_MAX_CMDS (sizeof(arp_cmds) / sizeof(arp_cmds[0]))
97
98 static struct {
99 char *name;
100 char *(*print)(unsigned char *ptr, int len);
101 } arp_types[] = {
102 { "0x%04X", unk_print },
103 { "10 Mbps Ethernet", eth_aprint },
104 { "3 Mbps Ethernet", eth_aprint },
105 { "AX.25", unk_print },
106 { "Pronet", unk_print },
107 { "Chaos", unk_print },
108 { "IEEE 802.2 Ethernet (?)", eth_aprint },
109 { "Arcnet", unk_print },
110 { "AppleTalk", unk_print },
111 { NULL, NULL }
112 };
113 #define ARP_MAX_TYPE (sizeof(arp_types) / sizeof(arp_types[0]))
114
115
116 struct arp_table *arp_tables[ARP_TABLE_SIZE] = {
117 NULL,
118 };
119
120 static int arp_proxies=0;
121
122
123
124 struct sk_buff * volatile arp_q = NULL;
125
126 static struct arp_table *arp_lookup(unsigned long addr);
127 static struct arp_table *arp_lookup_proxy(unsigned long addr);
128
129
130 static char *
131 unk_print(unsigned char *ptr, int len)
132 {
133 static char buff[32];
134 char *bufp = buff;
135 int i;
136
137 for (i = 0; i < len; i++)
138 bufp += sprintf(bufp, "%02X ", (*ptr++ & 0377));
139 return(buff);
140 }
141
142
143
144 static char *
145 eth_aprint(unsigned char *ptr, int len)
146 {
147 if (len != ETH_ALEN) return("");
148 return(eth_print(ptr));
149 }
150
151
152
153 static void
154 arp_print(struct arphdr *arp)
155 {
156 int len, idx;
157 unsigned char *ptr;
158
159 if (inet_debug != DBG_ARP) return;
160
161 printk("ARP: ");
162 if (arp == NULL) {
163 printk("(null)\n");
164 return;
165 }
166
167
168 len = htons(arp->ar_op);
169 if (len < ARP_MAX_CMDS) idx = len;
170 else idx = 0;
171 printk("op ");
172 printk(arp_cmds[idx], len);
173
174
175 len = htons(arp->ar_hrd);
176 if (len < ARP_MAX_TYPE) idx = len;
177 else idx = 0;
178 printk(" hrd = "); printk(arp_types[idx].name, len);
179 printk(" pro = 0x%04X\n", htons(arp->ar_pro));
180 printk(" hlen = %d plen = %d\n", arp->ar_hln, arp->ar_pln);
181
182
183
184
185
186
187
188 ptr = ((unsigned char *) &arp->ar_op) + sizeof(u_short);
189 printk(" sender HA = %s ", arp_types[idx].print(ptr, arp->ar_hln));
190 ptr += arp->ar_hln;
191 printk(" PA = %s\n", in_ntoa(*(unsigned long *) ptr));
192 ptr += arp->ar_pln;
193 printk(" target HA = %s ", arp_types[idx].print(ptr, arp->ar_hln));
194 ptr += arp->ar_hln;
195 printk(" PA = %s\n", in_ntoa(*(unsigned long *) ptr));
196 }
197
198
199
200 static void
201 arp_send_q(void)
202 {
203 struct sk_buff *skb;
204 struct sk_buff *volatile work_q;
205 cli();
206 work_q = arp_q;
207 skb_new_list_head(&work_q);
208 arp_q = NULL;
209 sti();
210 while((skb=skb_dequeue(&work_q))!=NULL)
211 {
212 IS_SKB(skb);
213 skb->magic = 0;
214 skb->next = NULL;
215 skb->prev = NULL;
216
217
218 cli();
219 skb->tries--;
220 if (skb->tries == 0) {
221
222
223
224
225
226
227
228
229
230 skb->sk = NULL;
231 if(skb->free)
232 kfree_skb(skb, FREE_WRITE);
233
234
235 sti();
236 continue;
237 }
238
239
240 sti();
241 if (skb->arp || !skb->dev->rebuild_header(skb->data, skb->dev)) {
242 skb->arp = 1;
243 skb->dev->queue_xmit(skb, skb->dev, 0);
244 } else {
245
246 skb->magic = ARP_QUEUE_MAGIC;
247 skb_queue_head(&arp_q,skb);
248 }
249 }
250 }
251
252
253
254 static int
255 arp_response(struct arphdr *arp1, struct device *dev, int addrtype)
256 {
257 struct arphdr *arp2;
258 struct sk_buff *skb;
259 unsigned long src, dst;
260 unsigned char *ptr1, *ptr2;
261 int hlen;
262 struct arp_table *apt = NULL;
263
264
265 ptr1 = ((unsigned char *) &arp1->ar_op) + sizeof(u_short);
266 src = *((unsigned long *) (ptr1 + arp1->ar_hln));
267 dst = *((unsigned long *) (ptr1 + (arp1->ar_hln * 2) + arp1->ar_pln));
268
269 if(addrtype!=IS_MYADDR)
270 {
271 apt=arp_lookup_proxy(dst);
272 if(apt==NULL)
273 return(1);
274 }
275
276
277 skb = alloc_skb(sizeof(struct sk_buff) +
278 sizeof(struct arphdr) +
279 (2 * arp1->ar_hln) + (2 * arp1->ar_pln) +
280 dev->hard_header_len, GFP_ATOMIC);
281 if (skb == NULL) {
282 printk("ARP: no memory available for ARP REPLY!\n");
283 return(1);
284 }
285
286 skb->mem_addr = skb;
287 skb->len = sizeof(struct arphdr) + (2 * arp1->ar_hln) +
288 (2 * arp1->ar_pln) + dev->hard_header_len;
289 skb->mem_len = sizeof(struct sk_buff) + skb->len;
290 hlen = dev->hard_header(skb->data, dev, ETH_P_ARP, src, dst, skb->len);
291 if (hlen < 0) {
292 printk("ARP: cannot create HW frame header for REPLY !\n");
293 kfree_skb(skb, FREE_WRITE);
294 return(1);
295 }
296
297
298
299
300
301
302 arp2 = (struct arphdr *) (skb->data + hlen);
303 ptr2 = ((unsigned char *) &arp2->ar_op) + sizeof(u_short);
304 arp2->ar_hrd = arp1->ar_hrd;
305 arp2->ar_pro = arp1->ar_pro;
306 arp2->ar_hln = arp1->ar_hln;
307 arp2->ar_pln = arp1->ar_pln;
308 arp2->ar_op = htons(ARPOP_REPLY);
309 if(addrtype==IS_MYADDR)
310 memcpy(ptr2, dev->dev_addr, arp2->ar_hln);
311 else
312 memcpy(ptr2, apt->ha, arp2->ar_hln);
313 ptr2 += arp2->ar_hln;
314 memcpy(ptr2, ptr1 + (arp1->ar_hln * 2) + arp1->ar_pln, arp2->ar_pln);
315 ptr2 += arp2->ar_pln;
316 memcpy(ptr2, ptr1, arp2->ar_hln);
317 ptr2 += arp2->ar_hln;
318 memcpy(ptr2, ptr1 + arp1->ar_hln, arp2->ar_pln);
319
320 skb->free = 1;
321 skb->arp = 1;
322 skb->sk = NULL;
323 skb->next = NULL;
324
325 DPRINTF((DBG_ARP, ">>"));
326 arp_print(arp2);
327
328
329 dev->queue_xmit(skb, dev, 0);
330 return(0);
331 }
332
333
334
335 static struct arp_table *
336 arp_lookup(unsigned long paddr)
337 {
338 struct arp_table *apt;
339 unsigned long hash;
340
341 DPRINTF((DBG_ARP, "ARP: lookup(%s)\n", in_ntoa(paddr)));
342
343
344 if (chk_addr(paddr) == IS_MYADDR) {
345 printk("ARP: ARPing my own IP address %s !\n", in_ntoa(paddr));
346 return(NULL);
347 }
348
349
350 hash = htonl(paddr) & (ARP_TABLE_SIZE - 1);
351 cli();
352 apt = arp_tables[hash];
353 while(apt != NULL) {
354 if (apt->ip == paddr) {
355 sti();
356 return(apt);
357 }
358 apt = apt->next;
359 }
360 sti();
361 return(NULL);
362 }
363
364
365
366 static struct arp_table *arp_lookup_proxy(unsigned long paddr)
367 {
368 struct arp_table *apt;
369 unsigned long hash;
370
371 DPRINTF((DBG_ARP, "ARP: lookup proxy(%s)\n", in_ntoa(paddr)));
372
373
374 hash = htonl(paddr) & (ARP_TABLE_SIZE - 1);
375 cli();
376 apt = arp_tables[hash];
377 while(apt != NULL) {
378 if (apt->ip == paddr && (apt->flags & ATF_PUBL) ) {
379 sti();
380 return(apt);
381 }
382 apt = apt->next;
383 }
384 sti();
385 return(NULL);
386 }
387
388
389
390 void
391 arp_destructor(unsigned long paddr, int force)
392 {
393 struct arp_table *apt;
394 struct arp_table **lapt;
395 unsigned long hash;
396
397 DPRINTF((DBG_ARP, "ARP: destroy(%s)\n", in_ntoa(paddr)));
398
399
400 if (chk_addr(paddr) == IS_MYADDR) {
401 DPRINTF((DBG_ARP, "ARP: Destroying my own IP address %s !\n",
402 in_ntoa(paddr)));
403 return;
404 }
405 hash = htonl(paddr) & (ARP_TABLE_SIZE - 1);
406
407 cli();
408 lapt = &arp_tables[hash];
409 while ((apt = *lapt) != NULL) {
410 if (apt->ip == paddr) {
411 if((apt->flags&ATF_PERM) && !force)
412 return;
413 *lapt = apt->next;
414 if(apt->flags&ATF_PUBL)
415 arp_proxies--;
416 kfree_s(apt, sizeof(struct arp_table));
417 sti();
418 return;
419 }
420 lapt = &apt->next;
421 }
422 sti();
423 }
424
425
426
427
428
429 void arp_destroy(unsigned long paddr)
430 {
431 arp_destructor(paddr,1);
432 }
433
434
435
436
437
438 void arp_destroy_maybe(unsigned long paddr)
439 {
440 arp_destructor(paddr,0);
441 }
442
443
444 static struct arp_table *
445 arp_create(unsigned long paddr, unsigned char *addr, int hlen, int htype)
446 {
447 struct arp_table *apt;
448 unsigned long hash;
449
450 DPRINTF((DBG_ARP, "ARP: create(%s, ", in_ntoa(paddr)));
451 DPRINTF((DBG_ARP, "%s, ", eth_print(addr)));
452 DPRINTF((DBG_ARP, "%d, %d)\n", hlen, htype));
453
454 apt = (struct arp_table *) kmalloc(sizeof(struct arp_table), GFP_ATOMIC);
455 if (apt == NULL) {
456 printk("ARP: no memory available for new ARP entry!\n");
457 return(NULL);
458 }
459
460
461 hash = htonl(paddr) & (ARP_TABLE_SIZE - 1);
462 apt->ip = paddr;
463 apt->hlen = hlen;
464 apt->htype = htype;
465 apt->flags = (ATF_INUSE | ATF_COM);
466 memcpy(apt->ha, addr, hlen);
467 apt->last_used = jiffies;
468 cli();
469 apt->next = arp_tables[hash];
470 arp_tables[hash] = apt;
471 sti();
472 return(apt);
473 }
474
475
476
477
478
479
480
481
482
483
484
485 int
486 arp_rcv(struct sk_buff *skb, struct device *dev, struct packet_type *pt)
487 {
488 struct arphdr *arp;
489 struct arp_table *tbl;
490 unsigned long src, dst;
491 unsigned char *ptr;
492 int ret;
493 int addr_hint;
494
495 DPRINTF((DBG_ARP, "<<\n"));
496 arp = skb->h.arp;
497 arp_print(arp);
498
499
500 if (arp->ar_hln != dev->addr_len || dev->type != NET16(arp->ar_hrd))
501 {
502 DPRINTF((DBG_ARP,"ARP: Bad packet received on device \"%s\" !\n", dev->name));
503 kfree_skb(skb, FREE_READ);
504 return(0);
505 }
506
507
508 if (((arp->ar_pro != NET16(0x00CC) && dev->type==3) || (arp->ar_pro != NET16(ETH_P_IP) && dev->type!=3) ) || arp->ar_pln != 4)
509 {
510 if (arp->ar_op != NET16(ARPOP_REQUEST))
511 DPRINTF((DBG_ARP,"ARP: Non-IP request on device \"%s\" !\n", dev->name));
512 kfree_skb(skb, FREE_READ);
513 return(0);
514 }
515
516
517
518
519
520
521 ptr = ((unsigned char *) &arp->ar_op) + sizeof(u_short);
522 memcpy(&src, ptr + arp->ar_hln, arp->ar_pln);
523 tbl = arp_lookup(src);
524 if (tbl != NULL) {
525 DPRINTF((DBG_ARP, "ARP: udating entry for %s\n", in_ntoa(src)));
526 memcpy(tbl->ha, ptr, arp->ar_hln);
527 tbl->hlen = arp->ar_hln;
528 tbl->flags |= ATF_COM;
529 tbl->last_used = jiffies;
530 } else {
531 memcpy(&dst, ptr + (arp->ar_hln * 2) + arp->ar_pln, arp->ar_pln);
532 if (chk_addr(dst) != IS_MYADDR && arp_proxies == 0) {
533 kfree_skb(skb, FREE_READ);
534 return(0);
535 } else {
536 tbl = arp_create(src, ptr, arp->ar_hln, arp->ar_hrd);
537 if (tbl == NULL) {
538 kfree_skb(skb, FREE_READ);
539 return(0);
540 }
541 }
542 }
543
544
545
546
547
548
549 arp_send_q();
550
551
552
553
554
555 if (arp->ar_op != NET16(ARPOP_REQUEST)) {
556 kfree_skb(skb, FREE_READ);
557 return(0);
558 }
559
560
561
562
563
564 if(chk_addr(dst)==IS_BROADCAST)
565 {
566 kfree_skb(skb, FREE_READ);
567 return 0;
568 }
569
570 memcpy(&dst, ptr + (arp->ar_hln * 2) + arp->ar_pln, arp->ar_pln);
571 if ((addr_hint=chk_addr(dst)) != IS_MYADDR && arp_proxies==0) {
572 DPRINTF((DBG_ARP, "ARP: request was not for me!\n"));
573 kfree_skb(skb, FREE_READ);
574 return(0);
575 }
576
577
578
579
580
581 ret = arp_response(arp, dev, addr_hint);
582 kfree_skb(skb, FREE_READ);
583 return(ret);
584 }
585
586
587
588 void
589 arp_send(unsigned long paddr, struct device *dev, unsigned long saddr)
590 {
591 struct sk_buff *skb;
592 struct arphdr *arp;
593 unsigned char *ptr;
594 int tmp;
595
596 DPRINTF((DBG_ARP, "ARP: send(paddr=%s, ", in_ntoa(paddr)));
597 DPRINTF((DBG_ARP, "dev=%s, ", dev->name));
598 DPRINTF((DBG_ARP, "saddr=%s)\n", in_ntoa(saddr)));
599
600 skb = alloc_skb(sizeof(struct sk_buff) +
601 sizeof(struct arphdr) + (2 * dev->addr_len) +
602 dev->hard_header_len +
603 (2 * 4 ), GFP_ATOMIC);
604 if (skb == NULL) {
605 printk("ARP: No memory available for REQUEST %s\n", in_ntoa(paddr));
606 return;
607 }
608
609
610 skb->sk = NULL;
611 skb->mem_addr = skb;
612 skb->len = sizeof(struct arphdr) +
613 dev->hard_header_len + (2 * dev->addr_len) + 8;
614 skb->mem_len = sizeof(struct sk_buff) + skb->len;
615 skb->arp = 1;
616 skb->dev = dev;
617 skb->next = NULL;
618 skb->free = 1;
619 tmp = dev->hard_header(skb->data, dev, ETH_P_ARP, 0, saddr, skb->len);
620 if (tmp < 0) {
621 kfree_skb(skb,FREE_WRITE);
622 return;
623 }
624 arp = (struct arphdr *) (skb->data + tmp);
625 arp->ar_hrd = htons(dev->type);
626 if(dev->type!=3)
627 arp->ar_pro = htons(ETH_P_IP);
628 else
629 arp->ar_pro = htons(0xCC);
630 arp->ar_hln = dev->addr_len;
631 arp->ar_pln = 4;
632 arp->ar_op = htons(ARPOP_REQUEST);
633
634 ptr = ((unsigned char *) &arp->ar_op) + sizeof(u_short);
635 memcpy(ptr, dev->dev_addr, arp->ar_hln);
636 ptr += arp->ar_hln;
637 memcpy(ptr, &saddr, arp->ar_pln);
638 ptr += arp->ar_pln;
639
640 memset(ptr,0,arp->ar_hln);
641 ptr += arp->ar_hln;
642 memcpy(ptr, &paddr, arp->ar_pln);
643
644 DPRINTF((DBG_ARP, ">>\n"));
645 arp_print(arp);
646 dev->queue_xmit(skb, dev, 0);
647 }
648
649
650
651 int
652 arp_find(unsigned char *haddr, unsigned long paddr, struct device *dev,
653 unsigned long saddr)
654 {
655 struct arp_table *apt;
656
657 DPRINTF((DBG_ARP, "ARP: find(haddr=%s, ", eth_print(haddr)));
658 DPRINTF((DBG_ARP, "paddr=%s, ", in_ntoa(paddr)));
659 DPRINTF((DBG_ARP, "dev=%s, saddr=%s)\n", dev->name, in_ntoa(saddr)));
660
661 switch(chk_addr(paddr)) {
662 case IS_MYADDR:
663 memcpy(haddr, dev->dev_addr, dev->addr_len);
664 return(0);
665 case IS_BROADCAST:
666 memcpy(haddr, dev->broadcast, dev->addr_len);
667 return(0);
668 }
669
670 apt = arp_lookup(paddr);
671 if (apt != NULL) {
672
673
674
675
676
677 if ((apt->flags & ATF_PERM) ||
678 (apt->last_used < jiffies+ARP_TIMEOUT && apt->hlen != 0)) {
679 apt->last_used = jiffies;
680 memcpy(haddr, apt->ha, dev->addr_len);
681 return(0);
682 } else {
683 DPRINTF((DBG_ARP, "ARP: find: found expired entry for %s\n",
684 in_ntoa(apt->ip)));
685 }
686 }
687
688
689
690
691
692
693 *(unsigned long *)haddr = paddr;
694
695
696 arp_send(paddr, dev, saddr);
697
698 return(1);
699 }
700
701
702
703 void
704 arp_add(unsigned long addr, unsigned char *haddr, struct device *dev)
705 {
706 struct arp_table *apt;
707
708 DPRINTF((DBG_ARP, "ARP: add(%s, ", in_ntoa(addr)));
709 DPRINTF((DBG_ARP, "%s, ", eth_print(haddr)));
710 DPRINTF((DBG_ARP, "%d, %d)\n", dev->hard_header_len, dev->type));
711
712
713 if (addr == 0) {
714 printk("ARP: add: will not add entry for 0.0.0.0 !\n");
715 return;
716 }
717
718
719 apt = arp_lookup(addr);
720 if (apt != NULL) {
721 DPRINTF((DBG_ARP, "ARP: updating entry for %s\n", in_ntoa(addr)));
722 apt->last_used = jiffies;
723 memcpy(apt->ha, haddr , dev->addr_len);
724 return;
725 }
726 arp_create(addr, haddr, dev->addr_len, dev->type);
727 }
728
729
730
731 void
732 arp_add_broad(unsigned long addr, struct device *dev)
733 {
734 struct arp_table *apt;
735
736 arp_add(addr, dev->broadcast, dev);
737 apt = arp_lookup(addr);
738 if (apt != NULL) {
739 apt->flags |= ATF_PERM;
740 }
741 }
742
743
744
745 void
746 arp_queue(struct sk_buff *skb)
747 {
748 cli();
749 skb->tries = ARP_MAX_TRIES;
750
751 if (skb->next != NULL) {
752 sti();
753 printk("ARP: arp_queue skb already on queue magic=%X.\n", skb->magic);
754 return;
755 }
756 skb_queue_tail(&arp_q,skb);
757 skb->magic = ARP_QUEUE_MAGIC;
758 sti();
759 }
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777 int
778 arp_get_info(char *buffer)
779 {
780 struct arpreq *req;
781 struct arp_table *apt;
782 int i;
783 char *pos;
784
785
786 pos = buffer;
787 i = 0;
788 for (i = 0; i < ARP_TABLE_SIZE; i++) {
789 cli();
790 apt = arp_tables[i];
791 sti();
792 while (apt != NULL) {
793 if (pos < (buffer + 4000)) {
794 req = (struct arpreq *) pos;
795 memset((char *) req, 0, sizeof(struct arpreq));
796 req->arp_pa.sa_family = AF_INET;
797 memcpy((char *) req->arp_pa.sa_data, (char *) &apt->ip, 4);
798 req->arp_ha.sa_family = apt->htype;
799 memcpy((char *) req->arp_ha.sa_data,
800 (char *) &apt->ha, apt->hlen);
801 req->arp_flags = apt->flags;
802 }
803 pos += sizeof(struct arpreq);
804 cli();
805 apt = apt->next;
806 sti();
807 }
808 }
809 return(pos - buffer);
810 }
811
812
813
814 static int
815 arp_req_set(struct arpreq *req)
816 {
817 struct arpreq r;
818 struct arp_table *apt;
819 struct sockaddr_in *si;
820 int htype, hlen;
821
822
823 memcpy_fromfs(&r, req, sizeof(r));
824 if (r.arp_pa.sa_family != AF_INET) return(-EPFNOSUPPORT);
825
826
827
828
829
830
831 si = (struct sockaddr_in *) &r.arp_pa;
832 switch(r.arp_ha.sa_family) {
833 case 0:
834 case ARPHRD_ETHER:
835 htype = ARPHRD_ETHER;
836 hlen = ETH_ALEN;
837 break;
838 case ARPHRD_AX25:
839 htype = ARPHRD_AX25;
840 hlen = 7;
841 break;
842
843 default:
844 return(-EPFNOSUPPORT);
845 }
846
847
848 if (si->sin_addr.s_addr == 0) {
849 printk("ARP: SETARP: requested PA is 0.0.0.0 !\n");
850 return(-EINVAL);
851 }
852 apt = arp_lookup(si->sin_addr.s_addr);
853 if (apt == NULL) {
854 apt = arp_create(si->sin_addr.s_addr,
855 (unsigned char *) r.arp_ha.sa_data, hlen, htype);
856 if (apt == NULL) return(-ENOMEM);
857 }
858
859
860 memcpy((char *) &apt->ha, (char *) &r.arp_ha.sa_data, hlen);
861 apt->last_used = jiffies;
862 apt->flags = r.arp_flags;
863 if(apt->flags&ATF_PUBL)
864 arp_proxies++;
865
866 return(0);
867 }
868
869
870
871 static int
872 arp_req_get(struct arpreq *req)
873 {
874 struct arpreq r;
875 struct arp_table *apt;
876 struct sockaddr_in *si;
877
878
879 memcpy_fromfs(&r, req, sizeof(r));
880 if (r.arp_pa.sa_family != AF_INET) return(-EPFNOSUPPORT);
881
882
883 si = (struct sockaddr_in *) &r.arp_pa;
884 apt = arp_lookup(si->sin_addr.s_addr);
885 if (apt == NULL) return(-ENXIO);
886
887
888 memcpy((char *) r.arp_ha.sa_data, (char *) &apt->ha, apt->hlen);
889 r.arp_ha.sa_family = apt->htype;
890
891
892 memcpy_tofs(req, &r, sizeof(r));
893 return(0);
894 }
895
896
897
898 static int
899 arp_req_del(struct arpreq *req)
900 {
901 struct arpreq r;
902 struct sockaddr_in *si;
903
904
905 memcpy_fromfs(&r, req, sizeof(r));
906 if (r.arp_pa.sa_family != AF_INET) return(-EPFNOSUPPORT);
907
908 si = (struct sockaddr_in *) &r.arp_pa;
909
910
911
912 if(chk_addr(si->sin_addr.s_addr)==IS_MYADDR)
913 return -EINVAL;
914
915 arp_destroy(si->sin_addr.s_addr);
916
917 return(0);
918 }
919
920
921
922 int
923 arp_ioctl(unsigned int cmd, void *arg)
924 {
925 int err;
926 switch(cmd) {
927 case DDIOCSDBG:
928 return(dbg_ioctl(arg, DBG_ARP));
929 case SIOCDARP:
930 if (!suser()) return(-EPERM);
931 err=verify_area(VERIFY_READ,arg,sizeof(struct arpreq));
932 if(err)
933 return err;
934 return(arp_req_del((struct arpreq *)arg));
935 case SIOCGARP:
936 err=verify_area(VERIFY_WRITE,arg,sizeof(struct arpreq));
937 if(err)
938 return err;
939 return(arp_req_get((struct arpreq *)arg));
940 case SIOCSARP:
941 if (!suser()) return(-EPERM);
942 err=verify_area(VERIFY_READ,arg,sizeof(struct arpreq));
943 if(err)
944 return err;
945 return(arp_req_set((struct arpreq *)arg));
946 default:
947 return(-EINVAL);
948 }
949
950 return(0);
951 }