Loading...
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 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 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 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 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 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 | /* * X.25 Packet Layer release 001 * * This is ALPHA test software. This code may break your machine, randomly fail to work with new * releases, misbehave and/or generally screw up. It might even work. * * This code REQUIRES 2.1.15 or higher * * This module: * This module 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. * * History * X.25 001 Jonathan Naylor Started coding. */ #include <linux/config.h> #if defined(CONFIG_X25) || defined(CONFIG_X25_MODULE) #include <linux/errno.h> #include <linux/types.h> #include <linux/socket.h> #include <linux/in.h> #include <linux/kernel.h> #include <linux/sched.h> #include <linux/timer.h> #include <linux/string.h> #include <linux/sockios.h> #include <linux/net.h> #include <linux/stat.h> #include <linux/inet.h> #include <linux/netdevice.h> #include <linux/if_arp.h> #include <linux/skbuff.h> #include <net/sock.h> #include <asm/segment.h> #include <asm/system.h> #include <asm/uaccess.h> #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/if_arp.h> #include <linux/firewall.h> #include <net/x25.h> static int x25_receive_data(struct sk_buff *skb, struct x25_neigh *neigh) { struct sock *sk; unsigned short frametype; unsigned int lci; #ifdef CONFIG_FIREWALL if (call_in_firewall(PF_X25, skb->dev, skb->data, NULL) != FW_ACCEPT) { kfree_skb(skb, FREE_READ); return 0; } #endif frametype = skb->data[2]; lci = ((skb->data[0] << 8) & 0xF00) + ((skb->data[1] << 0) & 0x0FF); /* * LCI of zero is always for us, and its always a link control * frame. */ if (lci == 0) { x25_link_control(skb, neigh, frametype); return 0; } /* * Find an existing socket. */ if ((sk = x25_find_socket(lci)) != NULL) { skb->h.raw = skb->data; return x25_process_rx_frame(sk, skb); } /* * Is is a Call Request ? if so process it. */ if (frametype == X25_CALL_REQUEST) return x25_rx_call_request(skb, neigh, lci); /* * Its not a Call Request, nor is it a control frame, throw it awa */ /* x25_transmit_clear_request(neigh, lci, 0x0D); */ kfree_skb(skb, FREE_READ); return 0; } int x25_lapb_receive_frame(struct sk_buff *skb, struct device *dev, struct packet_type *ptype) { struct x25_neigh *neigh; skb->sk = NULL; /* * Packet received from unrecognised device, throw it away. */ if ((neigh = x25_get_neigh(dev)) == NULL) { printk(KERN_DEBUG "X.25: unknown neighbour - %s\n", dev->name); kfree_skb(skb, FREE_READ); return 0; } switch (skb->data[0]) { case 0x00: skb_pull(skb, 1); return x25_receive_data(skb, neigh); case 0x01: x25_link_established(neigh); kfree_skb(skb, FREE_READ); return 0; case 0x02: x25_link_terminated(neigh); kfree_skb(skb, FREE_READ); return 0; case 0x03: kfree_skb(skb, FREE_READ); return 0; default: kfree_skb(skb, FREE_READ); return 0; } } int x25_llc_receive_frame(struct sk_buff *skb, struct device *dev, struct packet_type *ptype) { struct x25_neigh *neigh; skb->sk = NULL; /* * Packet received from unrecognised device, throw it away. */ if ((neigh = x25_get_neigh(dev)) == NULL) { printk(KERN_DEBUG "X.25: unknown_neighbour - %s\n", dev->name); kfree_skb(skb, FREE_READ); return 0; } return x25_receive_data(skb, neigh); } void x25_establish_link(struct x25_neigh *neigh) { struct sk_buff *skb; unsigned char *ptr; switch (neigh->dev->type) { case ARPHRD_X25: if ((skb = alloc_skb(1, GFP_ATOMIC)) == NULL) { printk(KERN_ERR "x25_dev: out of memory\n"); return; } ptr = skb_put(skb, 1); *ptr = 0x01; break; #if defined(CONFIG_LLC) || defined(CONFIG_LLC_MODULE) case ARPHRD_ETHER: return; #endif default: return; } skb->protocol = htons(ETH_P_X25); skb->priority = SOPRI_NORMAL; skb->dev = neigh->dev; skb->arp = 1; dev_queue_xmit(skb); } void x25_terminate_link(struct x25_neigh *neigh) { struct sk_buff *skb; unsigned char *ptr; switch (neigh->dev->type) { case ARPHRD_X25: if ((skb = alloc_skb(1, GFP_ATOMIC)) == NULL) { printk(KERN_ERR "x25_dev: out of memory\n"); return; } ptr = skb_put(skb, 1); *ptr = 0x02; break; #if defined(CONFIG_LLC) || defined(CONFIG_LLC_MODULE) case ARPHRD_ETHER: return; #endif default: return; } skb->protocol = htons(ETH_P_X25); skb->priority = SOPRI_NORMAL; skb->dev = neigh->dev; skb->arp = 1; dev_queue_xmit(skb); } void x25_send_frame(struct sk_buff *skb, struct x25_neigh *neigh) { unsigned char *dptr; switch (neigh->dev->type) { case ARPHRD_X25: dptr = skb_push(skb, 1); *dptr = 0x00; break; #if defined(CONFIG_LLC) || defined(CONFIG_LLC_MODULE) case ARPHRD_ETHER: kfree_skb(skb, FREE_WRITE); return; #endif default: kfree_skb(skb, FREE_WRITE); return; } skb->protocol = htons(ETH_P_X25); skb->priority = SOPRI_NORMAL; skb->dev = neigh->dev; skb->arp = 1; dev_queue_xmit(skb); } #endif |