Split 'flush_old_exec' into two functions
[linux-2.6/linux-2.6-openrd.git] / net / rose / rose_link.c
blob5ef5f6988a2e1aa892539e0c7c53364d7f796808
1 /*
2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License as published by
4 * the Free Software Foundation; either version 2 of the License, or
5 * (at your option) any later version.
7 * Copyright (C) Jonathan Naylor G4KLX (g4klx@g4klx.demon.co.uk)
8 */
9 #include <linux/errno.h>
10 #include <linux/types.h>
11 #include <linux/socket.h>
12 #include <linux/in.h>
13 #include <linux/kernel.h>
14 #include <linux/jiffies.h>
15 #include <linux/timer.h>
16 #include <linux/string.h>
17 #include <linux/sockios.h>
18 #include <linux/net.h>
19 #include <net/ax25.h>
20 #include <linux/inet.h>
21 #include <linux/netdevice.h>
22 #include <linux/skbuff.h>
23 #include <net/sock.h>
24 #include <asm/system.h>
25 #include <linux/fcntl.h>
26 #include <linux/mm.h>
27 #include <linux/interrupt.h>
28 #include <linux/netfilter.h>
29 #include <net/rose.h>
31 static void rose_ftimer_expiry(unsigned long);
32 static void rose_t0timer_expiry(unsigned long);
34 static void rose_transmit_restart_confirmation(struct rose_neigh *neigh);
35 static void rose_transmit_restart_request(struct rose_neigh *neigh);
37 void rose_start_ftimer(struct rose_neigh *neigh)
39 del_timer(&neigh->ftimer);
41 neigh->ftimer.data = (unsigned long)neigh;
42 neigh->ftimer.function = &rose_ftimer_expiry;
43 neigh->ftimer.expires =
44 jiffies + msecs_to_jiffies(sysctl_rose_link_fail_timeout);
46 add_timer(&neigh->ftimer);
49 static void rose_start_t0timer(struct rose_neigh *neigh)
51 del_timer(&neigh->t0timer);
53 neigh->t0timer.data = (unsigned long)neigh;
54 neigh->t0timer.function = &rose_t0timer_expiry;
55 neigh->t0timer.expires =
56 jiffies + msecs_to_jiffies(sysctl_rose_restart_request_timeout);
58 add_timer(&neigh->t0timer);
61 void rose_stop_ftimer(struct rose_neigh *neigh)
63 del_timer(&neigh->ftimer);
66 void rose_stop_t0timer(struct rose_neigh *neigh)
68 del_timer(&neigh->t0timer);
71 int rose_ftimer_running(struct rose_neigh *neigh)
73 return timer_pending(&neigh->ftimer);
76 static int rose_t0timer_running(struct rose_neigh *neigh)
78 return timer_pending(&neigh->t0timer);
81 static void rose_ftimer_expiry(unsigned long param)
85 static void rose_t0timer_expiry(unsigned long param)
87 struct rose_neigh *neigh = (struct rose_neigh *)param;
89 rose_transmit_restart_request(neigh);
91 neigh->dce_mode = 0;
93 rose_start_t0timer(neigh);
97 * Interface to ax25_send_frame. Changes my level 2 callsign depending
98 * on whether we have a global ROSE callsign or use the default port
99 * callsign.
101 static int rose_send_frame(struct sk_buff *skb, struct rose_neigh *neigh)
103 ax25_address *rose_call;
104 ax25_cb *ax25s;
106 if (ax25cmp(&rose_callsign, &null_ax25_address) == 0)
107 rose_call = (ax25_address *)neigh->dev->dev_addr;
108 else
109 rose_call = &rose_callsign;
111 ax25s = neigh->ax25;
112 neigh->ax25 = ax25_send_frame(skb, 260, rose_call, &neigh->callsign, neigh->digipeat, neigh->dev);
113 if (ax25s)
114 ax25_cb_put(ax25s);
116 return (neigh->ax25 != NULL);
120 * Interface to ax25_link_up. Changes my level 2 callsign depending
121 * on whether we have a global ROSE callsign or use the default port
122 * callsign.
124 static int rose_link_up(struct rose_neigh *neigh)
126 ax25_address *rose_call;
127 ax25_cb *ax25s;
129 if (ax25cmp(&rose_callsign, &null_ax25_address) == 0)
130 rose_call = (ax25_address *)neigh->dev->dev_addr;
131 else
132 rose_call = &rose_callsign;
134 ax25s = neigh->ax25;
135 neigh->ax25 = ax25_find_cb(rose_call, &neigh->callsign, neigh->digipeat, neigh->dev);
136 if (ax25s)
137 ax25_cb_put(ax25s);
139 return (neigh->ax25 != NULL);
143 * This handles all restart and diagnostic frames.
145 void rose_link_rx_restart(struct sk_buff *skb, struct rose_neigh *neigh, unsigned short frametype)
147 struct sk_buff *skbn;
149 switch (frametype) {
150 case ROSE_RESTART_REQUEST:
151 rose_stop_t0timer(neigh);
152 neigh->restarted = 1;
153 neigh->dce_mode = (skb->data[3] == ROSE_DTE_ORIGINATED);
154 rose_transmit_restart_confirmation(neigh);
155 break;
157 case ROSE_RESTART_CONFIRMATION:
158 rose_stop_t0timer(neigh);
159 neigh->restarted = 1;
160 break;
162 case ROSE_DIAGNOSTIC:
163 printk(KERN_WARNING "ROSE: received diagnostic #%d - %02X %02X %02X\n", skb->data[3], skb->data[4], skb->data[5], skb->data[6]);
164 break;
166 default:
167 printk(KERN_WARNING "ROSE: received unknown %02X with LCI 000\n", frametype);
168 break;
171 if (neigh->restarted) {
172 while ((skbn = skb_dequeue(&neigh->queue)) != NULL)
173 if (!rose_send_frame(skbn, neigh))
174 kfree_skb(skbn);
179 * This routine is called when a Restart Request is needed
181 static void rose_transmit_restart_request(struct rose_neigh *neigh)
183 struct sk_buff *skb;
184 unsigned char *dptr;
185 int len;
187 len = AX25_BPQ_HEADER_LEN + AX25_MAX_HEADER_LEN + ROSE_MIN_LEN + 3;
189 if ((skb = alloc_skb(len, GFP_ATOMIC)) == NULL)
190 return;
192 skb_reserve(skb, AX25_BPQ_HEADER_LEN + AX25_MAX_HEADER_LEN);
194 dptr = skb_put(skb, ROSE_MIN_LEN + 3);
196 *dptr++ = AX25_P_ROSE;
197 *dptr++ = ROSE_GFI;
198 *dptr++ = 0x00;
199 *dptr++ = ROSE_RESTART_REQUEST;
200 *dptr++ = ROSE_DTE_ORIGINATED;
201 *dptr++ = 0;
203 if (!rose_send_frame(skb, neigh))
204 kfree_skb(skb);
208 * This routine is called when a Restart Confirmation is needed
210 static void rose_transmit_restart_confirmation(struct rose_neigh *neigh)
212 struct sk_buff *skb;
213 unsigned char *dptr;
214 int len;
216 len = AX25_BPQ_HEADER_LEN + AX25_MAX_HEADER_LEN + ROSE_MIN_LEN + 1;
218 if ((skb = alloc_skb(len, GFP_ATOMIC)) == NULL)
219 return;
221 skb_reserve(skb, AX25_BPQ_HEADER_LEN + AX25_MAX_HEADER_LEN);
223 dptr = skb_put(skb, ROSE_MIN_LEN + 1);
225 *dptr++ = AX25_P_ROSE;
226 *dptr++ = ROSE_GFI;
227 *dptr++ = 0x00;
228 *dptr++ = ROSE_RESTART_CONFIRMATION;
230 if (!rose_send_frame(skb, neigh))
231 kfree_skb(skb);
235 * This routine is called when a Clear Request is needed outside of the context
236 * of a connected socket.
238 void rose_transmit_clear_request(struct rose_neigh *neigh, unsigned int lci, unsigned char cause, unsigned char diagnostic)
240 struct sk_buff *skb;
241 unsigned char *dptr;
242 int len;
244 len = AX25_BPQ_HEADER_LEN + AX25_MAX_HEADER_LEN + ROSE_MIN_LEN + 3;
246 if ((skb = alloc_skb(len, GFP_ATOMIC)) == NULL)
247 return;
249 skb_reserve(skb, AX25_BPQ_HEADER_LEN + AX25_MAX_HEADER_LEN);
251 dptr = skb_put(skb, ROSE_MIN_LEN + 3);
253 *dptr++ = AX25_P_ROSE;
254 *dptr++ = ((lci >> 8) & 0x0F) | ROSE_GFI;
255 *dptr++ = ((lci >> 0) & 0xFF);
256 *dptr++ = ROSE_CLEAR_REQUEST;
257 *dptr++ = cause;
258 *dptr++ = diagnostic;
260 if (!rose_send_frame(skb, neigh))
261 kfree_skb(skb);
264 void rose_transmit_link(struct sk_buff *skb, struct rose_neigh *neigh)
266 unsigned char *dptr;
268 #if 0
269 if (call_fw_firewall(PF_ROSE, skb->dev, skb->data, NULL, &skb) != FW_ACCEPT) {
270 kfree_skb(skb);
271 return;
273 #endif
275 if (neigh->loopback) {
276 rose_loopback_queue(skb, neigh);
277 return;
280 if (!rose_link_up(neigh))
281 neigh->restarted = 0;
283 dptr = skb_push(skb, 1);
284 *dptr++ = AX25_P_ROSE;
286 if (neigh->restarted) {
287 if (!rose_send_frame(skb, neigh))
288 kfree_skb(skb);
289 } else {
290 skb_queue_tail(&neigh->queue, skb);
292 if (!rose_t0timer_running(neigh)) {
293 rose_transmit_restart_request(neigh);
294 neigh->dce_mode = 0;
295 rose_start_t0timer(neigh);