1 /*
2 * AX.25 release 037
3 *
4 * This code REQUIRES 2.1.15 or higher/ NET3.038
5 *
6 * This module:
7 * This module is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version
10 * 2 of the License, or (at your option) any later version.
11 *
12 * History
13 * AX.25 036 Jonathan(G4KLX) Split from af_ax25.c.
14 */
15
16 #include <linux/config.h>
17 #include <linux/errno.h>
18 #include <linux/types.h>
19 #include <linux/socket.h>
20 #include <linux/in.h>
21 #include <linux/kernel.h>
22 #include <linux/sched.h>
23 #include <linux/timer.h>
24 #include <linux/string.h>
25 #include <linux/sockios.h>
26 #include <linux/net.h>
27 #include <net/ax25.h>
28 #include <linux/inet.h>
29 #include <linux/netdevice.h>
30 #include <linux/if_arp.h>
31 #include <linux/skbuff.h>
32 #include <net/sock.h>
33 #include <asm/uaccess.h>
34 #include <asm/system.h>
35 #include <linux/fcntl.h>
36 #include <linux/termios.h> /* For TIOCINQ/OUTQ */
37 #include <linux/mm.h>
38 #include <linux/interrupt.h>
39 #include <linux/notifier.h>
40 #include <linux/proc_fs.h>
41 #include <linux/stat.h>
42 #include <linux/netfilter.h>
43 #include <linux/sysctl.h>
44 #include <net/ip.h>
45 #include <net/arp.h>
46
47 /*
48 * IP over AX.25 encapsulation.
49 */
50
51 /*
52 * Shove an AX.25 UI header on an IP packet and handle ARP
53 */
54
55 #ifdef CONFIG_INET
56
57 int ax25_encapsulate(struct sk_buff *skb, struct net_device *dev, unsigned short type, void *daddr, void *saddr, unsigned len)
58 {
59 /* header is an AX.25 UI frame from us to them */
60 unsigned char *buff = skb_push(skb, AX25_HEADER_LEN);
61
62 *buff++ = 0x00; /* KISS DATA */
63
64 if (daddr != NULL)
65 memcpy(buff, daddr, dev->addr_len); /* Address specified */
66
67 buff[6] &= ~AX25_CBIT;
68 buff[6] &= ~AX25_EBIT;
69 buff[6] |= AX25_SSSID_SPARE;
70 buff += AX25_ADDR_LEN;
71
72 if (saddr != NULL)
73 memcpy(buff, saddr, dev->addr_len);
74 else
75 memcpy(buff, dev->dev_addr, dev->addr_len);
76
77 buff[6] &= ~AX25_CBIT;
78 buff[6] |= AX25_EBIT;
79 buff[6] |= AX25_SSSID_SPARE;
80 buff += AX25_ADDR_LEN;
81
82 *buff++ = AX25_UI; /* UI */
83
84 /* Append a suitable AX.25 PID */
85 switch (type) {
86 case ETH_P_IP:
87 *buff++ = AX25_P_IP;
88 break;
89 case ETH_P_ARP:
90 *buff++ = AX25_P_ARP;
91 break;
92 default:
93 printk(KERN_ERR "AX.25: ax25_encapsulate - wrong protocol type 0x%x2.2\n", type);
94 *buff++ = 0;
95 break;
96 }
97
98 if (daddr != NULL)
99 return AX25_HEADER_LEN;
100
101 return -AX25_HEADER_LEN; /* Unfinished header */
102 }
103
104 int ax25_rebuild_header(struct sk_buff *skb)
105 {
106 struct sk_buff *ourskb;
107 unsigned char *bp = skb->data;
108 struct net_device *dev;
109 ax25_address *src, *dst;
110 ax25_route *route;
111 ax25_dev *ax25_dev;
112
113 dst = (ax25_address *)(bp + 1);
114 src = (ax25_address *)(bp + 8);
115
116 if (arp_find(bp + 1, skb))
117 return 1;
118
119 route = ax25_rt_find_route(dst, NULL);
120 dev = route->dev;
121
122 if (dev == NULL)
123 dev = skb->dev;
124
125 if ((ax25_dev = ax25_dev_ax25dev(dev)) == NULL)
126 return 1;
127
128 if (bp[16] == AX25_P_IP) {
129 if (route->ip_mode == 'V' || (route->ip_mode == ' ' && ax25_dev->values[AX25_VALUES_IPDEFMODE])) {
130 /*
131 * We copy the buffer and release the original thereby
132 * keeping it straight
133 *
134 * Note: we report 1 back so the caller will
135 * not feed the frame direct to the physical device
136 * We don't want that to happen. (It won't be upset
137 * as we have pulled the frame from the queue by
138 * freeing it).
139 *
140 * NB: TCP modifies buffers that are still
141 * on a device queue, thus we use skb_copy()
142 * instead of using skb_clone() unless this
143 * gets fixed.
144 */
145
146 ax25_address src_c;
147 ax25_address dst_c;
148
149 if ((ourskb = skb_copy(skb, GFP_ATOMIC)) == NULL) {
150 kfree_skb(skb);
151 return 1;
152 }
153
154 if (skb->sk != NULL)
155 skb_set_owner_w(ourskb, skb->sk);
156
157 kfree_skb(skb);
158
159 src_c = *src;
160 dst_c = *dst;
161
162 skb_pull(ourskb, AX25_HEADER_LEN - 1); /* Keep PID */
163 skb->nh.raw = skb->data;
164
165 ax25_send_frame(ourskb, ax25_dev->values[AX25_VALUES_PACLEN], &src_c,
166 &dst_c, route->digipeat, dev);
167
168 return 1;
169 }
170 }
171
172 bp[7] &= ~AX25_CBIT;
173 bp[7] &= ~AX25_EBIT;
174 bp[7] |= AX25_SSSID_SPARE;
175
176 bp[14] &= ~AX25_CBIT;
177 bp[14] |= AX25_EBIT;
178 bp[14] |= AX25_SSSID_SPARE;
179
180 skb_pull(skb, AX25_KISS_HEADER_LEN);
181
182 if (route->digipeat != NULL) {
183 if ((ourskb = ax25_rt_build_path(skb, src, dst, route->digipeat)) == NULL) {
184 kfree_skb(skb);
185 return 1;
186 }
187
188 skb = ourskb;
189 }
190
191 skb->dev = dev;
192
193 ax25_queue_xmit(skb);
194
195 return 1;
196 }
197
198 #else /* INET */
199
200 int ax25_encapsulate(struct sk_buff *skb, struct net_device *dev, unsigned short type, void *daddr, void *saddr, unsigned len)
201 {
202 return -AX25_HEADER_LEN;
203 }
204
205 int ax25_rebuild_header(struct sk_buff *skb)
206 {
207 return 1;
208 }
209
210 #endif
211
212
This page was automatically generated by the
LXR engine.
Visit the LXR main site for more
information.