1 // SPDX-License-Identifier: GPL-2.0-or-later 1 // SPDX-License-Identifier: GPL-2.0-or-later 2 /* net/atm/pppoatm.c - RFC2364 PPP over ATM/AA 2 /* net/atm/pppoatm.c - RFC2364 PPP over ATM/AAL5 */ 3 3 4 /* Copyright 1999-2000 by Mitchell Blank Jr */ 4 /* Copyright 1999-2000 by Mitchell Blank Jr */ 5 /* Based on clip.c; 1995-1999 by Werner Almesb 5 /* Based on clip.c; 1995-1999 by Werner Almesberger, EPFL LRC/ICA */ 6 /* And on ppp_async.c; Copyright 1999 Paul Mac 6 /* And on ppp_async.c; Copyright 1999 Paul Mackerras */ 7 /* And help from Jens Axboe */ 7 /* And help from Jens Axboe */ 8 8 9 /* 9 /* 10 * 10 * 11 * This driver provides the encapsulation and 11 * This driver provides the encapsulation and framing for sending 12 * and receiving PPP frames in ATM AAL5 PDUs. 12 * and receiving PPP frames in ATM AAL5 PDUs. 13 */ 13 */ 14 14 15 /* 15 /* 16 * One shortcoming of this driver is that it d 16 * One shortcoming of this driver is that it does not comply with 17 * section 8 of RFC2364 - we are supposed to d 17 * section 8 of RFC2364 - we are supposed to detect a change 18 * in encapsulation and immediately abort the 18 * in encapsulation and immediately abort the connection (in order 19 * to avoid a black-hole being created if our 19 * to avoid a black-hole being created if our peer loses state 20 * and changes encapsulation unilaterally. Ho 20 * and changes encapsulation unilaterally. However, since the 21 * ppp_generic layer actually does the decapsu 21 * ppp_generic layer actually does the decapsulation, we need 22 * a way of notifying it when we _think_ there 22 * a way of notifying it when we _think_ there might be a problem) 23 * There's two cases: 23 * There's two cases: 24 * 1. LLC-encapsulation was missing when it 24 * 1. LLC-encapsulation was missing when it was enabled. In 25 * this case, we should tell the upper la 25 * this case, we should tell the upper layer "tear down 26 * this session if this skb looks ok to y 26 * this session if this skb looks ok to you" 27 * 2. LLC-encapsulation was present when it 27 * 2. LLC-encapsulation was present when it was disabled. Then 28 * we need to tell the upper layer "this 28 * we need to tell the upper layer "this packet may be 29 * ok, but if its in error tear down the 29 * ok, but if its in error tear down the session" 30 * These hooks are not yet available in ppp_ge 30 * These hooks are not yet available in ppp_generic 31 */ 31 */ 32 32 33 #define pr_fmt(fmt) KBUILD_MODNAME ":%s: " fmt 33 #define pr_fmt(fmt) KBUILD_MODNAME ":%s: " fmt, __func__ 34 34 35 #include <linux/module.h> 35 #include <linux/module.h> 36 #include <linux/init.h> 36 #include <linux/init.h> 37 #include <linux/interrupt.h> 37 #include <linux/interrupt.h> 38 #include <linux/skbuff.h> 38 #include <linux/skbuff.h> 39 #include <linux/slab.h> 39 #include <linux/slab.h> 40 #include <linux/atm.h> 40 #include <linux/atm.h> 41 #include <linux/atmdev.h> 41 #include <linux/atmdev.h> 42 #include <linux/capability.h> 42 #include <linux/capability.h> 43 #include <linux/ppp_defs.h> 43 #include <linux/ppp_defs.h> 44 #include <linux/ppp-ioctl.h> 44 #include <linux/ppp-ioctl.h> 45 #include <linux/ppp_channel.h> 45 #include <linux/ppp_channel.h> 46 #include <linux/atmppp.h> 46 #include <linux/atmppp.h> 47 47 48 #include "common.h" 48 #include "common.h" 49 49 50 enum pppoatm_encaps { 50 enum pppoatm_encaps { 51 e_autodetect = PPPOATM_ENCAPS_AUTODETE 51 e_autodetect = PPPOATM_ENCAPS_AUTODETECT, 52 e_vc = PPPOATM_ENCAPS_VC, 52 e_vc = PPPOATM_ENCAPS_VC, 53 e_llc = PPPOATM_ENCAPS_LLC, 53 e_llc = PPPOATM_ENCAPS_LLC, 54 }; 54 }; 55 55 56 struct pppoatm_vcc { 56 struct pppoatm_vcc { 57 struct atm_vcc *atmvcc; /* VCC 57 struct atm_vcc *atmvcc; /* VCC descriptor */ 58 void (*old_push)(struct atm_vcc *, str 58 void (*old_push)(struct atm_vcc *, struct sk_buff *); 59 void (*old_pop)(struct atm_vcc *, stru 59 void (*old_pop)(struct atm_vcc *, struct sk_buff *); 60 void (*old_release_cb)(struct atm_vcc 60 void (*old_release_cb)(struct atm_vcc *); 61 struct module *old_owner; 61 struct module *old_owner; 62 /* kee 62 /* keep old push/pop for detaching */ 63 enum pppoatm_encaps encaps; 63 enum pppoatm_encaps encaps; 64 atomic_t inflight; 64 atomic_t inflight; 65 unsigned long blocked; 65 unsigned long blocked; 66 int flags; /* SC_ 66 int flags; /* SC_COMP_PROT - compress protocol */ 67 struct ppp_channel chan; /* int 67 struct ppp_channel chan; /* interface to generic ppp layer */ 68 struct tasklet_struct wakeup_tasklet; 68 struct tasklet_struct wakeup_tasklet; 69 }; 69 }; 70 70 71 /* 71 /* 72 * We want to allow two packets in the queue. 72 * We want to allow two packets in the queue. The one that's currently in 73 * flight, and *one* queued up ready for the A 73 * flight, and *one* queued up ready for the ATM device to send immediately 74 * from its TX done IRQ. We want to be able to 74 * from its TX done IRQ. We want to be able to use atomic_inc_not_zero(), so 75 * inflight == -2 represents an empty queue, - 75 * inflight == -2 represents an empty queue, -1 one packet, and zero means 76 * there are two packets in the queue. 76 * there are two packets in the queue. 77 */ 77 */ 78 #define NONE_INFLIGHT -2 78 #define NONE_INFLIGHT -2 79 79 80 #define BLOCKED 0 80 #define BLOCKED 0 81 81 82 /* 82 /* 83 * Header used for LLC Encapsulated PPP (4 byt 83 * Header used for LLC Encapsulated PPP (4 bytes) followed by the LCP protocol 84 * ID (0xC021) used in autodetection 84 * ID (0xC021) used in autodetection 85 */ 85 */ 86 static const unsigned char pppllc[6] = { 0xFE, 86 static const unsigned char pppllc[6] = { 0xFE, 0xFE, 0x03, 0xCF, 0xC0, 0x21 }; 87 #define LLC_LEN (4) 87 #define LLC_LEN (4) 88 88 89 static inline struct pppoatm_vcc *atmvcc_to_pv 89 static inline struct pppoatm_vcc *atmvcc_to_pvcc(const struct atm_vcc *atmvcc) 90 { 90 { 91 return (struct pppoatm_vcc *) (atmvcc- 91 return (struct pppoatm_vcc *) (atmvcc->user_back); 92 } 92 } 93 93 94 static inline struct pppoatm_vcc *chan_to_pvcc 94 static inline struct pppoatm_vcc *chan_to_pvcc(const struct ppp_channel *chan) 95 { 95 { 96 return (struct pppoatm_vcc *) (chan->p 96 return (struct pppoatm_vcc *) (chan->private); 97 } 97 } 98 98 99 /* 99 /* 100 * We can't do this directly from our _pop han 100 * We can't do this directly from our _pop handler, since the ppp code 101 * doesn't want to be called in interrupt cont 101 * doesn't want to be called in interrupt context, so we do it from 102 * a tasklet 102 * a tasklet 103 */ 103 */ 104 static void pppoatm_wakeup_sender(struct taskl 104 static void pppoatm_wakeup_sender(struct tasklet_struct *t) 105 { 105 { 106 struct pppoatm_vcc *pvcc = from_taskle 106 struct pppoatm_vcc *pvcc = from_tasklet(pvcc, t, wakeup_tasklet); 107 107 108 ppp_output_wakeup(&pvcc->chan); 108 ppp_output_wakeup(&pvcc->chan); 109 } 109 } 110 110 111 static void pppoatm_release_cb(struct atm_vcc 111 static void pppoatm_release_cb(struct atm_vcc *atmvcc) 112 { 112 { 113 struct pppoatm_vcc *pvcc = atmvcc_to_p 113 struct pppoatm_vcc *pvcc = atmvcc_to_pvcc(atmvcc); 114 114 115 /* 115 /* 116 * As in pppoatm_pop(), it's safe to c 116 * As in pppoatm_pop(), it's safe to clear the BLOCKED bit here because 117 * the wakeup *can't* race with pppoat 117 * the wakeup *can't* race with pppoatm_send(). They both hold the PPP 118 * channel's ->downl lock. And the pot 118 * channel's ->downl lock. And the potential race with *setting* it, 119 * which leads to the double-check dan 119 * which leads to the double-check dance in pppoatm_may_send(), doesn't 120 * exist here. In the sock_owned_by_us 120 * exist here. In the sock_owned_by_user() case in pppoatm_send(), we 121 * set the BLOCKED bit while the socke 121 * set the BLOCKED bit while the socket is still locked. We know that 122 * ->release_cb() can't be called unti 122 * ->release_cb() can't be called until that's done. 123 */ 123 */ 124 if (test_and_clear_bit(BLOCKED, &pvcc- 124 if (test_and_clear_bit(BLOCKED, &pvcc->blocked)) 125 tasklet_schedule(&pvcc->wakeup 125 tasklet_schedule(&pvcc->wakeup_tasklet); 126 if (pvcc->old_release_cb) 126 if (pvcc->old_release_cb) 127 pvcc->old_release_cb(atmvcc); 127 pvcc->old_release_cb(atmvcc); 128 } 128 } 129 /* 129 /* 130 * This gets called every time the ATM card ha 130 * This gets called every time the ATM card has finished sending our 131 * skb. The ->old_pop will take care up norma 131 * skb. The ->old_pop will take care up normal atm flow control, 132 * but we also need to wake up the device if w 132 * but we also need to wake up the device if we blocked it 133 */ 133 */ 134 static void pppoatm_pop(struct atm_vcc *atmvcc 134 static void pppoatm_pop(struct atm_vcc *atmvcc, struct sk_buff *skb) 135 { 135 { 136 struct pppoatm_vcc *pvcc = atmvcc_to_p 136 struct pppoatm_vcc *pvcc = atmvcc_to_pvcc(atmvcc); 137 137 138 pvcc->old_pop(atmvcc, skb); 138 pvcc->old_pop(atmvcc, skb); 139 atomic_dec(&pvcc->inflight); 139 atomic_dec(&pvcc->inflight); 140 140 141 /* 141 /* 142 * We always used to run the wakeup ta 142 * We always used to run the wakeup tasklet unconditionally here, for 143 * fear of race conditions where we cl 143 * fear of race conditions where we clear the BLOCKED flag just as we 144 * refuse another packet in pppoatm_se 144 * refuse another packet in pppoatm_send(). This was quite inefficient. 145 * 145 * 146 * In fact it's OK. The PPP core will 146 * In fact it's OK. The PPP core will only ever call pppoatm_send() 147 * while holding the channel->downl lo 147 * while holding the channel->downl lock. And ppp_output_wakeup() as 148 * called by the tasklet will *also* g 148 * called by the tasklet will *also* grab that lock. So even if another 149 * CPU is in pppoatm_send() right now, 149 * CPU is in pppoatm_send() right now, the tasklet isn't going to race 150 * with it. The wakeup *will* happen a 150 * with it. The wakeup *will* happen after the other CPU is safely out 151 * of pppoatm_send() again. 151 * of pppoatm_send() again. 152 * 152 * 153 * So if the CPU in pppoatm_send() has 153 * So if the CPU in pppoatm_send() has already set the BLOCKED bit and 154 * it about to return, that's fine. We 154 * it about to return, that's fine. We trigger a wakeup which will 155 * happen later. And if the CPU in ppp 155 * happen later. And if the CPU in pppoatm_send() *hasn't* set the 156 * BLOCKED bit yet, that's fine too be 156 * BLOCKED bit yet, that's fine too because of the double check in 157 * pppoatm_may_send() which is comment 157 * pppoatm_may_send() which is commented there. 158 */ 158 */ 159 if (test_and_clear_bit(BLOCKED, &pvcc- 159 if (test_and_clear_bit(BLOCKED, &pvcc->blocked)) 160 tasklet_schedule(&pvcc->wakeup 160 tasklet_schedule(&pvcc->wakeup_tasklet); 161 } 161 } 162 162 163 /* 163 /* 164 * Unbind from PPP - currently we only do this 164 * Unbind from PPP - currently we only do this when closing the socket, 165 * but we could put this into an ioctl if need 165 * but we could put this into an ioctl if need be 166 */ 166 */ 167 static void pppoatm_unassign_vcc(struct atm_vc 167 static void pppoatm_unassign_vcc(struct atm_vcc *atmvcc) 168 { 168 { 169 struct pppoatm_vcc *pvcc; 169 struct pppoatm_vcc *pvcc; 170 pvcc = atmvcc_to_pvcc(atmvcc); 170 pvcc = atmvcc_to_pvcc(atmvcc); 171 atmvcc->push = pvcc->old_push; 171 atmvcc->push = pvcc->old_push; 172 atmvcc->pop = pvcc->old_pop; 172 atmvcc->pop = pvcc->old_pop; 173 atmvcc->release_cb = pvcc->old_release 173 atmvcc->release_cb = pvcc->old_release_cb; 174 tasklet_kill(&pvcc->wakeup_tasklet); 174 tasklet_kill(&pvcc->wakeup_tasklet); 175 ppp_unregister_channel(&pvcc->chan); 175 ppp_unregister_channel(&pvcc->chan); 176 atmvcc->user_back = NULL; 176 atmvcc->user_back = NULL; 177 kfree(pvcc); 177 kfree(pvcc); 178 } 178 } 179 179 180 /* Called when an AAL5 PDU comes in */ 180 /* Called when an AAL5 PDU comes in */ 181 static void pppoatm_push(struct atm_vcc *atmvc 181 static void pppoatm_push(struct atm_vcc *atmvcc, struct sk_buff *skb) 182 { 182 { 183 struct pppoatm_vcc *pvcc = atmvcc_to_p 183 struct pppoatm_vcc *pvcc = atmvcc_to_pvcc(atmvcc); 184 pr_debug("\n"); 184 pr_debug("\n"); 185 if (skb == NULL) { 185 if (skb == NULL) { /* VCC was closed */ 186 struct module *module; 186 struct module *module; 187 187 188 pr_debug("removing ATMPPP VCC 188 pr_debug("removing ATMPPP VCC %p\n", pvcc); 189 module = pvcc->old_owner; 189 module = pvcc->old_owner; 190 pppoatm_unassign_vcc(atmvcc); 190 pppoatm_unassign_vcc(atmvcc); 191 atmvcc->push(atmvcc, NULL); 191 atmvcc->push(atmvcc, NULL); /* Pass along bad news */ 192 module_put(module); 192 module_put(module); 193 return; 193 return; 194 } 194 } 195 atm_return(atmvcc, skb->truesize); 195 atm_return(atmvcc, skb->truesize); 196 switch (pvcc->encaps) { 196 switch (pvcc->encaps) { 197 case e_llc: 197 case e_llc: 198 if (skb->len < LLC_LEN || 198 if (skb->len < LLC_LEN || 199 memcmp(skb->data, pppllc, 199 memcmp(skb->data, pppllc, LLC_LEN)) 200 goto error; 200 goto error; 201 skb_pull(skb, LLC_LEN); 201 skb_pull(skb, LLC_LEN); 202 break; 202 break; 203 case e_autodetect: 203 case e_autodetect: 204 if (pvcc->chan.ppp == NULL) { 204 if (pvcc->chan.ppp == NULL) { /* Not bound yet! */ 205 kfree_skb(skb); 205 kfree_skb(skb); 206 return; 206 return; 207 } 207 } 208 if (skb->len >= sizeof(pppllc) 208 if (skb->len >= sizeof(pppllc) && 209 !memcmp(skb->data, pppllc, 209 !memcmp(skb->data, pppllc, sizeof(pppllc))) { 210 pvcc->encaps = e_llc; 210 pvcc->encaps = e_llc; 211 skb_pull(skb, LLC_LEN) 211 skb_pull(skb, LLC_LEN); 212 break; 212 break; 213 } 213 } 214 if (skb->len >= (sizeof(pppllc 214 if (skb->len >= (sizeof(pppllc) - LLC_LEN) && 215 !memcmp(skb->data, &pppllc 215 !memcmp(skb->data, &pppllc[LLC_LEN], 216 sizeof(pppllc) - LLC_LEN)) 216 sizeof(pppllc) - LLC_LEN)) { 217 pvcc->encaps = e_vc; 217 pvcc->encaps = e_vc; 218 pvcc->chan.mtu += LLC_ 218 pvcc->chan.mtu += LLC_LEN; 219 break; 219 break; 220 } 220 } 221 pr_debug("Couldn't autodetect 221 pr_debug("Couldn't autodetect yet (skb: %6ph)\n", skb->data); 222 goto error; 222 goto error; 223 case e_vc: 223 case e_vc: 224 break; 224 break; 225 } 225 } 226 ppp_input(&pvcc->chan, skb); 226 ppp_input(&pvcc->chan, skb); 227 return; 227 return; 228 228 229 error: 229 error: 230 kfree_skb(skb); 230 kfree_skb(skb); 231 ppp_input_error(&pvcc->chan, 0); 231 ppp_input_error(&pvcc->chan, 0); 232 } 232 } 233 233 234 static int pppoatm_may_send(struct pppoatm_vcc 234 static int pppoatm_may_send(struct pppoatm_vcc *pvcc, int size) 235 { 235 { 236 /* 236 /* 237 * It's not clear that we need to both 237 * It's not clear that we need to bother with using atm_may_send() 238 * to check we don't exceed sk->sk_snd 238 * to check we don't exceed sk->sk_sndbuf. If userspace sets a 239 * value of sk_sndbuf which is lower t 239 * value of sk_sndbuf which is lower than the MTU, we're going to 240 * block for ever. But the code always 240 * block for ever. But the code always did that before we introduced 241 * the packet count limit, so... 241 * the packet count limit, so... 242 */ 242 */ 243 if (atm_may_send(pvcc->atmvcc, size) & 243 if (atm_may_send(pvcc->atmvcc, size) && 244 atomic_inc_not_zero(&pvcc->infligh 244 atomic_inc_not_zero(&pvcc->inflight)) 245 return 1; 245 return 1; 246 246 247 /* 247 /* 248 * We use test_and_set_bit() rather th 248 * We use test_and_set_bit() rather than set_bit() here because 249 * we need to ensure there's a memory 249 * we need to ensure there's a memory barrier after it. The bit 250 * *must* be set before we do the atom 250 * *must* be set before we do the atomic_inc() on pvcc->inflight. 251 * There's no smp_mb__after_set_bit(), 251 * There's no smp_mb__after_set_bit(), so it's this or abuse 252 * smp_mb__after_atomic(). 252 * smp_mb__after_atomic(). 253 */ 253 */ 254 test_and_set_bit(BLOCKED, &pvcc->block 254 test_and_set_bit(BLOCKED, &pvcc->blocked); 255 255 256 /* 256 /* 257 * We may have raced with pppoatm_pop( 257 * We may have raced with pppoatm_pop(). If it ran for the 258 * last packet in the queue, *just* be 258 * last packet in the queue, *just* before we set the BLOCKED 259 * bit, then it might never run again 259 * bit, then it might never run again and the channel could 260 * remain permanently blocked. Cope wi 260 * remain permanently blocked. Cope with that race by checking 261 * *again*. If it did run in that wind 261 * *again*. If it did run in that window, we'll have space on 262 * the queue now and can return succes 262 * the queue now and can return success. It's harmless to leave 263 * the BLOCKED flag set, since it's on 263 * the BLOCKED flag set, since it's only used as a trigger to 264 * run the wakeup tasklet. Another wak 264 * run the wakeup tasklet. Another wakeup will never hurt. 265 * If pppoatm_pop() is running but has 265 * If pppoatm_pop() is running but hasn't got as far as making 266 * space on the queue yet, then it has 266 * space on the queue yet, then it hasn't checked the BLOCKED 267 * flag yet either, so we're safe in t 267 * flag yet either, so we're safe in that case too. It'll issue 268 * an "immediate" wakeup... where "imm 268 * an "immediate" wakeup... where "immediate" actually involves 269 * taking the PPP channel's ->downl lo 269 * taking the PPP channel's ->downl lock, which is held by the 270 * code path that calls pppoatm_send() 270 * code path that calls pppoatm_send(), and is thus going to 271 * wait for us to finish. 271 * wait for us to finish. 272 */ 272 */ 273 if (atm_may_send(pvcc->atmvcc, size) & 273 if (atm_may_send(pvcc->atmvcc, size) && 274 atomic_inc_not_zero(&pvcc->infligh 274 atomic_inc_not_zero(&pvcc->inflight)) 275 return 1; 275 return 1; 276 276 277 return 0; 277 return 0; 278 } 278 } 279 /* 279 /* 280 * Called by the ppp_generic.c to send a packe 280 * Called by the ppp_generic.c to send a packet - returns true if packet 281 * was accepted. If we return false, then it' 281 * was accepted. If we return false, then it's our job to call 282 * ppp_output_wakeup(chan) when we're feeling 282 * ppp_output_wakeup(chan) when we're feeling more up to it. 283 * Note that in the ENOMEM case (as opposed to 283 * Note that in the ENOMEM case (as opposed to the !atm_may_send case) 284 * we should really drop the packet, but the g 284 * we should really drop the packet, but the generic layer doesn't 285 * support this yet. We just return 'DROP_PAC 285 * support this yet. We just return 'DROP_PACKET' which we actually define 286 * as success, just to be clear what we're rea 286 * as success, just to be clear what we're really doing. 287 */ 287 */ 288 #define DROP_PACKET 1 288 #define DROP_PACKET 1 289 static int pppoatm_send(struct ppp_channel *ch 289 static int pppoatm_send(struct ppp_channel *chan, struct sk_buff *skb) 290 { 290 { 291 struct pppoatm_vcc *pvcc = chan_to_pvc 291 struct pppoatm_vcc *pvcc = chan_to_pvcc(chan); 292 struct atm_vcc *vcc; 292 struct atm_vcc *vcc; 293 int ret; 293 int ret; 294 294 295 ATM_SKB(skb)->vcc = pvcc->atmvcc; 295 ATM_SKB(skb)->vcc = pvcc->atmvcc; 296 pr_debug("(skb=0x%p, vcc=0x%p)\n", skb 296 pr_debug("(skb=0x%p, vcc=0x%p)\n", skb, pvcc->atmvcc); 297 if (skb->data[0] == '\0' && (pvcc->fla 297 if (skb->data[0] == '\0' && (pvcc->flags & SC_COMP_PROT)) 298 (void) skb_pull(skb, 1); 298 (void) skb_pull(skb, 1); 299 299 300 vcc = ATM_SKB(skb)->vcc; 300 vcc = ATM_SKB(skb)->vcc; 301 bh_lock_sock(sk_atm(vcc)); 301 bh_lock_sock(sk_atm(vcc)); 302 if (sock_owned_by_user(sk_atm(vcc))) { 302 if (sock_owned_by_user(sk_atm(vcc))) { 303 /* 303 /* 304 * Needs to happen (and be flu 304 * Needs to happen (and be flushed, hence test_and_) before we unlock 305 * the socket. It needs to be 305 * the socket. It needs to be seen by the time our ->release_cb gets 306 * called. 306 * called. 307 */ 307 */ 308 test_and_set_bit(BLOCKED, &pvc 308 test_and_set_bit(BLOCKED, &pvcc->blocked); 309 goto nospace; 309 goto nospace; 310 } 310 } 311 if (test_bit(ATM_VF_RELEASED, &vcc->fl 311 if (test_bit(ATM_VF_RELEASED, &vcc->flags) || 312 test_bit(ATM_VF_CLOSE, &vcc->flags 312 test_bit(ATM_VF_CLOSE, &vcc->flags) || 313 !test_bit(ATM_VF_READY, &vcc->flag 313 !test_bit(ATM_VF_READY, &vcc->flags)) { 314 bh_unlock_sock(sk_atm(vcc)); 314 bh_unlock_sock(sk_atm(vcc)); 315 kfree_skb(skb); 315 kfree_skb(skb); 316 return DROP_PACKET; 316 return DROP_PACKET; 317 } 317 } 318 318 319 switch (pvcc->encaps) { /* LLC 319 switch (pvcc->encaps) { /* LLC encapsulation needed */ 320 case e_llc: 320 case e_llc: 321 if (skb_headroom(skb) < LLC_LE 321 if (skb_headroom(skb) < LLC_LEN) { 322 struct sk_buff *n; 322 struct sk_buff *n; 323 n = skb_realloc_headro 323 n = skb_realloc_headroom(skb, LLC_LEN); 324 if (n != NULL && 324 if (n != NULL && 325 !pppoatm_may_send( 325 !pppoatm_may_send(pvcc, n->truesize)) { 326 kfree_skb(n); 326 kfree_skb(n); 327 goto nospace; 327 goto nospace; 328 } 328 } 329 consume_skb(skb); 329 consume_skb(skb); 330 skb = n; 330 skb = n; 331 if (skb == NULL) { 331 if (skb == NULL) { 332 bh_unlock_sock 332 bh_unlock_sock(sk_atm(vcc)); 333 return DROP_PA 333 return DROP_PACKET; 334 } 334 } 335 } else if (!pppoatm_may_send(p 335 } else if (!pppoatm_may_send(pvcc, skb->truesize)) 336 goto nospace; 336 goto nospace; 337 memcpy(skb_push(skb, LLC_LEN), 337 memcpy(skb_push(skb, LLC_LEN), pppllc, LLC_LEN); 338 break; 338 break; 339 case e_vc: 339 case e_vc: 340 if (!pppoatm_may_send(pvcc, sk 340 if (!pppoatm_may_send(pvcc, skb->truesize)) 341 goto nospace; 341 goto nospace; 342 break; 342 break; 343 case e_autodetect: 343 case e_autodetect: 344 bh_unlock_sock(sk_atm(vcc)); 344 bh_unlock_sock(sk_atm(vcc)); 345 pr_debug("Trying to send witho 345 pr_debug("Trying to send without setting encaps!\n"); 346 kfree_skb(skb); 346 kfree_skb(skb); 347 return 1; 347 return 1; 348 } 348 } 349 349 350 atm_account_tx(vcc, skb); 350 atm_account_tx(vcc, skb); 351 pr_debug("atm_skb(%p)->vcc(%p)->dev(%p 351 pr_debug("atm_skb(%p)->vcc(%p)->dev(%p)\n", 352 skb, ATM_SKB(skb)->vcc, ATM_S 352 skb, ATM_SKB(skb)->vcc, ATM_SKB(skb)->vcc->dev); 353 ret = ATM_SKB(skb)->vcc->send(ATM_SKB( 353 ret = ATM_SKB(skb)->vcc->send(ATM_SKB(skb)->vcc, skb) 354 ? DROP_PACKET : 1; 354 ? DROP_PACKET : 1; 355 bh_unlock_sock(sk_atm(vcc)); 355 bh_unlock_sock(sk_atm(vcc)); 356 return ret; 356 return ret; 357 nospace: 357 nospace: 358 bh_unlock_sock(sk_atm(vcc)); 358 bh_unlock_sock(sk_atm(vcc)); 359 /* 359 /* 360 * We don't have space to send this SK 360 * We don't have space to send this SKB now, but we might have 361 * already applied SC_COMP_PROT compre 361 * already applied SC_COMP_PROT compression, so may need to undo 362 */ 362 */ 363 if ((pvcc->flags & SC_COMP_PROT) && sk 363 if ((pvcc->flags & SC_COMP_PROT) && skb_headroom(skb) > 0 && 364 skb->data[-1] == '\0') 364 skb->data[-1] == '\0') 365 (void) skb_push(skb, 1); 365 (void) skb_push(skb, 1); 366 return 0; 366 return 0; 367 } 367 } 368 368 369 /* This handles ioctls sent to the /dev/ppp in 369 /* This handles ioctls sent to the /dev/ppp interface */ 370 static int pppoatm_devppp_ioctl(struct ppp_cha 370 static int pppoatm_devppp_ioctl(struct ppp_channel *chan, unsigned int cmd, 371 unsigned long arg) 371 unsigned long arg) 372 { 372 { 373 switch (cmd) { 373 switch (cmd) { 374 case PPPIOCGFLAGS: 374 case PPPIOCGFLAGS: 375 return put_user(chan_to_pvcc(c 375 return put_user(chan_to_pvcc(chan)->flags, (int __user *) arg) 376 ? -EFAULT : 0; 376 ? -EFAULT : 0; 377 case PPPIOCSFLAGS: 377 case PPPIOCSFLAGS: 378 return get_user(chan_to_pvcc(c 378 return get_user(chan_to_pvcc(chan)->flags, (int __user *) arg) 379 ? -EFAULT : 0; 379 ? -EFAULT : 0; 380 } 380 } 381 return -ENOTTY; 381 return -ENOTTY; 382 } 382 } 383 383 384 static const struct ppp_channel_ops pppoatm_op 384 static const struct ppp_channel_ops pppoatm_ops = { 385 .start_xmit = pppoatm_send, 385 .start_xmit = pppoatm_send, 386 .ioctl = pppoatm_devppp_ioctl, 386 .ioctl = pppoatm_devppp_ioctl, 387 }; 387 }; 388 388 389 static int pppoatm_assign_vcc(struct atm_vcc * 389 static int pppoatm_assign_vcc(struct atm_vcc *atmvcc, void __user *arg) 390 { 390 { 391 struct atm_backend_ppp be; 391 struct atm_backend_ppp be; 392 struct pppoatm_vcc *pvcc; 392 struct pppoatm_vcc *pvcc; 393 int err; 393 int err; 394 394 395 if (copy_from_user(&be, arg, sizeof be 395 if (copy_from_user(&be, arg, sizeof be)) 396 return -EFAULT; 396 return -EFAULT; 397 if (be.encaps != PPPOATM_ENCAPS_AUTODE 397 if (be.encaps != PPPOATM_ENCAPS_AUTODETECT && 398 be.encaps != PPPOATM_ENCAPS_VC && 398 be.encaps != PPPOATM_ENCAPS_VC && be.encaps != PPPOATM_ENCAPS_LLC) 399 return -EINVAL; 399 return -EINVAL; 400 pvcc = kzalloc(sizeof(*pvcc), GFP_KERN 400 pvcc = kzalloc(sizeof(*pvcc), GFP_KERNEL); 401 if (pvcc == NULL) 401 if (pvcc == NULL) 402 return -ENOMEM; 402 return -ENOMEM; 403 pvcc->atmvcc = atmvcc; 403 pvcc->atmvcc = atmvcc; 404 404 405 /* Maximum is zero, so that we can use 405 /* Maximum is zero, so that we can use atomic_inc_not_zero() */ 406 atomic_set(&pvcc->inflight, NONE_INFLI 406 atomic_set(&pvcc->inflight, NONE_INFLIGHT); 407 pvcc->old_push = atmvcc->push; 407 pvcc->old_push = atmvcc->push; 408 pvcc->old_pop = atmvcc->pop; 408 pvcc->old_pop = atmvcc->pop; 409 pvcc->old_owner = atmvcc->owner; 409 pvcc->old_owner = atmvcc->owner; 410 pvcc->old_release_cb = atmvcc->release 410 pvcc->old_release_cb = atmvcc->release_cb; 411 pvcc->encaps = (enum pppoatm_encaps) b 411 pvcc->encaps = (enum pppoatm_encaps) be.encaps; 412 pvcc->chan.private = pvcc; 412 pvcc->chan.private = pvcc; 413 pvcc->chan.ops = &pppoatm_ops; 413 pvcc->chan.ops = &pppoatm_ops; 414 pvcc->chan.mtu = atmvcc->qos.txtp.max_ 414 pvcc->chan.mtu = atmvcc->qos.txtp.max_sdu - PPP_HDRLEN - 415 (be.encaps == e_vc ? 0 : LLC_LEN); 415 (be.encaps == e_vc ? 0 : LLC_LEN); 416 tasklet_setup(&pvcc->wakeup_tasklet, p 416 tasklet_setup(&pvcc->wakeup_tasklet, pppoatm_wakeup_sender); 417 err = ppp_register_channel(&pvcc->chan 417 err = ppp_register_channel(&pvcc->chan); 418 if (err != 0) { 418 if (err != 0) { 419 kfree(pvcc); 419 kfree(pvcc); 420 return err; 420 return err; 421 } 421 } 422 atmvcc->user_back = pvcc; 422 atmvcc->user_back = pvcc; 423 atmvcc->push = pppoatm_push; 423 atmvcc->push = pppoatm_push; 424 atmvcc->pop = pppoatm_pop; 424 atmvcc->pop = pppoatm_pop; 425 atmvcc->release_cb = pppoatm_release_c 425 atmvcc->release_cb = pppoatm_release_cb; 426 __module_get(THIS_MODULE); 426 __module_get(THIS_MODULE); 427 atmvcc->owner = THIS_MODULE; 427 atmvcc->owner = THIS_MODULE; 428 428 429 /* re-process everything received betw 429 /* re-process everything received between connection setup and 430 backend setup */ 430 backend setup */ 431 vcc_process_recv_queue(atmvcc); 431 vcc_process_recv_queue(atmvcc); 432 return 0; 432 return 0; 433 } 433 } 434 434 435 /* 435 /* 436 * This handles ioctls actually performed on o 436 * This handles ioctls actually performed on our vcc - we must return 437 * -ENOIOCTLCMD for any unrecognized ioctl 437 * -ENOIOCTLCMD for any unrecognized ioctl 438 */ 438 */ 439 static int pppoatm_ioctl(struct socket *sock, 439 static int pppoatm_ioctl(struct socket *sock, unsigned int cmd, 440 unsigned long arg) 440 unsigned long arg) 441 { 441 { 442 struct atm_vcc *atmvcc = ATM_SD(sock); 442 struct atm_vcc *atmvcc = ATM_SD(sock); 443 void __user *argp = (void __user *)arg 443 void __user *argp = (void __user *)arg; 444 444 445 if (cmd != ATM_SETBACKEND && atmvcc->p 445 if (cmd != ATM_SETBACKEND && atmvcc->push != pppoatm_push) 446 return -ENOIOCTLCMD; 446 return -ENOIOCTLCMD; 447 switch (cmd) { 447 switch (cmd) { 448 case ATM_SETBACKEND: { 448 case ATM_SETBACKEND: { 449 atm_backend_t b; 449 atm_backend_t b; 450 if (get_user(b, (atm_backend_t 450 if (get_user(b, (atm_backend_t __user *) argp)) 451 return -EFAULT; 451 return -EFAULT; 452 if (b != ATM_BACKEND_PPP) 452 if (b != ATM_BACKEND_PPP) 453 return -ENOIOCTLCMD; 453 return -ENOIOCTLCMD; 454 if (!capable(CAP_NET_ADMIN)) 454 if (!capable(CAP_NET_ADMIN)) 455 return -EPERM; 455 return -EPERM; 456 if (sock->state != SS_CONNECTE 456 if (sock->state != SS_CONNECTED) 457 return -EINVAL; 457 return -EINVAL; 458 return pppoatm_assign_vcc(atmv 458 return pppoatm_assign_vcc(atmvcc, argp); 459 } 459 } 460 case PPPIOCGCHAN: 460 case PPPIOCGCHAN: 461 return put_user(ppp_channel_in 461 return put_user(ppp_channel_index(&atmvcc_to_pvcc(atmvcc)-> 462 chan), (int __user *) argp 462 chan), (int __user *) argp) ? -EFAULT : 0; 463 case PPPIOCGUNIT: 463 case PPPIOCGUNIT: 464 return put_user(ppp_unit_numbe 464 return put_user(ppp_unit_number(&atmvcc_to_pvcc(atmvcc)-> 465 chan), (int __user *) argp 465 chan), (int __user *) argp) ? -EFAULT : 0; 466 } 466 } 467 return -ENOIOCTLCMD; 467 return -ENOIOCTLCMD; 468 } 468 } 469 469 470 static struct atm_ioctl pppoatm_ioctl_ops = { 470 static struct atm_ioctl pppoatm_ioctl_ops = { 471 .owner = THIS_MODULE, 471 .owner = THIS_MODULE, 472 .ioctl = pppoatm_ioctl, 472 .ioctl = pppoatm_ioctl, 473 }; 473 }; 474 474 475 static int __init pppoatm_init(void) 475 static int __init pppoatm_init(void) 476 { 476 { 477 register_atm_ioctl(&pppoatm_ioctl_ops) 477 register_atm_ioctl(&pppoatm_ioctl_ops); 478 return 0; 478 return 0; 479 } 479 } 480 480 481 static void __exit pppoatm_exit(void) 481 static void __exit pppoatm_exit(void) 482 { 482 { 483 deregister_atm_ioctl(&pppoatm_ioctl_op 483 deregister_atm_ioctl(&pppoatm_ioctl_ops); 484 } 484 } 485 485 486 module_init(pppoatm_init); 486 module_init(pppoatm_init); 487 module_exit(pppoatm_exit); 487 module_exit(pppoatm_exit); 488 488 489 MODULE_AUTHOR("Mitchell Blank Jr <mitch@sfgoth 489 MODULE_AUTHOR("Mitchell Blank Jr <mitch@sfgoth.com>"); 490 MODULE_DESCRIPTION("RFC2364 PPP over ATM/AAL5" 490 MODULE_DESCRIPTION("RFC2364 PPP over ATM/AAL5"); 491 MODULE_LICENSE("GPL"); 491 MODULE_LICENSE("GPL"); 492 492
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.