1 /* pppoatm.c - pppd plugin to implement PPPoATM protocol.
3 * Copyright 2000 Mitchell Blank Jr.
4 * Based in part on work from Jens Axboe and Paul Mackerras.
5 * Updated to ppp-2.4.1 by Bernhard Kaindl
7 * Updated to ppp-2.4.2 by David Woodhouse 2004.
8 * - disconnect method added
9 * - remove_options() abuse removed.
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License
13 * as published by the Free Software Foundation; either version
14 * 2 of the License, or (at your option) any later version.
21 #include <linux/atmdev.h>
22 #include <linux/atmppp.h>
25 #include <sys/ioctl.h>
26 #include <sys/param.h>
30 #include <pppd/pppd.h>
31 #include <pppd/options.h>
32 #include <pppd/fsm.h> /* Needed for lcp.h to include cleanly */
36 const char pppd_version[] = PPPD_VERSION;
38 static struct sockaddr_atmpvc pvcaddr;
39 static char *qosstr = NULL;
40 static bool llc_encaps = 0;
41 static bool vc_encaps = 0;
42 static int device_got_set = 0;
43 static int pppoatm_max_mtu, pppoatm_max_mru;
44 static int setdevname_pppoatm(const char *cp, const char **argv, int doit);
45 struct channel pppoa_channel;
46 static int pppoa_fd = -1;
47 static char devnam[MAXNAMELEN];
49 static struct option pppoa_options[] = {
50 { "device name", o_wild, (void *) &setdevname_pppoatm,
51 "ATM service provider IDs: VPI.VCI",
52 OPT_DEVNAM | OPT_PRIVFIX | OPT_NOARG | OPT_A2STRVAL | OPT_STATIC,
54 { "llc-encaps", o_bool, &llc_encaps,
55 "use LLC encapsulation for PPPoATM", 1},
56 { "vc-encaps", o_bool, &vc_encaps,
57 "use VC multiplexing for PPPoATM (default)", 1},
58 { "qos", o_string, &qosstr,
59 "set QoS for PPPoATM connection", 1},
64 * -1 if there's a problem with setting the device
65 * 0 if we can't parse "cp" as a valid name of a device
66 * 1 if "cp" is a reasonable thing to name a device
67 * Note that we don't actually open the device at this point
68 * We do need to fill in:
69 * devnam: a string representation of the device
70 * devstat: a stat structure of the device. In this case
71 * we're not opening a device, so we just make sure
72 * to set up S_ISCHR(devstat.st_mode) != 1, so we
73 * don't get confused that we're on stdin.
75 int (*old_setdevname_hook)(const char* cp) = NULL;
76 static int setdevname_pppoatm(const char *cp, const char **argv, int doit)
78 struct sockaddr_atmpvc addr;
79 extern struct stat devstat;
84 memset(&addr, 0, sizeof addr);
85 if (text2atm(cp, (struct sockaddr *) &addr, sizeof(addr),
86 T2A_PVC | T2A_NAME | T2A_WILDCARD) < 0) {
88 info("cannot parse the ATM address: %s", cp);
94 memcpy(&pvcaddr, &addr, sizeof pvcaddr);
95 strlcpy(devnam, cp, sizeof(devnam));
96 ppp_set_devnam(devnam);
97 devstat.st_mode = S_IFSOCK;
98 if (the_channel != &pppoa_channel) {
99 the_channel = &pppoa_channel;
100 lcp_wantoptions[0].neg_accompression = 0;
101 lcp_allowoptions[0].neg_accompression = 0;
102 lcp_wantoptions[0].neg_asyncmap = 0;
103 lcp_allowoptions[0].neg_asyncmap = 0;
104 lcp_wantoptions[0].neg_pcompression = 0;
110 #define pppoatm_overhead() (llc_encaps ? 6 : 2)
112 static void no_device_given_pppoatm(void)
114 fatal("No vpi.vci specified");
117 static void set_line_discipline_pppoatm(int fd)
119 struct atm_backend_ppp be;
121 be.backend_num = ATM_BACKEND_PPP;
123 be.encaps = PPPOATM_ENCAPS_VC;
125 be.encaps = PPPOATM_ENCAPS_LLC;
127 be.encaps = PPPOATM_ENCAPS_AUTODETECT;
129 if (ioctl(fd, ATM_SETBACKEND, &be) < 0)
130 fatal("ioctl(ATM_SETBACKEND): %m");
134 static void reset_line_discipline_pppoatm(int fd)
136 atm_backend_t be = ATM_BACKEND_RAW;
137 /* 2.4 doesn't support this yet */
138 (void) ioctl(fd, ATM_SETBACKEND, &be);
142 static int connect_pppoatm(void)
148 no_device_given_pppoatm();
149 fd = socket(AF_ATMPVC, SOCK_DGRAM, 0);
151 fatal("failed to create socket: %m");
152 memset(&qos, 0, sizeof qos);
153 qos.txtp.traffic_class = qos.rxtp.traffic_class = ATM_UBR;
154 /* TODO: support simplified QoS setting */
156 if (text2qos(qosstr, &qos, 0))
157 fatal("Can't parse QoS: \"%s\"");
158 qos.txtp.max_sdu = lcp_allowoptions[0].mru + pppoatm_overhead();
159 qos.rxtp.max_sdu = lcp_wantoptions[0].mru + pppoatm_overhead();
161 if (setsockopt(fd, SOL_ATM, SO_ATMQOS, &qos, sizeof(qos)) < 0)
162 fatal("setsockopt(SO_ATMQOS): %m");
163 /* TODO: accept on SVCs... */
164 if (connect(fd, (struct sockaddr *) &pvcaddr,
165 sizeof(struct sockaddr_atmpvc)))
166 fatal("connect(%s): %m", devnam);
167 pppoatm_max_mtu = lcp_allowoptions[0].mru;
168 pppoatm_max_mru = lcp_wantoptions[0].mru;
169 set_line_discipline_pppoatm(fd);
170 ppp_set_pppdevnam(devnam);
175 static void disconnect_pppoatm(void)
180 void plugin_init(void)
183 extern int new_style_driver; /* From sys-linux.c */
184 if (!ppp_check_kernel_support() && !new_style_driver)
185 fatal("Kernel doesn't support ppp_generic - "
186 "needed for PPPoATM");
188 fatal("No PPPoATM support on this OS");
190 ppp_add_options(pppoa_options);
193 struct channel pppoa_channel = {
194 .options = pppoa_options,
195 .process_extra_options = NULL,
196 .check_options = NULL,
197 .connect = &connect_pppoatm,
198 .disconnect = &disconnect_pppoatm,
199 .establish_ppp = &ppp_generic_establish,
200 .disestablish_ppp = &ppp_generic_disestablish,