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