100-br2684.patch 12 KB

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