This source file includes following definitions.
- eth_print
- eth_setup
- eth_dump
- eth_header
- eth_rebuild_header
- eth_add_arp
- eth_type_trans
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 #include <asm/segment.h>
20 #include <asm/system.h>
21 #include <linux/types.h>
22 #include <linux/kernel.h>
23 #include <linux/sched.h>
24 #include <linux/string.h>
25 #include <linux/mm.h>
26 #include <linux/socket.h>
27 #include <linux/in.h>
28 #include "inet.h"
29 #include "dev.h"
30 #include "eth.h"
31 #include "ip.h"
32 #include "route.h"
33 #include "protocol.h"
34 #include "tcp.h"
35 #include "skbuff.h"
36 #include "sock.h"
37 #include <linux/errno.h>
38 #include "arp.h"
39
40
41
42 char *eth_print(unsigned char *ptr)
43 {
44 static char buff[64];
45
46 if (ptr == NULL) return("[NONE]");
47 sprintf(buff, "%02X:%02X:%02X:%02X:%02X:%02X",
48 (ptr[0] & 255), (ptr[1] & 255), (ptr[2] & 255),
49 (ptr[3] & 255), (ptr[4] & 255), (ptr[5] & 255)
50 );
51 return(buff);
52 }
53
54 void eth_setup(char *str, int *ints)
55 {
56 struct device *d = dev_base;
57
58 if (!str || !*str)
59 return;
60 while (d) {
61 if (!strcmp(str,d->name)) {
62 if (ints[0] > 0)
63 d->irq=ints[1];
64 if (ints[0] > 1)
65 d->base_addr=ints[2];
66 if (ints[0] > 2)
67 d->mem_start=ints[3];
68 if (ints[0] > 3)
69 d->mem_end=ints[4];
70 break;
71 }
72 d=d->next;
73 }
74 }
75
76
77 void
78 eth_dump(struct ethhdr *eth)
79 {
80 if (inet_debug != DBG_ETH) return;
81
82 printk("eth: SRC = %s ", eth_print(eth->h_source));
83 printk("DST = %s ", eth_print(eth->h_dest));
84 printk("TYPE = %04X\n", ntohs(eth->h_proto));
85 }
86
87
88
89 int
90 eth_header(unsigned char *buff, struct device *dev, unsigned short type,
91 unsigned long daddr, unsigned long saddr, unsigned len)
92 {
93 struct ethhdr *eth;
94
95 DPRINTF((DBG_DEV, "ETH: header(%s, ", in_ntoa(saddr)));
96 DPRINTF((DBG_DEV, "%s, 0x%X)\n", in_ntoa(daddr), type));
97
98
99 eth = (struct ethhdr *) buff;
100 eth->h_proto = ntohs(type);
101 memcpy(eth->h_source, dev->dev_addr, dev->addr_len);
102
103
104 if (dev->flags & IFF_LOOPBACK) {
105 DPRINTF((DBG_DEV, "ETH: No header for loopback\n"));
106 memset(eth->h_dest, 0, dev->addr_len);
107 return(dev->hard_header_len);
108 }
109
110
111 if (chk_addr(daddr) == IS_BROADCAST) {
112 DPRINTF((DBG_DEV, "ETH: Using MAC Broadcast\n"));
113 memcpy(eth->h_dest, dev->broadcast, dev->addr_len);
114 return(dev->hard_header_len);
115 }
116
117
118 if (arp_find(eth->h_dest, daddr, dev, saddr)) {
119 return(-dev->hard_header_len);
120 } else return(dev->hard_header_len);
121 }
122
123
124
125 int
126 eth_rebuild_header(void *buff, struct device *dev)
127 {
128 struct ethhdr *eth;
129 unsigned long src, dst;
130
131 DPRINTF((DBG_DEV, "ETH: Using MAC Broadcast\n"));
132 eth = (struct ethhdr *) buff;
133 src = *(unsigned long *) eth->h_source;
134 dst = *(unsigned long *) eth->h_dest;
135 DPRINTF((DBG_DEV, "ETH: RebuildHeader: SRC=%s ", in_ntoa(src)));
136 DPRINTF((DBG_DEV, "DST=%s\n", in_ntoa(dst)));
137 if (arp_find(eth->h_dest, dst, dev, src)) return(1);
138 memcpy(eth->h_source, dev->dev_addr, dev->addr_len);
139 return(0);
140 }
141
142
143
144 void
145 eth_add_arp(unsigned long addr, struct sk_buff *skb, struct device *dev)
146 {
147 struct ethhdr *eth;
148
149 eth = (struct ethhdr *) (skb + 1);
150 arp_add(addr, eth->h_source, dev);
151 }
152
153
154
155 unsigned short
156 eth_type_trans(struct sk_buff *skb, struct device *dev)
157 {
158 struct ethhdr *eth;
159
160 eth = (struct ethhdr *) (skb + 1);
161 return(eth->h_proto);
162 }