| 1 |
/* |
| 2 |
* NET3: A (fairly minimal) implementation of synchronous PPP for Linux |
| 3 |
* as well as a CISCO HDLC implementation. See the copyright |
| 4 |
* message below for the original source. |
| 5 |
* |
| 6 |
* This program is free software; you can redistribute it and/or |
| 7 |
* modify it under the terms of the GNU General Public License |
| 8 |
* as published by the Free Software Foundation; either version |
| 9 |
* 2 of the license, or (at your option) any later version. |
| 10 |
* |
| 11 |
* Note however. This code is also used in a different form by FreeBSD. |
| 12 |
* Therefore when making any non OS specific change please consider |
| 13 |
* contributing it back to the original author under the terms |
| 14 |
* below in addition. |
| 15 |
* -- Alan |
| 16 |
* |
| 17 |
* Port for Linux-2.1 by Jan "Yenya" Kasprzak <[email protected]> |
| 18 |
*/ |
| 19 |
|
| 20 |
/* |
| 21 |
* Synchronous PPP/Cisco link level subroutines. |
| 22 |
* Keepalive protocol implemented in both Cisco and PPP modes. |
| 23 |
* |
| 24 |
* Copyright (C) 1994 Cronyx Ltd. |
| 25 |
* Author: Serge Vakulenko, <[email protected]> |
| 26 |
* |
| 27 |
* This software is distributed with NO WARRANTIES, not even the implied |
| 28 |
* warranties for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| 29 |
* |
| 30 |
* Authors grant any other persons or organisations permission to use |
| 31 |
* or modify this software as long as this message is kept with the software, |
| 32 |
* all derivative works or modified versions. |
| 33 |
* |
| 34 |
* Version 1.9, Wed Oct 4 18:58:15 MSK 1995 |
| 35 |
* |
| 36 |
* $Id$ |
| 37 |
*/ |
| 38 |
#undef DEBUG |
| 39 |
|
| 40 |
#include <linux/config.h> |
| 41 |
#include <linux/module.h> |
| 42 |
#include <linux/kernel.h> |
| 43 |
#include <linux/errno.h> |
| 44 |
#include <linux/init.h> |
| 45 |
#include <linux/if_arp.h> |
| 46 |
#include <linux/skbuff.h> |
| 47 |
#include <linux/route.h> |
| 48 |
#include <linux/netdevice.h> |
| 49 |
#include <linux/inetdevice.h> |
| 50 |
#include <linux/random.h> |
| 51 |
#include <linux/pkt_sched.h> |
| 52 |
#include <linux/spinlock.h> |
| 53 |
#include <linux/rcupdate.h> |
| 54 |
#include <linux/slab.h> |
| 55 |
|
| 56 |
#include <net/syncppp.h> |
| 57 |
|
| 58 |
#include <asm/byteorder.h> |
| 59 |
#include <asm/uaccess.h> |
| 60 |
|
| 61 |
#define MAXALIVECNT 6 /* max. alive packets */ |
| 62 |
|
| 63 |
#define PPP_ALLSTATIONS 0xff /* All-Stations broadcast address */ |
| 64 |
#define PPP_UI 0x03 /* Unnumbered Information */ |
| 65 |
#define PPP_IP 0x0021 /* Internet Protocol */ |
| 66 |
#define PPP_ISO 0x0023 /* ISO OSI Protocol */ |
| 67 |
#define PPP_XNS 0x0025 /* Xerox NS Protocol */ |
| 68 |
#define PPP_IPX 0x002b /* Novell IPX Protocol */ |
| 69 |
#define PPP_LCP 0xc021 /* Link Control Protocol */ |
| 70 |
#define PPP_IPCP 0x8021 /* Internet Protocol Control Protocol */ |
| 71 |
|
| 72 |
#define LCP_CONF_REQ 1 /* PPP LCP configure request */ |
| 73 |
#define LCP_CONF_ACK 2 /* PPP LCP configure acknowledge */ |
| 74 |
#define LCP_CONF_NAK 3 /* PPP LCP configure negative ack */ |
| 75 |
#define LCP_CONF_REJ 4 /* PPP LCP configure reject */ |
| 76 |
#define LCP_TERM_REQ 5 /* PPP LCP terminate request */ |
| 77 |
#define LCP_TERM_ACK 6 /* PPP LCP terminate acknowledge */ |
| 78 |
#define LCP_CODE_REJ 7 /* PPP LCP code reject */ |
| 79 |
#define LCP_PROTO_REJ 8 /* PPP LCP protocol reject */ |
| 80 |
#define LCP_ECHO_REQ 9 /* PPP LCP echo request */ |
| 81 |
#define LCP_ECHO_REPLY 10 /* PPP LCP echo reply */ |
| 82 |
#define LCP_DISC_REQ 11 /* PPP LCP discard request */ |
| 83 |
|
| 84 |
#define LCP_OPT_MRU 1 /* maximum receive unit */ |
| 85 |
#define LCP_OPT_ASYNC_MAP 2 /* async control character map */ |
| 86 |
#define LCP_OPT_AUTH_PROTO 3 /* authentication protocol */ |
| 87 |
#define LCP_OPT_QUAL_PROTO 4 /* quality protocol */ |
| 88 |
#define LCP_OPT_MAGIC 5 /* magic number */ |
| 89 |
#define LCP_OPT_RESERVED 6 /* reserved */ |
| 90 |
#define LCP_OPT_PROTO_COMP 7 /* protocol field compression */ |
| 91 |
#define LCP_OPT_ADDR_COMP 8 /* address/control field compression */ |
| 92 |
|
| 93 |
#define IPCP_CONF_REQ LCP_CONF_REQ /* PPP IPCP configure request */ |
| 94 |
#define IPCP_CONF_ACK LCP_CONF_ACK /* PPP IPCP configure acknowledge */ |
| 95 |
#define IPCP_CONF_NAK LCP_CONF_NAK /* PPP IPCP configure negative ack */ |
| 96 |
#define IPCP_CONF_REJ LCP_CONF_REJ /* PPP IPCP configure reject */ |
| 97 |
#define IPCP_TERM_REQ LCP_TERM_REQ /* PPP IPCP terminate request */ |
| 98 |
#define IPCP_TERM_ACK LCP_TERM_ACK /* PPP IPCP terminate acknowledge */ |
| 99 |
#define IPCP_CODE_REJ LCP_CODE_REJ /* PPP IPCP code reject */ |
| 100 |
|
| 101 |
#define CISCO_MULTICAST 0x8f /* Cisco multicast address */ |
| 102 |
#define CISCO_UNICAST 0x0f /* Cisco unicast address */ |
| 103 |
#define CISCO_KEEPALIVE 0x8035 /* Cisco keepalive protocol */ |
| 104 |
#define CISCO_ADDR_REQ 0 /* Cisco address request */ |
| 105 |
#define CISCO_ADDR_REPLY 1 /* Cisco address reply */ |
| 106 |
#define CISCO_KEEPALIVE_REQ 2 /* Cisco keepalive request */ |
| 107 |
|
| 108 |
struct ppp_header { |
| 109 |
u8 address; |
| 110 |
u8 control; |
| 111 |
u16 protocol; |
| 112 |
}; |
| 113 |
#define PPP_HEADER_LEN sizeof (struct ppp_header) |
| 114 |
|
| 115 |
struct lcp_header { |
| 116 |
u8 type; |
| 117 |
u8 ident; |
| 118 |
u16 len; |
| 119 |
}; |
| 120 |
#define LCP_HEADER_LEN sizeof (struct lcp_header) |
| 121 |
|
| 122 |
struct cisco_packet { |
| 123 |
u32 type; |
| 124 |
u32 par1; |
| 125 |
u32 par2; |
| 126 |
u16 rel; |
| 127 |
u16 time0; |
| 128 |
u16 time1; |
| 129 |
}; |
| 130 |
#define CISCO_PACKET_LEN 18 |
| 131 |
#define CISCO_BIG_PACKET_LEN 20 |
| 132 |
|
| 133 |
static struct sppp *spppq; |
| 134 |
static struct timer_list sppp_keepalive_timer; |
| 135 |
static DEFINE_SPINLOCK(spppq_lock); |
| 136 |
|
| 137 |
/* global xmit queue for sending packets while spinlock is held */ |
| 138 |
static struct sk_buff_head tx_queue; |
| 139 |
|
| 140 |
static void sppp_keepalive (unsigned long dummy); |
| 141 |
static void sppp_cp_send (struct sppp *sp, u16 proto, u8 type, |
| 142 |
u8 ident, u16 len, void *data); |
| 143 |
static void sppp_cisco_send (struct sppp *sp, int type, long par1, long par2); |
| 144 |
static void sppp_lcp_input (struct sppp *sp, struct sk_buff *m); |
| 145 |
static void sppp_cisco_input (struct sppp *sp, struct sk_buff *m); |
| 146 |
static void sppp_ipcp_input (struct sppp *sp, struct sk_buff *m); |
| 147 |
static void sppp_lcp_open (struct sppp *sp); |
| 148 |
static void sppp_ipcp_open (struct sppp *sp); |
| 149 |
static int sppp_lcp_conf_parse_options (struct sppp *sp, struct lcp_header *h, |
| 150 |
int len, u32 *magic); |
| 151 |
static void sppp_cp_timeout (unsigned long arg); |
| 152 |
static char *sppp_lcp_type_name (u8 type); |
| 153 |
static char *sppp_ipcp_type_name (u8 type); |
| 154 |
static void sppp_print_bytes (u8 *p, u16 len); |
| 155 |
|
| 156 |
static int debug; |
| 157 |
|
| 158 |
/* Flush global outgoing packet queue to dev_queue_xmit(). |
| 159 |
* |
| 160 |
* dev_queue_xmit() must be called with interrupts enabled |
| 161 |
* which means it can't be called with spinlocks held. |
| 162 |
* If a packet needs to be sent while a spinlock is held, |
| 163 |
* then put the packet into tx_queue, and call sppp_flush_xmit() |
| 164 |
* after spinlock is released. |
| 165 |
*/ |
| 166 |
static void sppp_flush_xmit(void) |
| 167 |
{ |
| 168 |
struct sk_buff *skb; |
| 169 |
while ((skb = skb_dequeue(&tx_queue)) != NULL) |
| 170 |
dev_queue_xmit(skb); |
| 171 |
} |
| 172 |
|
| 173 |
/* |
| 174 |
* Interface down stub |
| 175 |
*/ |
| 176 |
|
| 177 |
static void if_down(struct net_device *dev) |
| 178 |
{ |
| 179 |
struct sppp *sp = (struct sppp *)sppp_of(dev); |
| 180 |
|
| 181 |
sp->pp_link_state=SPPP_LINK_DOWN; |
| 182 |
} |
| 183 |
|
| 184 |
/* |
| 185 |
* Timeout routine activations. |
| 186 |
*/ |
| 187 |
|
| 188 |
static void sppp_set_timeout(struct sppp *p,int s) |
| 189 |
{ |
| 190 |
if (! (p->pp_flags & PP_TIMO)) |
| 191 |
{ |
| 192 |
init_timer(&p->pp_timer); |
| 193 |
p->pp_timer.function=sppp_cp_timeout; |
| 194 |
p->pp_timer.expires=jiffies+s*HZ; |
| 195 |
p->pp_timer.data=(unsigned long)p; |
| 196 |
p->pp_flags |= PP_TIMO; |
| 197 |
add_timer(&p->pp_timer); |
| 198 |
} |
| 199 |
} |
| 200 |
|
| 201 |
static void sppp_clear_timeout(struct sppp *p) |
| 202 |
{ |
| 203 |
if (p->pp_flags & PP_TIMO) |
| 204 |
{ |
| 205 |
del_timer(&p->pp_timer); |
| 206 |
p->pp_flags &= ~PP_TIMO; |
| 207 |
} |
| 208 |
} |
| 209 |
|
| 210 |
/** |
| 211 |
* sppp_input - receive and process a WAN PPP frame |
| 212 |
* @skb: The buffer to process |
| 213 |
* @dev: The device it arrived on |
| 214 |
* |
| 215 |
* This can be called directly by cards that do not have |
| 216 |
* timing constraints but is normally called from the network layer |
| 217 |
* after interrupt servicing to process frames queued via netif_rx(). |
| 218 |
* |
| 219 |
* We process the options in the card. If the frame is destined for |
| 220 |
* the protocol stacks then it requeues the frame for the upper level |
| 221 |
* protocol. If it is a control from it is processed and discarded |
| 222 |
* here. |
| 223 |
*/ |
| 224 |
|
| 225 |
static void sppp_input (struct net_device *dev, struct sk_buff *skb) |
| 226 |
{ |
| 227 |
struct ppp_header *h; |
| 228 |
struct sppp *sp = (struct sppp *)sppp_of(dev); |
| 229 |
unsigned long flags; |
| 230 |
|
| 231 |
skb->dev=dev; |
| 232 |
skb->mac.raw=skb->data; |
| 233 |
|
| 234 |
if (dev->flags & IFF_RUNNING) |
| 235 |
{ |
| 236 |
/* Count received bytes, add FCS and one flag */ |
| 237 |
sp->ibytes+= skb->len + 3; |
| 238 |
sp->ipkts++; |
| 239 |
} |
| 240 |
|
| 241 |
if (!pskb_may_pull(skb, PPP_HEADER_LEN)) { |
| 242 |
/* Too small packet, drop it. */ |
| 243 |
if (sp->pp_flags & PP_DEBUG) |
| 244 |
printk (KERN_DEBUG "%s: input packet is too small, %d bytes\n", |
| 245 |
dev->name, skb->len); |
| 246 |
kfree_skb(skb); |
| 247 |
return; |
| 248 |
} |
| 249 |
|
| 250 |
/* Get PPP header. */ |
| 251 |
h = (struct ppp_header *)skb->data; |
| 252 |
skb_pull(skb,sizeof(struct ppp_header)); |
| 253 |
|
| 254 |
spin_lock_irqsave(&sp->lock, flags); |
| 255 |
|
| 256 |
switch (h->address) { |
| 257 |
default: /* Invalid PPP packet. */ |
| 258 |
goto invalid; |
| 259 |
case PPP_ALLSTATIONS: |
| 260 |
if (h->control != PPP_UI) |
| 261 |
goto invalid; |
| 262 |
if (sp->pp_flags & PP_CISCO) { |
| 263 |
if (sp->pp_flags & PP_DEBUG) |
| 264 |
printk (KERN_WARNING "%s: PPP packet in Cisco mode <0x%x 0x%x 0x%x>\n", |
| 265 |
dev->name, |
| 266 |
h->address, h->control, ntohs (h->protocol)); |
| 267 |
goto drop; |
| 268 |
} |
| 269 |
switch (ntohs (h->protocol)) { |
| 270 |
default: |
| 271 |
if (sp->lcp.state == LCP_STATE_OPENED) |
| 272 |
sppp_cp_send (sp, PPP_LCP, LCP_PROTO_REJ, |
| 273 |
++sp->pp_seq, skb->len + 2, |
| 274 |
&h->protocol); |
| 275 |
if (sp->pp_flags & PP_DEBUG) |
| 276 |
printk (KERN_WARNING "%s: invalid input protocol <0x%x 0x%x 0x%x>\n", |
| 277 |
dev->name, |
| 278 |
h->address, h->control, ntohs (h->protocol)); |
| 279 |
goto drop; |
| 280 |
case PPP_LCP: |
| 281 |
sppp_lcp_input (sp, skb); |
| 282 |
goto drop; |
| 283 |
case PPP_IPCP: |
| 284 |
if (sp->lcp.state == LCP_STATE_OPENED) |
| 285 |
sppp_ipcp_input (sp, skb); |
| 286 |
else |
| 287 |
printk(KERN_DEBUG "IPCP when still waiting LCP finish.\n"); |
| 288 |
goto drop; |
| 289 |
case PPP_IP: |
| 290 |
if (sp->ipcp.state == IPCP_STATE_OPENED) { |
| 291 |
if(sp->pp_flags&PP_DEBUG) |
| 292 |
printk(KERN_DEBUG "Yow an IP frame.\n"); |
| 293 |
skb->protocol=htons(ETH_P_IP); |
| 294 |
netif_rx(skb); |
| 295 |
dev->last_rx = jiffies; |
| 296 |
goto done; |
| 297 |
} |
| 298 |
break; |
| 299 |
#ifdef IPX |
| 300 |
case PPP_IPX: |
| 301 |
/* IPX IPXCP not implemented yet */ |
| 302 |
if (sp->lcp.state == LCP_STATE_OPENED) { |
| 303 |
skb->protocol=htons(ETH_P_IPX); |
| 304 |
netif_rx(skb); |
| 305 |
dev->last_rx = jiffies; |
| 306 |
goto done; |
| 307 |
} |
| 308 |
break; |
| 309 |
#endif |
| 310 |
} |
| 311 |
break; |
| 312 |
case CISCO_MULTICAST: |
| 313 |
case CISCO_UNICAST: |
| 314 |
/* Don't check the control field here (RFC 1547). */ |
| 315 |
if (! (sp->pp_flags & PP_CISCO)) { |
| 316 |
if (sp->pp_flags & PP_DEBUG) |
| 317 |
printk (KERN_WARNING "%s: Cisco packet in PPP mode <0x%x 0x%x 0x%x>\n", |
| 318 |
dev->name, |
| 319 |
h->address, h->control, ntohs (h->protocol)); |
| 320 |
goto drop; |
| 321 |
} |
| 322 |
switch (ntohs (h->protocol)) { |
| 323 |
default: |
| 324 |
goto invalid; |
| 325 |
case CISCO_KEEPALIVE: |
| 326 |
sppp_cisco_input (sp, skb); |
| 327 |
goto drop; |
| 328 |
#ifdef CONFIG_INET |
| 329 |
case ETH_P_IP: |
| 330 |
skb->protocol=htons(ETH_P_IP); |
| 331 |
netif_rx(skb); |
| 332 |
dev->last_rx = jiffies; |
| 333 |
goto done; |
| 334 |
#endif |
| 335 |
#ifdef CONFIG_IPX |
| 336 |
case ETH_P_IPX: |
| 337 |
skb->protocol=htons(ETH_P_IPX); |
| 338 |
netif_rx(skb); |
| 339 |
dev->last_rx = jiffies; |
| 340 |
goto done; |
| 341 |
#endif |
| 342 |
} |
| 343 |
break; |
| 344 |
} |
| 345 |
goto drop; |
| 346 |
|
| 347 |
invalid: |
| 348 |
if (sp->pp_flags & PP_DEBUG) |
| 349 |
printk (KERN_WARNING "%s: invalid input packet <0x%x 0x%x 0x%x>\n", |
| 350 |
dev->name, h->address, h->control, ntohs (h->protocol)); |
| 351 |
drop: |
| 352 |
kfree_skb(skb); |
| 353 |
done: |
| 354 |
spin_unlock_irqrestore(&sp->lock, flags); |
| 355 |
sppp_flush_xmit(); |
| 356 |
return; |
| 357 |
} |
| 358 |
|
| 359 |
/* |
| 360 |
* Handle transmit packets. |
| 361 |
*/ |
| 362 |
|
| 363 |
static int sppp_hard_header(struct sk_buff *skb, struct net_device *dev, __u16 type, |
| 364 |
void *daddr, void *saddr, unsigned int len) |
| 365 |
{ |
| 366 |
struct sppp *sp = (struct sppp *)sppp_of(dev); |
| 367 |
struct ppp_header *h; |
| 368 |
skb_push(skb,sizeof(struct ppp_header)); |
| 369 |
h=(struct ppp_header *)skb->data; |
| 370 |
if(sp->pp_flags&PP_CISCO) |
| 371 |
{ |
| 372 |
h->address = CISCO_UNICAST; |
| 373 |
h->control = 0; |
| 374 |
} |
| 375 |
else |
| 376 |
{ |
| 377 |
h->address = PPP_ALLSTATIONS; |
| 378 |
h->control = PPP_UI; |
| 379 |
} |
| 380 |
if(sp->pp_flags & PP_CISCO) |
| 381 |
{ |
| 382 |
h->protocol = htons(type); |
| 383 |
} |
| 384 |
else switch(type) |
| 385 |
{ |
| 386 |
case ETH_P_IP: |
| 387 |
h->protocol = htons(PPP_IP); |
| 388 |
break; |
| 389 |
case ETH_P_IPX: |
| 390 |
h->protocol = htons(PPP_IPX); |
| 391 |
break; |
| 392 |
} |
| 393 |
return sizeof(struct ppp_header); |
| 394 |
} |
| 395 |
|
| 396 |
static int sppp_rebuild_header(struct sk_buff *skb) |
| 397 |
{ |
| 398 |
return 0; |
| 399 |
} |
| 400 |
|
| 401 |
/* |
| 402 |
* Send keepalive packets, every 10 seconds. |
| 403 |
*/ |
| 404 |
|
| 405 |
static void sppp_keepalive (unsigned long dummy) |
| 406 |
{ |
| 407 |
struct sppp *sp; |
| 408 |
unsigned long flags; |
| 409 |
|
| 410 |
spin_lock_irqsave(&spppq_lock, flags); |
| 411 |
|
| 412 |
for (sp=spppq; sp; sp=sp->pp_next) |
| 413 |
{ |
| 414 |
struct net_device *dev = sp->pp_if; |
| 415 |
|
| 416 |
/* Keepalive mode disabled or channel down? */ |
| 417 |
if (! (sp->pp_flags & PP_KEEPALIVE) || |
| 418 |
! (dev->flags & IFF_UP)) |
| 419 |
continue; |
| 420 |
|
| 421 |
spin_lock(&sp->lock); |
| 422 |
|
| 423 |
/* No keepalive in PPP mode if LCP not opened yet. */ |
| 424 |
if (! (sp->pp_flags & PP_CISCO) && |
| 425 |
sp->lcp.state != LCP_STATE_OPENED) { |
| 426 |
spin_unlock(&sp->lock); |
| 427 |
continue; |
| 428 |
} |
| 429 |
|
| 430 |
if (sp->pp_alivecnt == MAXALIVECNT) { |
| 431 |
/* No keepalive packets got. Stop the interface. */ |
| 432 |
printk (KERN_WARNING "%s: protocol down\n", dev->name); |
| 433 |
if_down (dev); |
| 434 |
if (! (sp->pp_flags & PP_CISCO)) { |
| 435 |
/* Shut down the PPP link. */ |
| 436 |
sp->lcp.magic = jiffies; |
| 437 |
sp->lcp.state = LCP_STATE_CLOSED; |
| 438 |
sp->ipcp.state = IPCP_STATE_CLOSED; |
| 439 |
sppp_clear_timeout (sp); |
| 440 |
/* Initiate negotiation. */ |
| 441 |
sppp_lcp_open (sp); |
| 442 |
} |
| 443 |
} |
| 444 |
if (sp->pp_alivecnt <= MAXALIVECNT) |
| 445 |
++sp->pp_alivecnt; |
| 446 |
if (sp->pp_flags & PP_CISCO) |
| 447 |
sppp_cisco_send (sp, CISCO_KEEPALIVE_REQ, ++sp->pp_seq, |
| 448 |
sp->pp_rseq); |
| 449 |
else if (sp->lcp.state == LCP_STATE_OPENED) { |
| 450 |
long nmagic = htonl (sp->lcp.magic); |
| 451 |
sp->lcp.echoid = ++sp->pp_seq; |
| 452 |
sppp_cp_send (sp, PPP_LCP, LCP_ECHO_REQ, |
| 453 |
sp->lcp.echoid, 4, &nmagic); |
| 454 |
} |
| 455 |
|
| 456 |
spin_unlock(&sp->lock); |
| 457 |
} |
| 458 |
spin_unlock_irqrestore(&spppq_lock, flags); |
| 459 |
sppp_flush_xmit(); |
| 460 |
sppp_keepalive_timer.expires=jiffies+10*HZ; |
| 461 |
add_timer(&sppp_keepalive_timer); |
| 462 |
} |
| 463 |
|
| 464 |
/* |
| 465 |
* Handle incoming PPP Link Control Protocol packets. |
| 466 |
*/ |
| 467 |
|
| 468 |
static void sppp_lcp_input (struct sppp *sp, struct sk_buff *skb) |
| 469 |
{ |
| 470 |
struct lcp_header *h; |
| 471 |
struct net_device *dev = sp->pp_if; |
| 472 |
int len = skb->len; |
| 473 |
u8 *p, opt[6]; |
| 474 |
u32 rmagic; |
| 475 |
|
| 476 |
if (!pskb_may_pull(skb, sizeof(struct lcp_header))) { |
| 477 |
if (sp->pp_flags & PP_DEBUG) |
| 478 |
printk (KERN_WARNING "%s: invalid lcp packet length: %d bytes\n", |
| 479 |
dev->name, len); |
| 480 |
return; |
| 481 |
} |
| 482 |
h = (struct lcp_header *)skb->data; |
| 483 |
skb_pull(skb,sizeof(struct lcp_header *)); |
| 484 |
|
| 485 |
if (sp->pp_flags & PP_DEBUG) |
| 486 |
{ |
| 487 |
char state = '?'; |
| 488 |
switch (sp->lcp.state) { |
| 489 |
case LCP_STATE_CLOSED: state = 'C'; break; |
| 490 |
case LCP_STATE_ACK_RCVD: state = 'R'; break; |
| 491 |
case LCP_STATE_ACK_SENT: state = 'S'; break; |
| 492 |
case LCP_STATE_OPENED: state = 'O'; break; |
| 493 |
} |
| 494 |
printk (KERN_WARNING "%s: lcp input(%c): %d bytes <%s id=%xh len=%xh", |
| 495 |
dev->name, state, len, |
| 496 |
sppp_lcp_type_name (h->type), h->ident, ntohs (h->len)); |
| 497 |
if (len > 4) |
| 498 |
sppp_print_bytes ((u8*) (h+1), len-4); |
| 499 |
printk (">\n"); |
| 500 |
} |
| 501 |
if (len > ntohs (h->len)) |
| 502 |
len = ntohs (h->len); |
| 503 |
switch (h->type) { |
| 504 |
default: |
| 505 |
/* Unknown packet type -- send Code-Reject packet. */ |
| 506 |
sppp_cp_send (sp, PPP_LCP, LCP_CODE_REJ, ++sp->pp_seq, |
| 507 |
skb->len, h); |
| 508 |
break; |
| 509 |
case LCP_CONF_REQ: |
| 510 |
if (len < 4) { |
| 511 |
if (sp->pp_flags & PP_DEBUG) |
| 512 |
printk (KERN_DEBUG"%s: invalid lcp configure request packet length: %d bytes\n", |
| 513 |
dev->name, len); |
| 514 |
break; |
| 515 |
} |
| 516 |
if (len>4 && !sppp_lcp_conf_parse_options (sp, h, len, &rmagic)) |
| 517 |
goto badreq; |
| 518 |
if (rmagic == sp->lcp.magic) { |
| 519 |
/* Local and remote magics equal -- loopback? */ |
| 520 |
if (sp->pp_loopcnt >= MAXALIVECNT*5) { |
| 521 |
printk (KERN_WARNING "%s: loopback\n", |
| 522 |
dev->name); |
| 523 |
sp->pp_loopcnt = 0; |
| 524 |
if (dev->flags & IFF_UP) { |
| 525 |
if_down (dev); |
| 526 |
} |
| 527 |
} else if (sp->pp_flags & PP_DEBUG) |
| 528 |
printk (KERN_DEBUG "%s: conf req: magic glitch\n", |
| 529 |
dev->name); |
| 530 |
++sp->pp_loopcnt; |
| 531 |
|
| 532 |
/* MUST send Conf-Nack packet. */ |
| 533 |
rmagic = ~sp->lcp.magic; |
| 534 |
opt[0] = LCP_OPT_MAGIC; |
| 535 |
opt[1] = sizeof (opt); |
| 536 |
opt[2] = rmagic >> 24; |
| 537 |
opt[3] = rmagic >> 16; |
| 538 |
opt[4] = rmagic >> 8; |
| 539 |
opt[5] = rmagic; |
| 540 |
sppp_cp_send (sp, PPP_LCP, LCP_CONF_NAK, |
| 541 |
h->ident, sizeof (opt), &opt); |
| 542 |
badreq: |
| 543 |
switch (sp->lcp.state) { |
| 544 |
case LCP_STATE_OPENED: |
| 545 |
/* Initiate renegotiation. */ |
| 546 |
sppp_lcp_open (sp); |
| 547 |
/* fall through... */ |
| 548 |
case LCP_STATE_ACK_SENT: |
| 549 |
/* Go to closed state. */ |
| 550 |
sp->lcp.state = LCP_STATE_CLOSED; |
| 551 |
sp->ipcp.state = IPCP_STATE_CLOSED; |
| 552 |
} |
| 553 |
break; |
| 554 |
} |
| 555 |
/* Send Configure-Ack packet. */ |
| 556 |
sp->pp_loopcnt = 0; |
| 557 |
if (sp->lcp.state != LCP_STATE_OPENED) { |
| 558 |
sppp_cp_send (sp, PPP_LCP, LCP_CONF_ACK, |
| 559 |
h->ident, len-4, h+1); |
| 560 |
} |
| 561 |
/* Change the state. */ |
| 562 |
switch (sp->lcp.state) { |
| 563 |
case LCP_STATE_CLOSED: |
| 564 |
sp->lcp.state = LCP_STATE_ACK_SENT; |
| 565 |
break; |
| 566 |
case LCP_STATE_ACK_RCVD: |
| 567 |
sp->lcp.state = LCP_STATE_OPENED; |
| 568 |
sppp_ipcp_open (sp); |
| 569 |
break; |
| 570 |
case LCP_STATE_OPENED: |
| 571 |
/* Remote magic changed -- close session. */ |
| 572 |
sp->lcp.state = LCP_STATE_CLOSED; |
| 573 |
sp->ipcp.state = IPCP_STATE_CLOSED; |
| 574 |
/* Initiate renegotiation. */ |
| 575 |
sppp_lcp_open (sp); |
| 576 |
/* Send ACK after our REQ in attempt to break loop */ |
| 577 |
sppp_cp_send (sp, PPP_LCP, LCP_CONF_ACK, |
| 578 |
h->ident, len-4, h+1); |
| 579 |
sp->lcp.state = LCP_STATE_ACK_SENT; |
| 580 |
break; |
| 581 |
} |
| 582 |
break; |
| 583 |
case LCP_CONF_ACK: |
| 584 |
if (h->ident != sp->lcp.confid) |
| 585 |
break; |
| 586 |
sppp_clear_timeout (sp); |
| 587 |
if ((sp->pp_link_state != SPPP_LINK_UP) && |
| 588 |
(dev->flags & IFF_UP)) { |
| 589 |
/* Coming out of loopback mode. */ |
| 590 |
sp->pp_link_state=SPPP_LINK_UP; |
| 591 |
printk (KERN_INFO "%s: protocol up\n", dev->name); |
| 592 |
} |
| 593 |
switch (sp->lcp.state) { |
| 594 |
case LCP_STATE_CLOSED: |
| 595 |
sp->lcp.state = LCP_STATE_ACK_RCVD; |
| 596 |
sppp_set_timeout (sp, 5); |
| 597 |
break; |
| 598 |
case LCP_STATE_ACK_SENT: |
| 599 |
sp->lcp.state = LCP_STATE_OPENED; |
| 600 |
sppp_ipcp_open (sp); |
| 601 |
break; |
| 602 |
} |
| 603 |
break; |
| 604 |
case LCP_CONF_NAK: |
| 605 |
if (h->ident != sp->lcp.confid) |
| 606 |
break; |
| 607 |
p = (u8*) (h+1); |
| 608 |
if (len>=10 && p[0] == LCP_OPT_MAGIC && p[1] >= 4) { |
| 609 |
rmagic = (u32)p[2] << 24 | |
| 610 |
(u32)p[3] << 16 | p[4] << 8 | p[5]; |
| 611 |
if (rmagic == ~sp->lcp.magic) { |
| 612 |
int newmagic; |
| 613 |
if (sp->pp_flags & PP_DEBUG) |
| 614 |
printk (KERN_DEBUG "%s: conf nak: magic glitch\n", |
| 615 |
dev->name); |
| 616 |
get_random_bytes(&newmagic, sizeof(newmagic)); |
| 617 |
sp->lcp.magic += newmagic; |
| 618 |
} else |
| 619 |
sp->lcp.magic = rmagic; |
| 620 |
} |
| 621 |
if (sp->lcp.state != LCP_STATE_ACK_SENT) { |
| 622 |
/* Go to closed state. */ |
| 623 |
sp->lcp.state = LCP_STATE_CLOSED; |
| 624 |
sp->ipcp.state = IPCP_STATE_CLOSED; |
| 625 |
} |
| 626 |
/* The link will be renegotiated after timeout, |
| 627 |
* to avoid endless req-nack loop. */ |
| 628 |
sppp_clear_timeout (sp); |
| 629 |
sppp_set_timeout (sp, 2); |
| 630 |
break; |
| 631 |
case LCP_CONF_REJ: |
| 632 |
if (h->ident != sp->lcp.confid) |
| 633 |
break; |
| 634 |
sppp_clear_timeout (sp); |
| 635 |
/* Initiate renegotiation. */ |
| 636 |
sppp_lcp_open (sp); |
| 637 |
if (sp->lcp.state != LCP_STATE_ACK_SENT) { |
| 638 |
/* Go to closed state. */ |
| 639 |
sp->lcp.state = LCP_STATE_CLOSED; |
| 640 |
sp->ipcp.state = IPCP_STATE_CLOSED; |
| 641 |
} |
| 642 |
break; |
| 643 |
case LCP_TERM_REQ: |
| 644 |
sppp_clear_timeout (sp); |
| 645 |
/* Send Terminate-Ack packet. */ |
| 646 |
sppp_cp_send (sp, PPP_LCP, LCP_TERM_ACK, h->ident, 0, NULL); |
| 647 |
/* Go to closed state. */ |
| 648 |
sp->lcp.state = LCP_STATE_CLOSED; |
| 649 |
sp->ipcp.state = IPCP_STATE_CLOSED; |
| 650 |
/* Initiate renegotiation. */ |
| 651 |
sppp_lcp_open (sp); |
| 652 |
break; |
| 653 |
case LCP_TERM_ACK: |
| 654 |
case LCP_CODE_REJ: |
| 655 |
case LCP_PROTO_REJ: |
| 656 |
/* Ignore for now. */ |
| 657 |
break; |
| 658 |
case LCP_DISC_REQ: |
| 659 |
/* Discard the packet. */ |
| 660 |
break; |
| 661 |
case LCP_ECHO_REQ: |
| 662 |
if (sp->lcp.state != LCP_STATE_OPENED) |
| 663 |
break; |
| 664 |
if (len < 8) { |
| 665 |
if (sp->pp_flags & PP_DEBUG) |
| 666 |
printk (KERN_WARNING "%s: invalid lcp echo request packet length: %d bytes\n", |
| 667 |
dev->name, len); |
| 668 |
break; |
| 669 |
} |
| 670 |
if (ntohl (*(long*)(h+1)) == sp->lcp.magic) { |
| 671 |
/* Line loopback mode detected. */ |
| 672 |
printk (KERN_WARNING "%s: loopback\n", dev->name); |
| 673 |
if_down (dev); |
| 674 |
|
| 675 |
/* Shut down the PPP link. */ |
| 676 |
sp->lcp.state = LCP_STATE_CLOSED; |
| 677 |
sp->ipcp.state = IPCP_STATE_CLOSED; |
| 678 |
sppp_clear_timeout (sp); |
| 679 |
/* Initiate negotiation. */ |
| 680 |
sppp_lcp_open (sp); |
| 681 |
break; |
| 682 |
} |
| 683 |
*(long*)(h+1) = htonl (sp->lcp.magic); |
| 684 |
sppp_cp_send (sp, PPP_LCP, LCP_ECHO_REPLY, h->ident, len-4, h+1); |
| 685 |
break; |
| 686 |
case LCP_ECHO_REPLY: |
| 687 |
if (h->ident != sp->lcp.echoid) |
| 688 |
break; |
| 689 |
if (len < 8) { |
| 690 |
if (sp->pp_flags & PP_DEBUG) |
| 691 |
printk (KERN_WARNING "%s: invalid lcp echo reply packet length: %d bytes\n", |
| 692 |
dev->name, len); |
| 693 |
break; |
| 694 |
} |
| 695 |
if (ntohl (*(long*)(h+1)) != sp->lcp.magic) |
| 696 |
sp->pp_alivecnt = 0; |
| 697 |
break; |
| 698 |
} |
| 699 |
} |
| 700 |
|
| 701 |
/* |
| 702 |
* Handle incoming Cisco keepalive protocol packets. |
| 703 |
*/ |
| 704 |
|
| 705 |
static void sppp_cisco_input (struct sppp *sp, struct sk_buff *skb) |
| 706 |
{ |
| 707 |
struct cisco_packet *h; |
| 708 |
struct net_device *dev = sp->pp_if; |
| 709 |
|
| 710 |
if (!pskb_may_pull(skb, sizeof(struct cisco_packet)) |
| 711 |
|| (skb->len != CISCO_PACKET_LEN |
| 712 |
&& skb->len != CISCO_BIG_PACKET_LEN)) { |
| 713 |
if (sp->pp_flags & PP_DEBUG) |
| 714 |
printk (KERN_WARNING "%s: invalid cisco packet length: %d bytes\n", |
| 715 |
dev->name, skb->len); |
| 716 |
return; |
| 717 |
} |
| 718 |
h = (struct cisco_packet *)skb->data; |
| 719 |
skb_pull(skb, sizeof(struct cisco_packet*)); |
| 720 |
if (sp->pp_flags & PP_DEBUG) |
| 721 |
printk (KERN_WARNING "%s: cisco input: %d bytes <%xh %xh %xh %xh %xh-%xh>\n", |
| 722 |
dev->name, skb->len, |
| 723 |
ntohl (h->type), h->par1, h->par2, h->rel, |
| 724 |
h->time0, h->time1); |
| 725 |
switch (ntohl (h->type)) { |
| 726 |
default: |
| 727 |
if (sp->pp_flags & PP_DEBUG) |
| 728 |
printk (KERN_WARNING "%s: unknown cisco packet type: 0x%x\n", |
| 729 |
dev->name, ntohl (h->type)); |
| 730 |
break; |
| 731 |
case CISCO_ADDR_REPLY: |
| 732 |
/* Reply on address request, ignore */ |
| 733 |
break; |
| 734 |
case CISCO_KEEPALIVE_REQ: |
| 735 |
sp->pp_alivecnt = 0; |
| 736 |
sp->pp_rseq = ntohl (h->par1); |
| 737 |
if (sp->pp_seq == sp->pp_rseq) { |
| 738 |
/* Local and remote sequence numbers are equal. |
| 739 |
* Probably, the line is in loopback mode. */ |
| 740 |
int newseq; |
| 741 |
if (sp->pp_loopcnt >= MAXALIVECNT) { |
| 742 |
printk (KERN_WARNING "%s: loopback\n", |
| 743 |
dev->name); |
| 744 |
sp->pp_loopcnt = 0; |
| 745 |
if (dev->flags & IFF_UP) { |
| 746 |
if_down (dev); |
| 747 |
} |
| 748 |
} |
| 749 |
++sp->pp_loopcnt; |
| 750 |
|
| 751 |
/* Generate new local sequence number */ |
| 752 |
get_random_bytes(&newseq, sizeof(newseq)); |
| 753 |
sp->pp_seq ^= newseq; |
| 754 |
break; |
| 755 |
} |
| 756 |
sp->pp_loopcnt = 0; |
| 757 |
if (sp->pp_link_state==SPPP_LINK_DOWN && |
| 758 |
(dev->flags & IFF_UP)) { |
| 759 |
sp->pp_link_state=SPPP_LINK_UP; |
| 760 |
printk (KERN_INFO "%s: protocol up\n", dev->name); |
| 761 |
} |
| 762 |
break; |
| 763 |
case CISCO_ADDR_REQ: |
| 764 |
/* Stolen from net/ipv4/devinet.c -- SIOCGIFADDR ioctl */ |
| 765 |
{ |
| 766 |
struct in_device *in_dev; |
| 767 |
struct in_ifaddr *ifa; |
| 768 |
u32 addr = 0, mask = ~0; /* FIXME: is the mask correct? */ |
| 769 |
#ifdef CONFIG_INET |
| 770 |
rcu_read_lock(); |
| 771 |
if ((in_dev = __in_dev_get_rcu(dev)) != NULL) |
| 772 |
{ |
| 773 |
for (ifa=in_dev->ifa_list; ifa != NULL; |
| 774 |
ifa=ifa->ifa_next) { |
| 775 |
if (strcmp(dev->name, ifa->ifa_label) == 0) |
| 776 |
{ |
| 777 |
addr = ifa->ifa_local; |
| 778 |
mask = ifa->ifa_mask; |
| 779 |
break; |
| 780 |
} |
| 781 |
} |
| 782 |
} |
| 783 |
rcu_read_unlock(); |
| 784 |
#endif |
| 785 |
/* I hope both addr and mask are in the net order */ |
| 786 |
sppp_cisco_send (sp, CISCO_ADDR_REPLY, addr, mask); |
| 787 |
break; |
| 788 |
} |
| 789 |
} |
| 790 |
} |
| 791 |
|
| 792 |
|
| 793 |
/* |
| 794 |
* Send PPP LCP packet. |
| 795 |
*/ |
| 796 |
|
| 797 |
static void sppp_cp_send (struct sppp *sp, u16 proto, u8 type, |
| 798 |
u8 ident, u16 len, void *data) |
| 799 |
{ |
| 800 |
struct ppp_header *h; |
| 801 |
struct lcp_header *lh; |
| 802 |
struct sk_buff *skb; |
| 803 |
struct net_device *dev = sp->pp_if; |
| 804 |
|
| 805 |
skb=alloc_skb(dev->hard_header_len+PPP_HEADER_LEN+LCP_HEADER_LEN+len, |
| 806 |
GFP_ATOMIC); |
| 807 |
if (skb==NULL) |
| 808 |
return; |
| 809 |
|
| 810 |
skb_reserve(skb,dev->hard_header_len); |
| 811 |
|
| 812 |
h = (struct ppp_header *)skb_put(skb, sizeof(struct ppp_header)); |
| 813 |
h->address = PPP_ALLSTATIONS; /* broadcast address */ |
| 814 |
h->control = PPP_UI; /* Unnumbered Info */ |
| 815 |
h->protocol = htons (proto); /* Link Control Protocol */ |
| 816 |
|
| 817 |
lh = (struct lcp_header *)skb_put(skb, sizeof(struct lcp_header)); |
| 818 |
lh->type = type; |
| 819 |
lh->ident = ident; |
| 820 |
lh->len = htons (LCP_HEADER_LEN + len); |
| 821 |
|
| 822 |
if (len) |
| 823 |
memcpy(skb_put(skb,len),data, len); |
| 824 |
|
| 825 |
if (sp->pp_flags & PP_DEBUG) { |
| 826 |
printk (KERN_WARNING "%s: %s output <%s id=%xh len=%xh", |
| 827 |
dev->name, |
| 828 |
proto==PPP_LCP ? "lcp" : "ipcp", |
| 829 |
proto==PPP_LCP ? sppp_lcp_type_name (lh->type) : |
| 830 |
sppp_ipcp_type_name (lh->type), lh->ident, |
| 831 |
ntohs (lh->len)); |
| 832 |
if (len) |
| 833 |
sppp_print_bytes ((u8*) (lh+1), len); |
| 834 |
printk (">\n"); |
| 835 |
} |
| 836 |
sp->obytes += skb->len; |
| 837 |
/* Control is high priority so it doesn't get queued behind data */ |
| 838 |
skb->priority=TC_PRIO_CONTROL; |
| 839 |
skb->dev = dev; |
| 840 |
skb_queue_tail(&tx_queue, skb); |
| 841 |
} |
| 842 |
|
| 843 |
/* |
| 844 |
* Send Cisco keepalive packet. |
| 845 |
*/ |
| 846 |
|
| 847 |
static void sppp_cisco_send (struct sppp *sp, int type, long par1, long par2) |
| 848 |
{ |
| 849 |
struct ppp_header *h; |
| 850 |
struct cisco_packet *ch; |
| 851 |
struct sk_buff *skb; |
| 852 |
struct net_device *dev = sp->pp_if; |
| 853 |
u32 t = jiffies * 1000/HZ; |
| 854 |
|
| 855 |
skb=alloc_skb(dev->hard_header_len+PPP_HEADER_LEN+CISCO_PACKET_LEN, |
| 856 |
GFP_ATOMIC); |
| 857 |
|
| 858 |
if(skb==NULL) |
| 859 |
return; |
| 860 |
|
| 861 |
skb_reserve(skb, dev->hard_header_len); |
| 862 |
h = (struct ppp_header *)skb_put (skb, sizeof(struct ppp_header)); |
| 863 |
h->address = CISCO_MULTICAST; |
| 864 |
h->control = 0; |
| 865 |
h->protocol = htons (CISCO_KEEPALIVE); |
| 866 |
|
| 867 |
ch = (struct cisco_packet*)skb_put(skb, CISCO_PACKET_LEN); |
| 868 |
ch->type = htonl (type); |
| 869 |
ch->par1 = htonl (par1); |
| 870 |
ch->par2 = htonl (par2); |
| 871 |
ch->rel = -1; |
| 872 |
ch->time0 = htons ((u16) (t >> 16)); |
| 873 |
ch->time1 = htons ((u16) t); |
| 874 |
|
| 875 |
if (sp->pp_flags & PP_DEBUG) |
| 876 |
printk (KERN_WARNING "%s: cisco output: <%xh %xh %xh %xh %xh-%xh>\n", |
| 877 |
dev->name, ntohl (ch->type), ch->par1, |
| 878 |
ch->par2, ch->rel, ch->time0, ch->time1); |
| 879 |
sp->obytes += skb->len; |
| 880 |
skb->priority=TC_PRIO_CONTROL; |
| 881 |
skb->dev = dev; |
| 882 |
skb_queue_tail(&tx_queue, skb); |
| 883 |
} |
| 884 |
|
| 885 |
/** |
| 886 |
* sppp_close - close down a synchronous PPP or Cisco HDLC link |
| 887 |
* @dev: The network device to drop the link of |
| 888 |
* |
| 889 |
* This drops the logical interface to the channel. It is not |
| 890 |
* done politely as we assume we will also be dropping DTR. Any |
| 891 |
* timeouts are killed. |
| 892 |
*/ |
| 893 |
|
| 894 |
int sppp_close (struct net_device *dev) |
| 895 |
{ |
| 896 |
struct sppp *sp = (struct sppp *)sppp_of(dev); |
| 897 |
unsigned long flags; |
| 898 |
|
| 899 |
spin_lock_irqsave(&sp->lock, flags); |
| 900 |
sp->pp_link_state = SPPP_LINK_DOWN; |
| 901 |
sp->lcp.state = LCP_STATE_CLOSED; |
| 902 |
sp->ipcp.state = IPCP_STATE_CLOSED; |
| 903 |
sppp_clear_timeout (sp); |
| 904 |
spin_unlock_irqrestore(&sp->lock, flags); |
| 905 |
|
| 906 |
return 0; |
| 907 |
} |
| 908 |
|
| 909 |
EXPORT_SYMBOL(sppp_close); |
| 910 |
|
| 911 |
/** |
| 912 |
* sppp_open - open a synchronous PPP or Cisco HDLC link |
| 913 |
* @dev: Network device to activate |
| 914 |
* |
| 915 |
* Close down any existing synchronous session and commence |
| 916 |
* from scratch. In the PPP case this means negotiating LCP/IPCP |
| 917 |
* and friends, while for Cisco HDLC we simply need to start sending |
| 918 |
* keepalives |
| 919 |
*/ |
| 920 |
|
| 921 |
int sppp_open (struct net_device *dev) |
| 922 |
{ |
| 923 |
struct sppp *sp = (struct sppp *)sppp_of(dev); |
| 924 |
unsigned long flags; |
| 925 |
|
| 926 |
sppp_close(dev); |
| 927 |
|
| 928 |
spin_lock_irqsave(&sp->lock, flags); |
| 929 |
if (!(sp->pp_flags & PP_CISCO)) { |
| 930 |
sppp_lcp_open (sp); |
| 931 |
} |
| 932 |
sp->pp_link_state = SPPP_LINK_DOWN; |
| 933 |
spin_unlock_irqrestore(&sp->lock, flags); |
| 934 |
sppp_flush_xmit(); |
| 935 |
|
| 936 |
return 0; |
| 937 |
} |
| 938 |
|
| 939 |
EXPORT_SYMBOL(sppp_open); |
| 940 |
|
| 941 |
/** |
| 942 |
* sppp_reopen - notify of physical link loss |
| 943 |
* @dev: Device that lost the link |
| 944 |
* |
| 945 |
* This function informs the synchronous protocol code that |
| 946 |
* the underlying link died (for example a carrier drop on X.21) |
| 947 |
* |
| 948 |
* We increment the magic numbers to ensure that if the other end |
| 949 |
* failed to notice we will correctly start a new session. It happens |
| 950 |
* do to the nature of telco circuits is that you can lose carrier on |
| 951 |
* one endonly. |
| 952 |
* |
| 953 |
* Having done this we go back to negotiating. This function may |
| 954 |
* be called from an interrupt context. |
| 955 |
*/ |
| 956 |
|
| 957 |
int sppp_reopen (struct net_device *dev) |
| 958 |
{ |
| 959 |
struct sppp *sp = (struct sppp *)sppp_of(dev); |
| 960 |
unsigned long flags; |
| 961 |
|
| 962 |
sppp_close(dev); |
| 963 |
|
| 964 |
spin_lock_irqsave(&sp->lock, flags); |
| 965 |
if (!(sp->pp_flags & PP_CISCO)) |
| 966 |
{ |
| 967 |
sp->lcp.magic = jiffies; |
| 968 |
++sp->pp_seq; |
| 969 |
sp->lcp.state = LCP_STATE_CLOSED; |
| 970 |
sp->ipcp.state = IPCP_STATE_CLOSED; |
| 971 |
/* Give it a moment for the line to settle then go */ |
| 972 |
sppp_set_timeout (sp, 1); |
| 973 |
} |
| 974 |
sp->pp_link_state=SPPP_LINK_DOWN; |
| 975 |
spin_unlock_irqrestore(&sp->lock, flags); |
| 976 |
|
| 977 |
return 0; |
| 978 |
} |
| 979 |
|
| 980 |
EXPORT_SYMBOL(sppp_reopen); |
| 981 |
|
| 982 |
/** |
| 983 |
* sppp_change_mtu - Change the link MTU |
| 984 |
* @dev: Device to change MTU on |
| 985 |
* @new_mtu: New MTU |
| 986 |
* |
| 987 |
* Change the MTU on the link. This can only be called with |
| 988 |
* the link down. It returns an error if the link is up or |
| 989 |
* the mtu is out of range. |
| 990 |
*/ |
| 991 |
|
| 992 |
static int sppp_change_mtu(struct net_device *dev, int new_mtu) |
| 993 |
{ |
| 994 |
if(new_mtu<128||new_mtu>PPP_MTU||(dev->flags&IFF_UP)) |
| 995 |
return -EINVAL; |
| 996 |
dev->mtu=new_mtu; |
| 997 |
return 0; |
| 998 |
} |
| 999 |
|
| 1000 |
/** |
| 1001 |
* sppp_do_ioctl - Ioctl handler for ppp/hdlc |
| 1002 |
* @dev: Device subject to ioctl |
| 1003 |
* @ifr: Interface request block from the user |
| 1004 |
* @cmd: Command that is being issued |
| 1005 |
* |
| 1006 |
* This function handles the ioctls that may be issued by the user |
| 1007 |
* to control the settings of a PPP/HDLC link. It does both busy |
| 1008 |
* and security checks. This function is intended to be wrapped by |
| 1009 |
* callers who wish to add additional ioctl calls of their own. |
| 1010 |
*/ |
| 1011 |
|
| 1012 |
int sppp_do_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd) |
| 1013 |
{ |
| 1014 |
struct sppp *sp = (struct sppp *)sppp_of(dev); |
| 1015 |
|
| 1016 |
if(dev->flags&IFF_UP) |
| 1017 |
return -EBUSY; |
| 1018 |
|
| 1019 |
if(!capable(CAP_NET_ADMIN)) |
| 1020 |
return -EPERM; |
| 1021 |
|
| 1022 |
switch(cmd) |
| 1023 |
{ |
| 1024 |
case SPPPIOCCISCO: |
| 1025 |
sp->pp_flags|=PP_CISCO; |
| 1026 |
dev->type = ARPHRD_HDLC; |
| 1027 |
break; |
| 1028 |
case SPPPIOCPPP: |
| 1029 |
sp->pp_flags&=~PP_CISCO; |
| 1030 |
dev->type = ARPHRD_PPP; |
| 1031 |
break; |
| 1032 |
case SPPPIOCDEBUG: |
| 1033 |
sp->pp_flags&=~PP_DEBUG; |
| 1034 |
if(ifr->ifr_flags) |
| 1035 |
sp->pp_flags|=PP_DEBUG; |
| 1036 |
break; |
| 1037 |
case SPPPIOCGFLAGS: |
| 1038 |
if(copy_to_user(ifr->ifr_data, &sp->pp_flags, sizeof(sp->pp_flags))) |
| 1039 |
return -EFAULT; |
| 1040 |
break; |
| 1041 |
case SPPPIOCSFLAGS: |
| 1042 |
if(copy_from_user(&sp->pp_flags, ifr->ifr_data, sizeof(sp->pp_flags))) |
| 1043 |
return -EFAULT; |
| 1044 |
break; |
| 1045 |
default: |
| 1046 |
return -EINVAL; |
| 1047 |
} |
| 1048 |
return 0; |
| 1049 |
} |
| 1050 |
|
| 1051 |
EXPORT_SYMBOL(sppp_do_ioctl); |
| 1052 |
|
| 1053 |
/** |
| 1054 |
* sppp_attach - attach synchronous PPP/HDLC to a device |
| 1055 |
* @pd: PPP device to initialise |
| 1056 |
* |
| 1057 |
* This initialises the PPP/HDLC support on an interface. At the |
| 1058 |
* time of calling the dev element must point to the network device |
| 1059 |
* that this interface is attached to. The interface should not yet |
| 1060 |
* be registered. |
| 1061 |
*/ |
| 1062 |
|
| 1063 |
void sppp_attach(struct ppp_device *pd) |
| 1064 |
{ |
| 1065 |
struct net_device *dev = pd->dev; |
| 1066 |
struct sppp *sp = &pd->sppp; |
| 1067 |
unsigned long flags; |
| 1068 |
|
| 1069 |
/* Make sure embedding is safe for sppp_of */ |
| 1070 |
BUG_ON(sppp_of(dev) != sp); |
| 1071 |
|
| 1072 |
spin_lock_irqsave(&spppq_lock, flags); |
| 1073 |
/* Initialize keepalive handler. */ |
| 1074 |
if (! spppq) |
| 1075 |
{ |
| 1076 |
init_timer(&sppp_keepalive_timer); |
| 1077 |
sppp_keepalive_timer.expires=jiffies+10*HZ; |
| 1078 |
sppp_keepalive_timer.function=sppp_keepalive; |
| 1079 |
add_timer(&sppp_keepalive_timer); |
| 1080 |
} |
| 1081 |
/* Insert new entry into the keepalive list. */ |
| 1082 |
sp->pp_next = spppq; |
| 1083 |
spppq = sp; |
| 1084 |
spin_unlock_irqrestore(&spppq_lock, flags); |
| 1085 |
|
| 1086 |
sp->pp_loopcnt = 0; |
| 1087 |
sp->pp_alivecnt = 0; |
| 1088 |
sp->pp_seq = 0; |
| 1089 |
sp->pp_rseq = 0; |
| 1090 |
sp->pp_flags = PP_KEEPALIVE|PP_CISCO|debug;/*PP_DEBUG;*/ |
| 1091 |
sp->lcp.magic = 0; |
| 1092 |
sp->lcp.state = LCP_STATE_CLOSED; |
| 1093 |
sp->ipcp.state = IPCP_STATE_CLOSED; |
| 1094 |
sp->pp_if = dev; |
| 1095 |
spin_lock_init(&sp->lock); |
| 1096 |
|
| 1097 |
/* |
| 1098 |
* Device specific setup. All but interrupt handler and |
| 1099 |
* hard_start_xmit. |
| 1100 |
*/ |
| 1101 |
|
| 1102 |
dev->hard_header = sppp_hard_header; |
| 1103 |
dev->rebuild_header = sppp_rebuild_header; |
| 1104 |
dev->tx_queue_len = 10; |
| 1105 |
dev->type = ARPHRD_HDLC; |
| 1106 |
dev->addr_len = 0; |
| 1107 |
dev->hard_header_len = sizeof(struct ppp_header); |
| 1108 |
dev->mtu = PPP_MTU; |
| 1109 |
/* |
| 1110 |
* These 4 are callers but MUST also call sppp_ functions |
| 1111 |
*/ |
| 1112 |
dev->do_ioctl = sppp_do_ioctl; |
| 1113 |
#if 0 |
| 1114 |
dev->get_stats = NULL; /* Let the driver override these */ |
| 1115 |
dev->open = sppp_open; |
| 1116 |
dev->stop = sppp_close; |
| 1117 |
#endif |
| 1118 |
dev->change_mtu = sppp_change_mtu; |
| 1119 |
dev->hard_header_cache = NULL; |
| 1120 |
dev->header_cache_update = NULL; |
| 1121 |
dev->flags = IFF_MULTICAST|IFF_POINTOPOINT|IFF_NOARP; |
| 1122 |
} |
| 1123 |
|
| 1124 |
EXPORT_SYMBOL(sppp_attach); |
| 1125 |
|
| 1126 |
/** |
| 1127 |
* sppp_detach - release PPP resources from a device |
| 1128 |
* @dev: Network device to release |
| 1129 |
* |
| 1130 |
* Stop and free up any PPP/HDLC resources used by this |
| 1131 |
* interface. This must be called before the device is |
| 1132 |
* freed. |
| 1133 |
*/ |
| 1134 |
|
| 1135 |
void sppp_detach (struct net_device *dev) |
| 1136 |
{ |
| 1137 |
struct sppp **q, *p, *sp = (struct sppp *)sppp_of(dev); |
| 1138 |
unsigned long flags; |
| 1139 |
|
| 1140 |
spin_lock_irqsave(&spppq_lock, flags); |
| 1141 |
/* Remove the entry from the keepalive list. */ |
| 1142 |
for (q = &spppq; (p = *q); q = &p->pp_next) |
| 1143 |
if (p == sp) { |
| 1144 |
*q = p->pp_next; |
| 1145 |
break; |
| 1146 |
} |
| 1147 |
|
| 1148 |
/* Stop keepalive handler. */ |
| 1149 |
if (! spppq) |
| 1150 |
del_timer(&sppp_keepalive_timer); |
| 1151 |
sppp_clear_timeout (sp); |
| 1152 |
spin_unlock_irqrestore(&spppq_lock, flags); |
| 1153 |
} |
| 1154 |
|
| 1155 |
EXPORT_SYMBOL(sppp_detach); |
| 1156 |
|
| 1157 |
/* |
| 1158 |
* Analyze the LCP Configure-Request options list |
| 1159 |
* for the presence of unknown options. |
| 1160 |
* If the request contains unknown options, build and |
| 1161 |
* send Configure-reject packet, containing only unknown options. |
| 1162 |
*/ |
| 1163 |
static int |
| 1164 |
sppp_lcp_conf_parse_options (struct sppp *sp, struct lcp_header *h, |
| 1165 |
int len, u32 *magic) |
| 1166 |
{ |
| 1167 |
u8 *buf, *r, *p; |
| 1168 |
int rlen; |
| 1169 |
|
| 1170 |
len -= 4; |
| 1171 |
buf = r = kmalloc (len, GFP_ATOMIC); |
| 1172 |
if (! buf) |
| 1173 |
return (0); |
| 1174 |
|
| 1175 |
p = (void*) (h+1); |
| 1176 |
for (rlen=0; len>1 && p[1]; len-=p[1], p+=p[1]) { |
| 1177 |
switch (*p) { |
| 1178 |
case LCP_OPT_MAGIC: |
| 1179 |
/* Magic number -- extract. */ |
| 1180 |
if (len >= 6 && p[1] == 6) { |
| 1181 |
*magic = (u32)p[2] << 24 | |
| 1182 |
(u32)p[3] << 16 | p[4] << 8 | p[5]; |
| 1183 |
continue; |
| 1184 |
} |
| 1185 |
break; |
| 1186 |
case LCP_OPT_ASYNC_MAP: |
| 1187 |
/* Async control character map -- check to be zero. */ |
| 1188 |
if (len >= 6 && p[1] == 6 && ! p[2] && ! p[3] && |
| 1189 |
! p[4] && ! p[5]) |
| 1190 |
continue; |
| 1191 |
break; |
| 1192 |
case LCP_OPT_MRU: |
| 1193 |
/* Maximum receive unit -- always OK. */ |
| 1194 |
continue; |
| 1195 |
default: |
| 1196 |
/* Others not supported. */ |
| 1197 |
break; |
| 1198 |
} |
| 1199 |
/* Add the option to rejected list. */ |
| 1200 |
memcpy(r, p, p[1]); |
| 1201 |
r += p[1]; |
| 1202 |
rlen += p[1]; |
| 1203 |
} |
| 1204 |
if (rlen) |
| 1205 |
sppp_cp_send (sp, PPP_LCP, LCP_CONF_REJ, h->ident, rlen, buf); |
| 1206 |
kfree(buf); |
| 1207 |
return (rlen == 0); |
| 1208 |
} |
| 1209 |
|
| 1210 |
static void sppp_ipcp_input (struct sppp *sp, struct sk_buff *skb) |
| 1211 |
{ |
| 1212 |
struct lcp_header *h; |
| 1213 |
struct net_device *dev = sp->pp_if; |
| 1214 |
int len = skb->len; |
| 1215 |
|
| 1216 |
if (!pskb_may_pull(skb, sizeof(struct lcp_header))) { |
| 1217 |
if (sp->pp_flags & PP_DEBUG) |
| 1218 |
printk (KERN_WARNING "%s: invalid ipcp packet length: %d bytes\n", |
| 1219 |
dev->name, len); |
| 1220 |
return; |
| 1221 |
} |
| 1222 |
h = (struct lcp_header *)skb->data; |
| 1223 |
skb_pull(skb,sizeof(struct lcp_header)); |
| 1224 |
if (sp->pp_flags & PP_DEBUG) { |
| 1225 |
printk (KERN_WARNING "%s: ipcp input: %d bytes <%s id=%xh len=%xh", |
| 1226 |
dev->name, len, |
| 1227 |
sppp_ipcp_type_name (h->type), h->ident, ntohs (h->len)); |
| 1228 |
if (len > 4) |
| 1229 |
sppp_print_bytes ((u8*) (h+1), len-4); |
| 1230 |
printk (">\n"); |
| 1231 |
} |
| 1232 |
if (len > ntohs (h->len)) |
| 1233 |
len = ntohs (h->len); |
| 1234 |
switch (h->type) { |
| 1235 |
default: |
| 1236 |
/* Unknown packet type -- send Code-Reject packet. */ |
| 1237 |
sppp_cp_send (sp, PPP_IPCP, IPCP_CODE_REJ, ++sp->pp_seq, len, h); |
| 1238 |
break; |
| 1239 |
case IPCP_CONF_REQ: |
| 1240 |
if (len < 4) { |
| 1241 |
if (sp->pp_flags & PP_DEBUG) |
| 1242 |
printk (KERN_WARNING "%s: invalid ipcp configure request packet length: %d bytes\n", |
| 1243 |
dev->name, len); |
| 1244 |
return; |
| 1245 |
} |
| 1246 |
if (len > 4) { |
| 1247 |
sppp_cp_send (sp, PPP_IPCP, LCP_CONF_REJ, h->ident, |
| 1248 |
len-4, h+1); |
| 1249 |
|
| 1250 |
switch (sp->ipcp.state) { |
| 1251 |
case IPCP_STATE_OPENED: |
| 1252 |
/* Initiate renegotiation. */ |
| 1253 |
sppp_ipcp_open (sp); |
| 1254 |
/* fall through... */ |
| 1255 |
case IPCP_STATE_ACK_SENT: |
| 1256 |
/* Go to closed state. */ |
| 1257 |
sp->ipcp.state = IPCP_STATE_CLOSED; |
| 1258 |
} |
| 1259 |
} else { |
| 1260 |
/* Send Configure-Ack packet. */ |
| 1261 |
sppp_cp_send (sp, PPP_IPCP, IPCP_CONF_ACK, h->ident, |
| 1262 |
0, NULL); |
| 1263 |
/* Change the state. */ |
| 1264 |
if (sp->ipcp.state == IPCP_STATE_ACK_RCVD) |
| 1265 |
sp->ipcp.state = IPCP_STATE_OPENED; |
| 1266 |
else |
| 1267 |
sp->ipcp.state = IPCP_STATE_ACK_SENT; |
| 1268 |
} |
| 1269 |
break; |
| 1270 |
case IPCP_CONF_ACK: |
| 1271 |
if (h->ident != sp->ipcp.confid) |
| 1272 |
break; |
| 1273 |
sppp_clear_timeout (sp); |
| 1274 |
switch (sp->ipcp.state) { |
| 1275 |
case IPCP_STATE_CLOSED: |
| 1276 |
sp->ipcp.state = IPCP_STATE_ACK_RCVD; |
| 1277 |
sppp_set_timeout (sp, 5); |
| 1278 |
break; |
| 1279 |
case IPCP_STATE_ACK_SENT: |
| 1280 |
sp->ipcp.state = IPCP_STATE_OPENED; |
| 1281 |
break; |
| 1282 |
} |
| 1283 |
break; |
| 1284 |
case IPCP_CONF_NAK: |
| 1285 |
case IPCP_CONF_REJ: |
| 1286 |
if (h->ident != sp->ipcp.confid) |
| 1287 |
break; |
| 1288 |
sppp_clear_timeout (sp); |
| 1289 |
/* Initiate renegotiation. */ |
| 1290 |
sppp_ipcp_open (sp); |
| 1291 |
if (sp->ipcp.state != IPCP_STATE_ACK_SENT) |
| 1292 |
/* Go to closed state. */ |
| 1293 |
sp->ipcp.state = IPCP_STATE_CLOSED; |
| 1294 |
break; |
| 1295 |
case IPCP_TERM_REQ: |
| 1296 |
/* Send Terminate-Ack packet. */ |
| 1297 |
sppp_cp_send (sp, PPP_IPCP, IPCP_TERM_ACK, h->ident, 0, NULL); |
| 1298 |
/* Go to closed state. */ |
| 1299 |
sp->ipcp.state = IPCP_STATE_CLOSED; |
| 1300 |
/* Initiate renegotiation. */ |
| 1301 |
sppp_ipcp_open (sp); |
| 1302 |
break; |
| 1303 |
case IPCP_TERM_ACK: |
| 1304 |
/* Ignore for now. */ |
| 1305 |
case IPCP_CODE_REJ: |
| 1306 |
/* Ignore for now. */ |
| 1307 |
break; |
| 1308 |
} |
| 1309 |
} |
| 1310 |
|
| 1311 |
static void sppp_lcp_open (struct sppp *sp) |
| 1312 |
{ |
| 1313 |
char opt[6]; |
| 1314 |
|
| 1315 |
if (! sp->lcp.magic) |
| 1316 |
sp->lcp.magic = jiffies; |
| 1317 |
opt[0] = LCP_OPT_MAGIC; |
| 1318 |
opt[1] = sizeof (opt); |
| 1319 |
opt[2] = sp->lcp.magic >> 24; |
| 1320 |
opt[3] = sp->lcp.magic >> 16; |
| 1321 |
opt[4] = sp->lcp.magic >> 8; |
| 1322 |
opt[5] = sp->lcp.magic; |
| 1323 |
sp->lcp.confid = ++sp->pp_seq; |
| 1324 |
sppp_cp_send (sp, PPP_LCP, LCP_CONF_REQ, sp->lcp.confid, |
| 1325 |
sizeof (opt), &opt); |
| 1326 |
sppp_set_timeout (sp, 2); |
| 1327 |
} |
| 1328 |
|
| 1329 |
static void sppp_ipcp_open (struct sppp *sp) |
| 1330 |
{ |
| 1331 |
sp->ipcp.confid = ++sp->pp_seq; |
| 1332 |
sppp_cp_send (sp, PPP_IPCP, IPCP_CONF_REQ, sp->ipcp.confid, 0, NULL); |
| 1333 |
sppp_set_timeout (sp, 2); |
| 1334 |
} |
| 1335 |
|
| 1336 |
/* |
| 1337 |
* Process PPP control protocol timeouts. |
| 1338 |
*/ |
| 1339 |
|
| 1340 |
static void sppp_cp_timeout (unsigned long arg) |
| 1341 |
{ |
| 1342 |
struct sppp *sp = (struct sppp*) arg; |
| 1343 |
unsigned long flags; |
| 1344 |
|
| 1345 |
spin_lock_irqsave(&sp->lock, flags); |
| 1346 |
|
| 1347 |
sp->pp_flags &= ~PP_TIMO; |
| 1348 |
if (! (sp->pp_if->flags & IFF_UP) || (sp->pp_flags & PP_CISCO)) { |
| 1349 |
spin_unlock_irqrestore(&sp->lock, flags); |
| 1350 |
return; |
| 1351 |
} |
| 1352 |
switch (sp->lcp.state) { |
| 1353 |
case LCP_STATE_CLOSED: |
| 1354 |
/* No ACK for Configure-Request, retry. */ |
| 1355 |
sppp_lcp_open (sp); |
| 1356 |
break; |
| 1357 |
case LCP_STATE_ACK_RCVD: |
| 1358 |
/* ACK got, but no Configure-Request for peer, retry. */ |
| 1359 |
sppp_lcp_open (sp); |
| 1360 |
sp->lcp.state = LCP_STATE_CLOSED; |
| 1361 |
break; |
| 1362 |
case LCP_STATE_ACK_SENT: |
| 1363 |
/* ACK sent but no ACK for Configure-Request, retry. */ |
| 1364 |
sppp_lcp_open (sp); |
| 1365 |
break; |
| 1366 |
case LCP_STATE_OPENED: |
| 1367 |
/* LCP is already OK, try IPCP. */ |
| 1368 |
switch (sp->ipcp.state) { |
| 1369 |
case IPCP_STATE_CLOSED: |
| 1370 |
/* No ACK for Configure-Request, retry. */ |
| 1371 |
sppp_ipcp_open (sp); |
| 1372 |
break; |
| 1373 |
case IPCP_STATE_ACK_RCVD: |
| 1374 |
/* ACK got, but no Configure-Request for peer, retry. */ |
| 1375 |
sppp_ipcp_open (sp); |
| 1376 |
sp->ipcp.state = IPCP_STATE_CLOSED; |
| 1377 |
break; |
| 1378 |
case IPCP_STATE_ACK_SENT: |
| 1379 |
/* ACK sent but no ACK for Configure-Request, retry. */ |
| 1380 |
sppp_ipcp_open (sp); |
| 1381 |
break; |
| 1382 |
case IPCP_STATE_OPENED: |
| 1383 |
/* IPCP is OK. */ |
| 1384 |
break; |
| 1385 |
} |
| 1386 |
break; |
| 1387 |
} |
| 1388 |
spin_unlock_irqrestore(&sp->lock, flags); |
| 1389 |
sppp_flush_xmit(); |
| 1390 |
} |
| 1391 |
|
| 1392 |
static char *sppp_lcp_type_name (u8 type) |
| 1393 |
{ |
| 1394 |
static char buf [8]; |
| 1395 |
switch (type) { |
| 1396 |
case LCP_CONF_REQ: return ("conf-req"); |
| 1397 |
case LCP_CONF_ACK: return ("conf-ack"); |
| 1398 |
case LCP_CONF_NAK: return ("conf-nack"); |
| 1399 |
case LCP_CONF_REJ: return ("conf-rej"); |
| 1400 |
case LCP_TERM_REQ: return ("term-req"); |
| 1401 |
case LCP_TERM_ACK: return ("term-ack"); |
| 1402 |
case LCP_CODE_REJ: return ("code-rej"); |
| 1403 |
case LCP_PROTO_REJ: return ("proto-rej"); |
| 1404 |
case LCP_ECHO_REQ: return ("echo-req"); |
| 1405 |
case LCP_ECHO_REPLY: return ("echo-reply"); |
| 1406 |
case LCP_DISC_REQ: return ("discard-req"); |
| 1407 |
} |
| 1408 |
sprintf (buf, "%xh", type); |
| 1409 |
return (buf); |
| 1410 |
} |
| 1411 |
|
| 1412 |
static char *sppp_ipcp_type_name (u8 type) |
| 1413 |
{ |
| 1414 |
static char buf [8]; |
| 1415 |
switch (type) { |
| 1416 |
case IPCP_CONF_REQ: return ("conf-req"); |
| 1417 |
case IPCP_CONF_ACK: return ("conf-ack"); |
| 1418 |
case IPCP_CONF_NAK: return ("conf-nack"); |
| 1419 |
case IPCP_CONF_REJ: return ("conf-rej"); |
| 1420 |
case IPCP_TERM_REQ: return ("term-req"); |
| 1421 |
case IPCP_TERM_ACK: return ("term-ack"); |
| 1422 |
case IPCP_CODE_REJ: return ("code-rej"); |
| 1423 |
} |
| 1424 |
sprintf (buf, "%xh", type); |
| 1425 |
return (buf); |
| 1426 |
} |
| 1427 |
|
| 1428 |
static void sppp_print_bytes (u_char *p, u16 len) |
| 1429 |
{ |
| 1430 |
printk (" %x", *p++); |
| 1431 |
while (--len > 0) |
| 1432 |
printk ("-%x", *p++); |
| 1433 |
} |
| 1434 |
|
| 1435 |
/** |
| 1436 |
* sppp_rcv - receive and process a WAN PPP frame |
| 1437 |
* @skb: The buffer to process |
| 1438 |
* @dev: The device it arrived on |
| 1439 |
* @p: Unused |
| 1440 |
* @orig_dev: Unused |
| 1441 |
* |
| 1442 |
* Protocol glue. This drives the deferred processing mode the poorer |
| 1443 |
* cards use. This can be called directly by cards that do not have |
| 1444 |
* timing constraints but is normally called from the network layer |
| 1445 |
* after interrupt servicing to process frames queued via netif_rx. |
| 1446 |
*/ |
| 1447 |
|
| 1448 |
static int sppp_rcv(struct sk_buff *skb, struct net_device *dev, struct packet_type *p, struct net_device *orig_dev) |
| 1449 |
{ |
| 1450 |
if ((skb = skb_share_check(skb, GFP_ATOMIC)) == NULL) |
| 1451 |
return NET_RX_DROP; |
| 1452 |
sppp_input(dev,skb); |
| 1453 |
return 0; |
| 1454 |
} |
| 1455 |
|
| 1456 |
static struct packet_type sppp_packet_type = { |
| 1457 |
.type = __constant_htons(ETH_P_WAN_PPP), |
| 1458 |
.func = sppp_rcv, |
| 1459 |
}; |
| 1460 |
|
| 1461 |
static char banner[] __initdata = |
| 1462 |
KERN_INFO "Cronyx Ltd, Synchronous PPP and CISCO HDLC (c) 1994\n" |
| 1463 |
KERN_INFO "Linux port (c) 1998 Building Number Three Ltd & " |
| 1464 |
"Jan \"Yenya\" Kasprzak.\n"; |
| 1465 |
|
| 1466 |
static int __init sync_ppp_init(void) |
| 1467 |
{ |
| 1468 |
if(debug) |
| 1469 |
debug=PP_DEBUG; |
| 1470 |
printk(banner); |
| 1471 |
skb_queue_head_init(&tx_queue); |
| 1472 |
dev_add_pack(&sppp_packet_type); |
| 1473 |
return 0; |
| 1474 |
} |
| 1475 |
|
| 1476 |
|
| 1477 |
static void __exit sync_ppp_cleanup(void) |
| 1478 |
{ |
| 1479 |
dev_remove_pack(&sppp_packet_type); |
| 1480 |
} |
| 1481 |
|
| 1482 |
module_init(sync_ppp_init); |
| 1483 |
module_exit(sync_ppp_cleanup); |
| 1484 |
module_param(debug, int, 0); |
| 1485 |
MODULE_LICENSE("GPL v2"); |