hdlc_ppp.c (0612ec48762bf8712db1925b2e67246d2237ebab) | hdlc_ppp.c (eb2a2fd91f7c8a53b15063d6f08cf22b9a56cbfb) |
---|---|
1/* 2 * Generic HDLC support routines for Linux 3 * Point-to-point protocol support 4 * | 1/* 2 * Generic HDLC support routines for Linux 3 * Point-to-point protocol support 4 * |
5 * Copyright (C) 1999 - 2003 Krzysztof Halasa <khc@pm.waw.pl> | 5 * Copyright (C) 1999 - 2006 Krzysztof Halasa <khc@pm.waw.pl> |
6 * 7 * This program is free software; you can redistribute it and/or modify it 8 * under the terms of version 2 of the GNU General Public License 9 * as published by the Free Software Foundation. 10 */ 11 12#include <linux/module.h> 13#include <linux/kernel.h> 14#include <linux/slab.h> 15#include <linux/poll.h> 16#include <linux/errno.h> 17#include <linux/if_arp.h> 18#include <linux/init.h> 19#include <linux/skbuff.h> 20#include <linux/pkt_sched.h> 21#include <linux/inetdevice.h> 22#include <linux/lapb.h> 23#include <linux/rtnetlink.h> 24#include <linux/hdlc.h> | 6 * 7 * This program is free software; you can redistribute it and/or modify it 8 * under the terms of version 2 of the GNU General Public License 9 * as published by the Free Software Foundation. 10 */ 11 12#include <linux/module.h> 13#include <linux/kernel.h> 14#include <linux/slab.h> 15#include <linux/poll.h> 16#include <linux/errno.h> 17#include <linux/if_arp.h> 18#include <linux/init.h> 19#include <linux/skbuff.h> 20#include <linux/pkt_sched.h> 21#include <linux/inetdevice.h> 22#include <linux/lapb.h> 23#include <linux/rtnetlink.h> 24#include <linux/hdlc.h> |
25#include <net/syncppp.h> |
|
25 | 26 |
27struct ppp_state { 28 struct ppp_device pppdev; 29 struct ppp_device *syncppp_ptr; 30 int (*old_change_mtu)(struct net_device *dev, int new_mtu); 31}; |
|
26 | 32 |
33static int ppp_ioctl(struct net_device *dev, struct ifreq *ifr); 34 35 36static inline struct ppp_state* state(hdlc_device *hdlc) 37{ 38 return(struct ppp_state *)(hdlc->state); 39} 40 41 |
|
27static int ppp_open(struct net_device *dev) 28{ 29 hdlc_device *hdlc = dev_to_hdlc(dev); 30 void *old_ioctl; 31 int result; 32 | 42static int ppp_open(struct net_device *dev) 43{ 44 hdlc_device *hdlc = dev_to_hdlc(dev); 45 void *old_ioctl; 46 int result; 47 |
33 dev->priv = &hdlc->state.ppp.syncppp_ptr; 34 hdlc->state.ppp.syncppp_ptr = &hdlc->state.ppp.pppdev; 35 hdlc->state.ppp.pppdev.dev = dev; | 48 dev->priv = &state(hdlc)->syncppp_ptr; 49 state(hdlc)->syncppp_ptr = &state(hdlc)->pppdev; 50 state(hdlc)->pppdev.dev = dev; |
36 37 old_ioctl = dev->do_ioctl; | 51 52 old_ioctl = dev->do_ioctl; |
38 hdlc->state.ppp.old_change_mtu = dev->change_mtu; 39 sppp_attach(&hdlc->state.ppp.pppdev); | 53 state(hdlc)->old_change_mtu = dev->change_mtu; 54 sppp_attach(&state(hdlc)->pppdev); |
40 /* sppp_attach nukes them. We don't need syncppp's ioctl */ 41 dev->do_ioctl = old_ioctl; | 55 /* sppp_attach nukes them. We don't need syncppp's ioctl */ 56 dev->do_ioctl = old_ioctl; |
42 hdlc->state.ppp.pppdev.sppp.pp_flags &= ~PP_CISCO; | 57 state(hdlc)->pppdev.sppp.pp_flags &= ~PP_CISCO; |
43 dev->type = ARPHRD_PPP; 44 result = sppp_open(dev); 45 if (result) { 46 sppp_detach(dev); 47 return result; 48 } 49 50 return 0; 51} 52 53 54 55static void ppp_close(struct net_device *dev) 56{ 57 hdlc_device *hdlc = dev_to_hdlc(dev); 58 59 sppp_close(dev); 60 sppp_detach(dev); 61 dev->rebuild_header = NULL; | 58 dev->type = ARPHRD_PPP; 59 result = sppp_open(dev); 60 if (result) { 61 sppp_detach(dev); 62 return result; 63 } 64 65 return 0; 66} 67 68 69 70static void ppp_close(struct net_device *dev) 71{ 72 hdlc_device *hdlc = dev_to_hdlc(dev); 73 74 sppp_close(dev); 75 sppp_detach(dev); 76 dev->rebuild_header = NULL; |
62 dev->change_mtu = hdlc->state.ppp.old_change_mtu; | 77 dev->change_mtu = state(hdlc)->old_change_mtu; |
63 dev->mtu = HDLC_MAX_MTU; 64 dev->hard_header_len = 16; 65} 66 67 68 69static __be16 ppp_type_trans(struct sk_buff *skb, struct net_device *dev) 70{ 71 return __constant_htons(ETH_P_WAN_PPP); 72} 73 74 75 | 78 dev->mtu = HDLC_MAX_MTU; 79 dev->hard_header_len = 16; 80} 81 82 83 84static __be16 ppp_type_trans(struct sk_buff *skb, struct net_device *dev) 85{ 86 return __constant_htons(ETH_P_WAN_PPP); 87} 88 89 90 |
76int hdlc_ppp_ioctl(struct net_device *dev, struct ifreq *ifr) | 91static struct hdlc_proto proto = { 92 .open = ppp_open, 93 .close = ppp_close, 94 .type_trans = ppp_type_trans, 95 .ioctl = ppp_ioctl, 96 .module = THIS_MODULE, 97}; 98 99 100static int ppp_ioctl(struct net_device *dev, struct ifreq *ifr) |
77{ 78 hdlc_device *hdlc = dev_to_hdlc(dev); 79 int result; 80 81 switch (ifr->ifr_settings.type) { 82 case IF_GET_PROTO: | 101{ 102 hdlc_device *hdlc = dev_to_hdlc(dev); 103 int result; 104 105 switch (ifr->ifr_settings.type) { 106 case IF_GET_PROTO: |
107 if (dev_to_hdlc(dev)->proto != &proto) 108 return -EINVAL; |
|
83 ifr->ifr_settings.type = IF_PROTO_PPP; 84 return 0; /* return protocol only, no settable parameters */ 85 86 case IF_PROTO_PPP: 87 if(!capable(CAP_NET_ADMIN)) 88 return -EPERM; 89 90 if(dev->flags & IFF_UP) 91 return -EBUSY; 92 93 /* no settable parameters */ 94 95 result=hdlc->attach(dev, ENCODING_NRZ,PARITY_CRC16_PR1_CCITT); 96 if (result) 97 return result; 98 | 109 ifr->ifr_settings.type = IF_PROTO_PPP; 110 return 0; /* return protocol only, no settable parameters */ 111 112 case IF_PROTO_PPP: 113 if(!capable(CAP_NET_ADMIN)) 114 return -EPERM; 115 116 if(dev->flags & IFF_UP) 117 return -EBUSY; 118 119 /* no settable parameters */ 120 121 result=hdlc->attach(dev, ENCODING_NRZ,PARITY_CRC16_PR1_CCITT); 122 if (result) 123 return result; 124 |
99 hdlc_proto_detach(hdlc); 100 memset(&hdlc->proto, 0, sizeof(hdlc->proto)); 101 102 hdlc->proto.open = ppp_open; 103 hdlc->proto.close = ppp_close; 104 hdlc->proto.type_trans = ppp_type_trans; 105 hdlc->proto.id = IF_PROTO_PPP; | 125 result = attach_hdlc_protocol(dev, &proto, NULL, 126 sizeof(struct ppp_state)); 127 if (result) 128 return result; |
106 dev->hard_start_xmit = hdlc->xmit; 107 dev->hard_header = NULL; 108 dev->type = ARPHRD_PPP; 109 dev->addr_len = 0; 110 netif_dormant_off(dev); 111 return 0; 112 } 113 114 return -EINVAL; 115} | 129 dev->hard_start_xmit = hdlc->xmit; 130 dev->hard_header = NULL; 131 dev->type = ARPHRD_PPP; 132 dev->addr_len = 0; 133 netif_dormant_off(dev); 134 return 0; 135 } 136 137 return -EINVAL; 138} |
139 140 141static int __init mod_init(void) 142{ 143 register_hdlc_protocol(&proto); 144 return 0; 145} 146 147 148 149static void __exit mod_exit(void) 150{ 151 unregister_hdlc_protocol(&proto); 152} 153 154 155module_init(mod_init); 156module_exit(mod_exit); 157 158MODULE_AUTHOR("Krzysztof Halasa <khc@pm.waw.pl>"); 159MODULE_DESCRIPTION("PPP protocol support for generic HDLC"); 160MODULE_LICENSE("GPL v2"); |
|