dfb1de0205f02309d256fd253787badcf6c82991
[openwrt/svn-archive/archive.git] / package / linux-atm / patches / 100-br2684.patch
1 diff -ruN linux-atm-2.4.1/configure.in linux-atm-2.4.1.new/configure.in
2 --- linux-atm-2.4.1/configure.in 2003-04-25 04:17:05.000000000 +0200
3 +++ linux-atm-2.4.1.new/configure.in 2005-07-27 15:45:49.532396543 +0200
4 @@ -153,26 +153,6 @@
5 src/Makefile \
6 src/include/Makefile \
7 src/lib/Makefile \
8 - src/test/Makefile \
9 - src/debug/Makefile \
10 - src/qgen/Makefile \
11 - src/saal/Makefile \
12 - src/sigd/Makefile \
13 - src/maint/Makefile \
14 - src/arpd/Makefile \
15 - src/ilmid/Makefile \
16 - src/ilmid/asn1/Makefile \
17 - src/man/Makefile \
18 - src/led/Makefile \
19 - src/lane/Makefile \
20 - src/mpoad/Makefile \
21 - src/switch/Makefile \
22 - src/switch/debug/Makefile \
23 - src/switch/tcp/Makefile \
24 - src/config/Makefile \
25 - src/config/init-redhat/Makefile \
26 - src/extra/Makefile \
27 - src/extra/linux-atm.spec \
28 - src/extra/ANS/Makefile
29 + src/br2684/Makefile \
30 )
31
32 diff -ruN linux-atm-2.4.1/src/br2684/Makefile linux-atm-2.4.1.new/src/br2684/Makefile
33 --- linux-atm-2.4.1/src/br2684/Makefile 1970-01-01 02:00:00.000000000 +0200
34 +++ linux-atm-2.4.1.new/src/br2684/Makefile 2002-07-15 23:44:25.000000000 +0200
35 @@ -0,0 +1,13 @@
36 +PREFIX=${TI_FILESYSTEM}
37 +
38 +all: br2684ctl
39 +
40 +br2684ctl: br2684ctl.c
41 + gcc -latm -o br2684ctl br2684ctl.c
42 + strip br2684ctl
43 +
44 +install: br2684ctl
45 + cp br2684ctl $(PREFIX)/usr/sbin/
46 +
47 +clean:
48 + rm -rf br2684ctl *.o
49 diff -ruN linux-atm-2.4.1/src/Makefile.am linux-atm-2.4.1.new/src/Makefile.am
50 --- linux-atm-2.4.1/src/Makefile.am 2001-10-03 23:14:53.000000000 +0200
51 +++ linux-atm-2.4.1.new/src/Makefile.am 2005-07-27 15:33:52.389309711 +0200
52 @@ -1,3 +1,2 @@
53 -SUBDIRS = include lib test debug qgen saal sigd maint arpd ilmid man led lane \
54 - mpoad switch config extra
55 +SUBDIRS = include lib br2684
56
57
58 diff -Nur linux-atm-2.4.1.orig/src/include/linux/atmbr2684.h linux-atm-2.4.1/src/include/linux/atmbr2684.h
59 --- linux-atm-2.4.1.orig/src/include/linux/atmbr2684.h 1970-01-01 01:00:00.000000000 +0100
60 +++ linux-atm-2.4.1/src/include/linux/atmbr2684.h 2005-11-13 00:06:42.000000000 +0100
61 @@ -0,0 +1,117 @@
62 +#ifndef _LINUX_ATMBR2684_H
63 +#define _LINUX_ATMBR2684_H
64 +
65 +#include <linux/atm.h>
66 +#include <linux/if.h> /* For IFNAMSIZ */
67 +#include <linux/if_ether.h> /* ETH_P_* */
68 +
69 +/*
70 + * Type of media we're bridging (ethernet, token ring, etc) Currently only
71 + * ethernet is supported
72 + */
73 +#define BR2684_MEDIA_ETHERNET (0) /* 802.3 */
74 +#define BR2684_MEDIA_802_4 (1) /* 802.4 */
75 +#define BR2684_MEDIA_TR (2) /* 802.5 - token ring */
76 +#define BR2684_MEDIA_FDDI (3)
77 +#define BR2684_MEDIA_802_6 (4) /* 802.6 */
78 +
79 +/*
80 + * Is there FCS inbound on this VC? This currently isn't supported.
81 + */
82 +#define BR2684_FCSIN_NO (0)
83 +#define BR2684_FCSIN_IGNORE (1)
84 +#define BR2684_FCSIN_VERIFY (2)
85 +
86 +/*
87 + * Is there FCS outbound on this VC? This currently isn't supported.
88 + */
89 +#define BR2684_FCSOUT_NO (0)
90 +#define BR2684_FCSOUT_SENDZERO (1)
91 +#define BR2684_FCSOUT_GENERATE (2)
92 +
93 +/*
94 + * Does this VC include LLC encapsulation?
95 + */
96 +#define BR2684_ENCAPS_VC (0) /* VC-mux */
97 +#define BR2684_ENCAPS_LLC (1)
98 +#define BR2684_ENCAPS_AUTODETECT (2) /* Unsuported */
99 +
100 +/*
101 + * Is this VC bridged or routed?
102 + */
103 +
104 +#define BR2684_PAYLOAD_ROUTED (0)
105 +#define BR2684_PAYLOAD_BRIDGED (1)
106 +
107 +
108 +/*
109 + * This is for the ATM_NEWBACKENDIF call - these are like socket families:
110 + * the first element of the structure is the backend number and the rest
111 + * is per-backend specific
112 + */
113 +struct atm_newif_br2684 {
114 + atm_backend_t backend_num; /* ATM_BACKEND_BR2684 */
115 + int media; /* BR2684_MEDIA_* */
116 + char ifname[IFNAMSIZ];
117 + int mtu;
118 + int payload; /* bridged or routed */
119 +};
120 +
121 +/*
122 + * This structure is used to specify a br2684 interface - either by a
123 + * positive integer (returned by ATM_NEWBACKENDIF) or the interfaces name
124 + */
125 +#define BR2684_FIND_BYNOTHING (0)
126 +#define BR2684_FIND_BYNUM (1)
127 +#define BR2684_FIND_BYIFNAME (2)
128 +struct br2684_if_spec {
129 + int method; /* BR2684_FIND_* */
130 + union {
131 + char ifname[IFNAMSIZ];
132 + int devnum;
133 + } spec;
134 +};
135 +
136 +/*
137 + * This is for the ATM_SETBACKEND call - these are like socket families:
138 + * the first element of the structure is the backend number and the rest
139 + * is per-backend specific
140 + */
141 +struct atm_backend_br2684 {
142 + atm_backend_t backend_num; /* ATM_BACKEND_BR2684 */
143 + struct br2684_if_spec ifspec;
144 + int fcs_in; /* BR2684_FCSIN_* */
145 + int fcs_out; /* BR2684_FCSOUT_* */
146 + int fcs_auto; /* 1: fcs_{in,out} disabled if no FCS rx'ed */
147 + int encaps; /* BR2684_ENCAPS_* */
148 + int payload; /* BR2684_PAYLOAD_* */
149 + int has_vpiid; /* 1: use vpn_id - Unsupported */
150 + __u8 vpn_id[7];
151 + int send_padding; /* unsupported */
152 + int min_size; /* we will pad smaller packets than this */
153 +};
154 +
155 +/*
156 + * The BR2684_SETFILT ioctl is an experimental mechanism for folks
157 + * terminating a large number of IP-only vcc's. When netfilter allows
158 + * efficient per-if in/out filters, this support will be removed
159 + */
160 +struct br2684_filter {
161 + __u32 prefix; /* network byte order */
162 + __u32 netmask; /* 0 = disable filter */
163 +};
164 +
165 +struct br2684_filter_set {
166 + struct br2684_if_spec ifspec;
167 + struct br2684_filter filter;
168 +};
169 +
170 +enum br2684_payload {
171 + p_routed = BR2684_PAYLOAD_ROUTED,
172 + p_bridged = BR2684_PAYLOAD_BRIDGED,
173 +};
174 +
175 +#define BR2684_SETFILT _IOW( 'a', ATMIOC_BACKEND + 0, \
176 + struct br2684_filter_set)
177 +
178 +#endif /* _LINUX_ATMBR2684_H */
179 --- linux-atm-2.4.1/src/br2684/br2684ctl.c 1970-01-01 01:00:00.000000000 +0100
180 +++ linux-atm-2.4.1.new/src/br2684/br2684ctl.c 2006-02-07 14:19:42.000000000 +0100
181 @@ -0,0 +1,307 @@
182 +#include <stdio.h>
183 +#include <stdlib.h>
184 +#include <unistd.h>
185 +#include <errno.h>
186 +#include <sys/ioctl.h>
187 +#include <string.h>
188 +#include <syslog.h>
189 +#include <atm.h>
190 +#include <linux/atmdev.h>
191 +#include <linux/atmbr2684.h>
192 +
193 +/* Written by Marcell GAL <cell@sch.bme.hu> to make use of the */
194 +/* ioctls defined in the br2684... kernel patch */
195 +/* Compile with cc -o br2684ctl br2684ctl.c -latm */
196 +
197 +/*
198 + Modified feb 2001 by Stephen Aaskov (saa@lasat.com)
199 + - Added daemonization code
200 + - Added syslog
201 +
202 + TODO: Delete interfaces after exit?
203 +*/
204 +
205 +
206 +#define LOG_NAME "RFC1483/2684 bridge"
207 +#define LOG_OPTION LOG_PERROR
208 +#define LOG_FACILITY LOG_LOCAL0
209 +
210 +
211 +int lastsock, lastitf;
212 +
213 +void fatal(char *str, int i)
214 +{
215 + syslog(LOG_ERR, "Fatal: %s", str);
216 + exit(-2);
217 +};
218 +
219 +
220 +void exitFunc(void)
221 +{
222 + syslog(LOG_PID, "Daemon terminated\n");
223 +}
224 +
225 +
226 +int create_pidfile(char *nstr)
227 +{
228 + FILE *pidfile = NULL;
229 + char name[20];
230 + int num;
231 +
232 + if (nstr == NULL)
233 + return -1;
234 + num = atoi(nstr);
235 + if (num < 0)
236 + return -1;
237 +
238 + snprintf(name, 20, "/var/run/nas%d.pid", num);
239 + pidfile = fopen(name, "w");
240 + if (pidfile == NULL)
241 + return -1;
242 + fprintf(pidfile, "%d", getpid());
243 + fclose(pidfile);
244 +
245 + return 0;
246 +}
247 +
248 +int create_br(char *nstr, int payload)
249 +{
250 + int num, err;
251 +
252 + if (lastsock < 0) {
253 + lastsock = socket(PF_ATMPVC, SOCK_DGRAM, ATM_AAL5);
254 + }
255 + if (lastsock < 0) {
256 + syslog(LOG_ERR, "socket creation failed: %s",
257 + strerror(errno));
258 + } else {
259 + /* create the device with ioctl: */
260 + num = atoi(nstr);
261 + if (num >= 0 && num < 1234567890) {
262 + struct atm_newif_br2684 ni;
263 + ni.backend_num = ATM_BACKEND_BR2684;
264 + ni.media = BR2684_MEDIA_ETHERNET;
265 + ni.mtu = 1500;
266 + ni.payload = payload; /* bridged or routed */
267 + sprintf(ni.ifname, "nas%d", num);
268 + err = ioctl(lastsock, ATM_NEWBACKENDIF, &ni);
269 +
270 + if (err == 0)
271 + syslog(LOG_INFO,
272 + "Interface \"%s\" (mtu=%d, payload=%s) created sucessfully\n",
273 + ni.ifname, ni.mtu,ni.payload ? "bridged" : "routed");
274 + else
275 + syslog(LOG_INFO,
276 + "Interface \"%s\" could not be created, reason: %s\n",
277 + ni.ifname, strerror(errno));
278 + lastitf = num; /* even if we didn't create, because existed, assign_vcc wil want to know it! */
279 + } else {
280 + syslog(LOG_ERR, "err: strange interface number %d",
281 + num);
282 + }
283 + }
284 + return 0;
285 +}
286 +
287 +
288 +int assign_vcc(char *astr, int encap, int payload, int bufsize)
289 +{
290 + int err, errno;
291 + struct atm_qos qos;
292 + struct sockaddr_atmpvc addr;
293 + int fd;
294 + struct atm_backend_br2684 be;
295 +
296 + memset(&addr, 0, sizeof(addr));
297 + err =
298 + text2atm(astr, (struct sockaddr *) (&addr), sizeof(addr),
299 + T2A_PVC);
300 + if (err != 0)
301 + syslog(LOG_ERR,
302 + "Could not parse ATM parameters (error=%d)\n", err);
303 +
304 +#if 0
305 + addr.sap_family = AF_ATMPVC;
306 + addr.sap_addr.itf = itf;
307 + addr.sap_addr.vpi = 0;
308 + addr.sap_addr.vci = vci;
309 +#endif
310 + syslog(LOG_INFO,
311 + "Communicating over ATM %d.%d.%d, encapsulation: %s\n",
312 + addr.sap_addr.itf, addr.sap_addr.vpi, addr.sap_addr.vci,
313 + encap ? "VC mux" : "LLC");
314 +
315 + if ((fd = socket(PF_ATMPVC, SOCK_DGRAM, ATM_AAL5)) < 0)
316 + syslog(LOG_ERR, "failed to create socket %d, reason: %s",
317 + errno, strerror(errno));
318 +
319 +
320 + memset(&qos, 0, sizeof(qos));
321 + qos.aal = ATM_AAL5;
322 + qos.txtp.traffic_class = ATM_UBR;
323 + qos.txtp.max_sdu = 1524;
324 + qos.txtp.pcr = ATM_MAX_PCR;
325 + qos.rxtp = qos.txtp;
326 +
327 + if ((err =
328 + setsockopt(fd, SOL_SOCKET, SO_SNDBUF, &bufsize,
329 + sizeof(bufsize))))
330 + syslog(LOG_ERR, "setsockopt SO_SNDBUF: (%d) %s\n", err,
331 + strerror(err));
332 +
333 + if (setsockopt(fd, SOL_ATM, SO_ATMQOS, &qos, sizeof(qos)) < 0)
334 + syslog(LOG_ERR, "setsockopt SO_ATMQOS %d", errno);
335 +
336 + err =
337 + connect(fd, (struct sockaddr *) &addr,
338 + sizeof(struct sockaddr_atmpvc));
339 +
340 + if (err < 0)
341 + fatal("failed to connect on socket", err);
342 +
343 + /* attach the vcc to device: */
344 +
345 + be.backend_num = ATM_BACKEND_BR2684;
346 + be.ifspec.method = BR2684_FIND_BYIFNAME;
347 + sprintf(be.ifspec.spec.ifname, "nas%d", lastitf);
348 + be.fcs_in = BR2684_FCSIN_NO;
349 + be.fcs_out = BR2684_FCSOUT_NO;
350 + be.fcs_auto = 0;
351 + be.encaps = encap ? BR2684_ENCAPS_VC : BR2684_ENCAPS_LLC;
352 + be.payload = payload;
353 + be.has_vpiid = 0;
354 + be.send_padding = 0;
355 + be.min_size = 0;
356 + err = ioctl(fd, ATM_SETBACKEND, &be);
357 + if (err == 0)
358 + syslog(LOG_INFO, "Interface configured");
359 + else {
360 + syslog(LOG_ERR, "Could not configure interface:%s",
361 + strerror(errno));
362 + exit(2);
363 + }
364 + return fd;
365 +}
366 +
367 +
368 +
369 +void usage(char *s)
370 +{
371 + printf("usage: %s [-b] [[-c number] [-e 0|1] [-p 0|1] [-s num] [-a [itf.]vpi.vci]*]*\n"
372 + " -b = run in background (daemonize)\n"
373 + " -c <num> = use interface nas<num>\n"
374 + " -e 0|1 = encapsulation (0=LLC, 1=VC Mux)\n"
375 + " -p 0|1 = payload type (0=routed,1=bridged)\n"
376 + " -s <num> = set sndbuf (send buffer) size (default 8192)\n"
377 + " -a [itf.]vpi.vci = ATM interface no, VPI, VCI\n",
378 + s);
379 + exit(1);
380 +}
381 +
382 +
383 +
384 +int main(int argc, char **argv)
385 +{
386 + int c, background = 0, encap = 0, sndbuf = 8192, payload = 1;
387 + char *itfnum = NULL;
388 +
389 + lastsock = -1;
390 + lastitf = 0;
391 +
392 + openlog(LOG_NAME, LOG_OPTION, LOG_FACILITY);
393 + if (argc > 1)
394 + while ((c = getopt(argc, argv, "a:bc:e:s:p:t:?h")) != EOF)
395 + switch (c) {
396 + case 'a':
397 + assign_vcc(optarg, encap, payload, sndbuf);
398 + break;
399 + case 'b':
400 + background = 1;
401 + break;
402 + case 'c':
403 + create_br(optarg, payload);
404 + itfnum = strdup(optarg);
405 + break;
406 + case 'e':
407 + encap = (atoi(optarg));
408 + if (encap < 0) {
409 + syslog(LOG_ERR,
410 + "invalid encapsulation: %s:\n",
411 + optarg);
412 + encap = 0;
413 + }
414 + break;
415 + case 's':
416 + sndbuf = (atoi(optarg));
417 + if (sndbuf < 0) {
418 + syslog(LOG_ERR,
419 + "Invalid sndbuf: %s, using size of 8192 instead\n",
420 + optarg);
421 + sndbuf = 8192;
422 + }
423 + break;
424 + case 'p': /* payload type: routed (0) or bridged (1) */
425 + payload = atoi(optarg);
426 + break;
427 + case '?':
428 + case 'h':
429 + default:
430 + usage(argv[0]);
431 + } else
432 + usage(argv[0]);
433 +
434 + if (argc != optind)
435 + usage(argv[0]);
436 +
437 + if (lastsock >= 0)
438 + close(lastsock);
439 +
440 + if (background) {
441 + pid_t pid;
442 +
443 + pid = fork();
444 + if (pid < 0) {
445 + fprintf(stderr, "Error detaching\n");
446 + exit(2);
447 + } else if (pid)
448 + exit(0); // This is the parent
449 +
450 + // Become a process group and session group leader
451 + if (setsid() < 0) {
452 + fprintf(stderr, "Could not set process group\n");
453 + exit(2);
454 + }
455 + // Fork again to let process group leader exit
456 + pid = fork();
457 + if (pid < 0) {
458 + fprintf(stderr,
459 + "Error detaching during second fork\n");
460 + exit(2);
461 + } else if (pid)
462 + exit(0); // This is the parent
463 +
464 + // Now we're ready for buisness
465 + chdir("/"); // Don't keep directories in use
466 + close(0);
467 + close(1);
468 + close(2); // Close stdin, -out and -error
469 + /*
470 + Note that this implementation does not keep an open
471 + stdout/err.
472 + If we need them they can be opened now
473 + */
474 +
475 + }
476 +
477 + if (itfnum != NULL) {
478 + create_pidfile(itfnum);
479 + free(itfnum);
480 + }
481 +
482 + syslog(LOG_INFO, "RFC 1483/2684 bridge daemon started\n");
483 + atexit(exitFunc);
484 +
485 + while (1)
486 + sleep(30); /* to keep the sockets... */
487 + return 0;
488 +}