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