Blame view
net/ax25/ax25_ip.c
5.22 KB
1da177e4c Linux-2.6.12-rc2 |
1 2 3 4 5 6 7 8 |
/* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * Copyright (C) Jonathan Naylor G4KLX (g4klx@g4klx.demon.co.uk) */ |
1da177e4c Linux-2.6.12-rc2 |
9 10 11 12 13 |
#include <linux/errno.h> #include <linux/types.h> #include <linux/socket.h> #include <linux/in.h> #include <linux/kernel.h> |
70868eace [AX.25]: Move AX.... |
14 |
#include <linux/module.h> |
1da177e4c Linux-2.6.12-rc2 |
15 16 17 18 |
#include <linux/timer.h> #include <linux/string.h> #include <linux/sockios.h> #include <linux/net.h> |
5a0e3ad6a include cleanup: ... |
19 |
#include <linux/slab.h> |
1da177e4c Linux-2.6.12-rc2 |
20 21 22 23 24 25 26 |
#include <net/ax25.h> #include <linux/inet.h> #include <linux/netdevice.h> #include <linux/if_arp.h> #include <linux/skbuff.h> #include <net/sock.h> #include <asm/uaccess.h> |
1da177e4c Linux-2.6.12-rc2 |
27 28 29 30 31 32 33 |
#include <linux/fcntl.h> #include <linux/termios.h> /* For TIOCINQ/OUTQ */ #include <linux/mm.h> #include <linux/interrupt.h> #include <linux/notifier.h> #include <linux/proc_fs.h> #include <linux/stat.h> |
1da177e4c Linux-2.6.12-rc2 |
34 35 36 37 38 39 40 41 42 43 44 45 46 |
#include <linux/sysctl.h> #include <net/ip.h> #include <net/arp.h> /* * IP over AX.25 encapsulation. */ /* * Shove an AX.25 UI header on an IP packet and handle ARP */ #ifdef CONFIG_INET |
46d4e47ab ax25: Make ax25_h... |
47 48 49 |
static int ax25_hard_header(struct sk_buff *skb, struct net_device *dev, unsigned short type, const void *daddr, const void *saddr, unsigned int len) |
1da177e4c Linux-2.6.12-rc2 |
50 51 52 53 54 55 |
{ unsigned char *buff; /* they sometimes come back to us... */ if (type == ETH_P_AX25) return 0; |
528930b91 [NET] AX25: Fix w... |
56 57 58 |
/* header is an AX.25 UI frame from us to them */ buff = skb_push(skb, AX25_HEADER_LEN); *buff++ = 0x00; /* KISS DATA */ |
1da177e4c Linux-2.6.12-rc2 |
59 60 61 |
if (daddr != NULL) memcpy(buff, daddr, dev->addr_len); /* Address specified */ |
528930b91 [NET] AX25: Fix w... |
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
buff[6] &= ~AX25_CBIT; buff[6] &= ~AX25_EBIT; buff[6] |= AX25_SSSID_SPARE; buff += AX25_ADDR_LEN; if (saddr != NULL) memcpy(buff, saddr, dev->addr_len); else memcpy(buff, dev->dev_addr, dev->addr_len); buff[6] &= ~AX25_CBIT; buff[6] |= AX25_EBIT; buff[6] |= AX25_SSSID_SPARE; buff += AX25_ADDR_LEN; *buff++ = AX25_UI; /* UI */ /* Append a suitable AX.25 PID */ switch (type) { case ETH_P_IP: *buff++ = AX25_P_IP; break; case ETH_P_ARP: *buff++ = AX25_P_ARP; break; default: printk(KERN_ERR "AX.25: ax25_hard_header - wrong protocol type 0x%2.2x ", type); *buff++ = 0; break; } |
1da177e4c Linux-2.6.12-rc2 |
93 94 |
if (daddr != NULL) |
528930b91 [NET] AX25: Fix w... |
95 |
return AX25_HEADER_LEN; |
1da177e4c Linux-2.6.12-rc2 |
96 97 98 |
return -AX25_HEADER_LEN; /* Unfinished header */ } |
1d5da757d ax25: Stop using ... |
99 |
netdev_tx_t ax25_ip_xmit(struct sk_buff *skb) |
1da177e4c Linux-2.6.12-rc2 |
100 101 102 |
{ struct sk_buff *ourskb; unsigned char *bp = skb->data; |
006f68b84 [AX.25]: Referenc... |
103 104 |
ax25_route *route; struct net_device *dev = NULL; |
1da177e4c Linux-2.6.12-rc2 |
105 |
ax25_address *src, *dst; |
006f68b84 [AX.25]: Referenc... |
106 |
ax25_digi *digipeat = NULL; |
1da177e4c Linux-2.6.12-rc2 |
107 |
ax25_dev *ax25_dev; |
1da177e4c Linux-2.6.12-rc2 |
108 |
ax25_cb *ax25; |
006f68b84 [AX.25]: Referenc... |
109 |
char ip_mode = ' '; |
1da177e4c Linux-2.6.12-rc2 |
110 111 112 |
dst = (ax25_address *)(bp + 1); src = (ax25_address *)(bp + 8); |
006f68b84 [AX.25]: Referenc... |
113 114 115 116 117 |
route = ax25_get_route(dst, NULL); if (route) { digipeat = route->digipeat; dev = route->dev; ip_mode = route->ip_mode; |
3ff50b799 [NET]: cleanup ex... |
118 |
} |
1da177e4c Linux-2.6.12-rc2 |
119 120 121 |
if (dev == NULL) dev = skb->dev; |
528930b91 [NET] AX25: Fix w... |
122 |
if ((ax25_dev = ax25_dev_ax25dev(dev)) == NULL) { |
e18dbd059 ax25: In ax25_reb... |
123 |
kfree_skb(skb); |
528930b91 [NET] AX25: Fix w... |
124 |
goto put; |
1da177e4c Linux-2.6.12-rc2 |
125 126 127 |
} if (bp[16] == AX25_P_IP) { |
006f68b84 [AX.25]: Referenc... |
128 |
if (ip_mode == 'V' || (ip_mode == ' ' && ax25_dev->values[AX25_VALUES_IPDEFMODE])) { |
1da177e4c Linux-2.6.12-rc2 |
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 |
/* * We copy the buffer and release the original thereby * keeping it straight * * Note: we report 1 back so the caller will * not feed the frame direct to the physical device * We don't want that to happen. (It won't be upset * as we have pulled the frame from the queue by * freeing it). * * NB: TCP modifies buffers that are still * on a device queue, thus we use skb_copy() * instead of using skb_clone() unless this * gets fixed. */ ax25_address src_c; ax25_address dst_c; if ((ourskb = skb_copy(skb, GFP_ATOMIC)) == NULL) { kfree_skb(skb); goto put; } if (skb->sk != NULL) skb_set_owner_w(ourskb, skb->sk); kfree_skb(skb); /* dl9sau: bugfix * after kfree_skb(), dst and src which were pointer * to bp which is part of skb->data would not be valid * anymore hope that after skb_pull(ourskb, ..) our * dsc_c and src_c will not become invalid */ bp = ourskb->data; dst_c = *(ax25_address *)(bp + 1); src_c = *(ax25_address *)(bp + 8); skb_pull(ourskb, AX25_HEADER_LEN - 1); /* Keep PID */ |
c1d2bbe1c [SK_BUFF]: Introd... |
168 |
skb_reset_network_header(ourskb); |
1da177e4c Linux-2.6.12-rc2 |
169 170 |
ax25=ax25_send_frame( |
528930b91 [NET] AX25: Fix w... |
171 172 |
ourskb, ax25_dev->values[AX25_VALUES_PACLEN], |
1da177e4c Linux-2.6.12-rc2 |
173 |
&src_c, |
006f68b84 [AX.25]: Referenc... |
174 |
&dst_c, digipeat, dev); |
1da177e4c Linux-2.6.12-rc2 |
175 176 177 178 179 180 |
if (ax25) { ax25_cb_put(ax25); } goto put; } } |
528930b91 [NET] AX25: Fix w... |
181 182 183 |
bp[7] &= ~AX25_CBIT; bp[7] &= ~AX25_EBIT; bp[7] |= AX25_SSSID_SPARE; |
1da177e4c Linux-2.6.12-rc2 |
184 |
|
528930b91 [NET] AX25: Fix w... |
185 186 187 |
bp[14] &= ~AX25_CBIT; bp[14] |= AX25_EBIT; bp[14] |= AX25_SSSID_SPARE; |
1da177e4c Linux-2.6.12-rc2 |
188 189 |
skb_pull(skb, AX25_KISS_HEADER_LEN); |
006f68b84 [AX.25]: Referenc... |
190 |
if (digipeat != NULL) { |
1da177e4c Linux-2.6.12-rc2 |
191 192 193 194 195 196 197 |
if ((ourskb = ax25_rt_build_path(skb, src, dst, route->digipeat)) == NULL) { kfree_skb(skb); goto put; } skb = ourskb; } |
29c4be51e [AX25]: make ax25... |
198 |
ax25_queue_xmit(skb, dev); |
1da177e4c Linux-2.6.12-rc2 |
199 200 |
put: |
006f68b84 [AX.25]: Referenc... |
201 202 |
if (route) ax25_put_route(route); |
1da177e4c Linux-2.6.12-rc2 |
203 |
|
1d5da757d ax25: Stop using ... |
204 |
return NETDEV_TX_OK; |
3b6a94bed ax25: Refactor to... |
205 |
} |
1da177e4c Linux-2.6.12-rc2 |
206 |
#else /* INET */ |
46d4e47ab ax25: Make ax25_h... |
207 208 209 |
static int ax25_hard_header(struct sk_buff *skb, struct net_device *dev, unsigned short type, const void *daddr, const void *saddr, unsigned int len) |
1da177e4c Linux-2.6.12-rc2 |
210 211 212 |
{ return -AX25_HEADER_LEN; } |
787fb2bd4 ax25: Fix the bui... |
213 |
netdev_tx_t ax25_ip_xmit(struct sk_buff *skb) |
3b6a94bed ax25: Refactor to... |
214 |
{ |
1d5da757d ax25: Stop using ... |
215 216 |
kfree_skb(skb); return NETDEV_TX_OK; |
3b6a94bed ax25: Refactor to... |
217 |
} |
1da177e4c Linux-2.6.12-rc2 |
218 |
#endif |
3b04ddde0 [NET]: Move hardw... |
219 220 |
const struct header_ops ax25_header_ops = { .create = ax25_hard_header, |
3b04ddde0 [NET]: Move hardw... |
221 |
}; |
3b04ddde0 [NET]: Move hardw... |
222 |
EXPORT_SYMBOL(ax25_header_ops); |
1d5da757d ax25: Stop using ... |
223 |
EXPORT_SYMBOL(ax25_ip_xmit); |
3b04ddde0 [NET]: Move hardw... |
224 |