101-routed_support.patch 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  1. diff -Nu br2684ctl-20040226.orig/br2684ctl.c br2684ctl.orig/br2684ctl.c
  2. --- br2684ctl-20040226.orig/br2684ctl.c 2008-03-25 22:26:59.000000000 +0000
  3. +++ br2684ctl.orig/br2684ctl.c 2008-03-31 10:11:06.000000000 +0100
  4. @@ -10,6 +10,10 @@
  5. #include <atm.h>
  6. #include <linux/atmdev.h>
  7. #include <linux/atmbr2684.h>
  8. +#ifndef BR2684_FLAG_ROUTED
  9. +#warning "Kernel missing routed support for br2684"
  10. +#define BR2684_FLAG_ROUTED (1<<16) /* payload is routed, not bridged */
  11. +#endif
  12. /* Written by Marcell GAL <[email protected]> to make use of the */
  13. /* ioctls defined in the br2684... kernel patch */
  14. @@ -28,26 +32,35 @@
  15. #define LOG_OPTION LOG_PERROR|LOG_PID
  16. #define LOG_FACILITY LOG_LOCAL2
  17. +struct br2684_params {
  18. + int itfnum;
  19. + int encap;
  20. + int sndbuf;
  21. + int payload;
  22. + char *astr; /* temporary */
  23. + struct atm_qos reqqos;
  24. +};
  25. +
  26. int lastsock, lastitf;
  27. -void fatal(const char *str, int i)
  28. +void fatal(const char *str, int err)
  29. {
  30. - syslog (LOG_ERR,"Fatal: %s",str);
  31. + syslog (LOG_ERR,"Fatal: %s; %s", str, strerror(err));
  32. exit(-2);
  33. };
  34. void exitFunc(void)
  35. {
  36. - syslog (LOG_NOTICE,"Daemon terminated\n");
  37. + syslog (LOG_NOTICE,"Daemon terminated");
  38. }
  39. void int_signal(int dummy)
  40. {
  41. - syslog (LOG_INFO,"Killed by a signal\n");
  42. + syslog (LOG_INFO,"Killed by a signal");
  43. exit(0);
  44. }
  45. @@ -58,7 +71,7 @@
  46. if (num < 0) return -1;
  47. - snprintf(name, 20, "/var/run/nas%d.pid", num);
  48. + snprintf(name, 32, "/var/run/br2684ctl-nas%d.pid", num);
  49. pidfile = fopen(name, "w");
  50. if (pidfile == NULL) return -1;
  51. fprintf(pidfile, "%d", getpid());
  52. @@ -67,9 +80,9 @@
  53. return 0;
  54. }
  55. -int create_br(char *nstr)
  56. +int create_br(int itfnum, int payload)
  57. {
  58. - int num, err;
  59. + int err;
  60. if(lastsock<0) {
  61. lastsock = socket(PF_ATMPVC, SOCK_DGRAM, ATM_AAL5);
  62. @@ -78,31 +91,36 @@
  63. syslog(LOG_ERR, "socket creation failed: %s",strerror(errno));
  64. } else {
  65. /* create the device with ioctl: */
  66. - num=atoi(nstr);
  67. - if( num>=0 && num<1234567890){
  68. + if( itfnum>=0 && itfnum<1234567890){
  69. struct atm_newif_br2684 ni;
  70. ni.backend_num = ATM_BACKEND_BR2684;
  71. ni.media = BR2684_MEDIA_ETHERNET;
  72. +#ifdef BR2684_FLAG_ROUTED
  73. + if (payload == 0)
  74. + ni.media |= BR2684_FLAG_ROUTED;
  75. +#endif
  76. ni.mtu = 1500;
  77. - sprintf(ni.ifname, "nas%d", num);
  78. + sprintf(ni.ifname, "nas%d", itfnum);
  79. err=ioctl (lastsock, ATM_NEWBACKENDIF, &ni);
  80. if (err == 0)
  81. - syslog(LOG_NOTICE, "Interface \"%s\" created sucessfully\n",ni.ifname);
  82. + syslog(LOG_NOTICE, "Interface \"%s\" created sucessfully",ni.ifname);
  83. else
  84. - syslog(LOG_INFO, "Interface \"%s\" could not be created, reason: %s\n",
  85. + syslog(LOG_INFO, "Interface \"%s\" could not be created, reason: %s",
  86. ni.ifname,
  87. strerror(errno));
  88. - lastitf=num; /* even if we didn't create, because existed, assign_vcc wil want to know it! */
  89. + lastitf=itfnum; /* even if we didn't create, because existed,
  90. + assign_vcc wil want to know it! */
  91. } else {
  92. - syslog(LOG_ERR,"err: strange interface number %d", num );
  93. + syslog(LOG_ERR,"err: strange interface number %d", itfnum );
  94. }
  95. }
  96. return 0;
  97. }
  98. -int assign_vcc(char *astr, int encap, int bufsize, struct atm_qos qos)
  99. +int assign_vcc(char *astr, int encap, int payload,
  100. + int bufsize, struct atm_qos qos)
  101. {
  102. int err;
  103. struct sockaddr_atmpvc addr;
  104. @@ -112,21 +130,17 @@
  105. memset(&addr, 0, sizeof(addr));
  106. err=text2atm(astr,(struct sockaddr *)(&addr), sizeof(addr), T2A_PVC);
  107. if (err!=0)
  108. - syslog(LOG_ERR,"Could not parse ATM parameters (error=%d)\n",err);
  109. + syslog(LOG_ERR,"Could not parse ATM parameters (error=%d)",err);
  110. -#if 0
  111. - addr.sap_family = AF_ATMPVC;
  112. - addr.sap_addr.itf = itf;
  113. - addr.sap_addr.vpi = 0;
  114. - addr.sap_addr.vci = vci;
  115. -#endif
  116. - syslog(LOG_NOTICE,"Communicating over ATM %d.%d.%d, encapsulation: %s\n", addr.sap_addr.itf,
  117. + syslog(LOG_NOTICE,"Communicating over ATM %d.%d.%d, encapsulation: %s",
  118. + addr.sap_addr.itf,
  119. addr.sap_addr.vpi,
  120. addr.sap_addr.vci,
  121. encap?"VC mux":"LLC");
  122. if ((fd = socket(PF_ATMPVC, SOCK_DGRAM, ATM_AAL5)) < 0)
  123. - syslog(LOG_ERR,"failed to create socket %d, reason: %s", errno,strerror(errno));
  124. + syslog(LOG_ERR,"failed to create socket %d, reason: %s",
  125. + errno,strerror(errno));
  126. if (qos.aal == 0) {
  127. qos.aal = ATM_AAL5;
  128. @@ -137,7 +151,7 @@
  129. }
  130. if ( (err=setsockopt(fd,SOL_SOCKET,SO_SNDBUF, &bufsize ,sizeof(bufsize))) )
  131. - syslog(LOG_ERR,"setsockopt SO_SNDBUF: (%d) %s\n",err, strerror(err));
  132. + syslog(LOG_ERR,"setsockopt SO_SNDBUF: (%d) %s",err, strerror(err));
  133. if (setsockopt(fd, SOL_ATM, SO_ATMQOS, &qos, sizeof(qos)) < 0)
  134. syslog(LOG_ERR,"setsockopt SO_ATMQOS %d", errno);
  135. @@ -145,7 +159,7 @@
  136. err = connect(fd, (struct sockaddr*)&addr, sizeof(struct sockaddr_atmpvc));
  137. if (err < 0)
  138. - fatal("failed to connect on socket", err);
  139. + fatal("failed to connect on socket", errno);
  140. /* attach the vcc to device: */
  141. @@ -169,10 +183,30 @@
  142. return fd ;
  143. }
  144. +void start_interface(struct br2684_params* params)
  145. +{
  146. + if (params->astr==NULL) {
  147. + syslog(LOG_ERR, "Required ATM parameters not specified.");
  148. + exit(1);
  149. + }
  150. +
  151. + create_br(params->itfnum, params->payload);
  152. + assign_vcc(params->astr, params->encap, params->payload, params->sndbuf,
  153. + params->reqqos);
  154. +}
  155. +
  156. void usage(char *s)
  157. {
  158. - printf("usage: %s [-b] [[-c number] [-e 0|1] [-s sndbuf] [-q qos] [-a [itf.]vpi.vci]*]*\n", s);
  159. + printf("usage: %s [-b] [[-c number] [-e 0|1] [-s sndbuf] [-q qos] [-p 0|1] "
  160. + "[-a [itf.]vpi.vci]*]*\n"
  161. + " -b = run in background (daemonize)\n"
  162. + " -c <num> = use interface nas<num>\n"
  163. + " -e 0|1 = encapsulation (0=LLC, 1=VC Mux)\n"
  164. + " -p 0|1 = payload type (0=routed,1=bridged)\n"
  165. + " -s <num> = set sndbuf (send buffer) size (default 8192)\n"
  166. + " -a [itf.]vpi.vci = ATM interface no, VPI, VCI\n",
  167. + s);
  168. exit(1);
  169. }
  170. @@ -180,47 +214,63 @@
  171. int main (int argc, char **argv)
  172. {
  173. - int c, background=0, encap=0, sndbuf=8192;
  174. - struct atm_qos reqqos;
  175. - int itfnum;
  176. + int c, background=0;
  177. +
  178. + struct br2684_params params;
  179. + params.itfnum=-1;
  180. + params.encap=0;
  181. + params.sndbuf=8192;
  182. + params.payload=1;
  183. + params.astr=NULL;
  184. + memset(&params.reqqos, 0, sizeof(params.reqqos));
  185. +
  186. lastsock=-1;
  187. lastitf=0;
  188. /* st qos to 0 */
  189. - memset(&reqqos, 0, sizeof(reqqos));
  190. openlog (LOG_NAME,LOG_OPTION,LOG_FACILITY);
  191. if (argc>1)
  192. - while ((c = getopt(argc, argv,"q:a:bc:e:s:?h")) !=EOF)
  193. + while ((c = getopt(argc, argv,"q:a:bc:e:s:p:?h")) !=EOF)
  194. switch (c) {
  195. case 'q':
  196. printf ("optarg : %s",optarg);
  197. - if (text2qos(optarg,&reqqos,0)) fprintf(stderr,"QOS parameter invalid\n");
  198. + if (text2qos(optarg,&params.reqqos,0))
  199. + fprintf(stderr,"QOS parameter invalid\n");
  200. break;
  201. case 'a':
  202. - assign_vcc(optarg, encap, sndbuf, reqqos);
  203. + params.astr=optarg;
  204. break;
  205. case 'b':
  206. background=1;
  207. break;
  208. case 'c':
  209. - create_br(optarg);
  210. - itfnum = atoi(optarg);
  211. + /* temporary, to make it work with multiple interfaces: */
  212. + if (params.itfnum>=0) start_interface(&params);
  213. + params.itfnum= atoi(optarg);
  214. break;
  215. case 'e':
  216. - encap=(atoi(optarg));
  217. - if(encap<0){
  218. - syslog (LOG_ERR, "invalid encapsulation: %s:\n",optarg);
  219. - encap=0;
  220. + params.encap=(atoi(optarg));
  221. + if(params.encap<0){
  222. + syslog (LOG_ERR, "invalid encapsulation: %s:",optarg);
  223. + params.encap=0;
  224. }
  225. break;
  226. case 's':
  227. - sndbuf=(atoi(optarg));
  228. - if(sndbuf<0){
  229. - syslog(LOG_ERR, "Invalid sndbuf: %s, using size of 8192 instead\n",optarg);
  230. - sndbuf=8192;
  231. + params.sndbuf=(atoi(optarg));
  232. + if(params.sndbuf<0){
  233. + syslog(LOG_ERR, "Invalid sndbuf: %s, using size of 8192 instead",
  234. + optarg);
  235. + params.sndbuf=8192;
  236. }
  237. break;
  238. + case 'p': /* payload type: routed (0) or bridged (1) */
  239. +#ifdef BR2684_FLAG_ROUTED
  240. + params.payload = atoi(optarg);
  241. + break;
  242. +#else
  243. + syslog(LOG_ERR, "payload option not supported.");
  244. +#endif
  245. case '?':
  246. case 'h':
  247. default:
  248. @@ -231,6 +281,8 @@
  249. if (argc != optind) usage(argv[0]);
  250. + start_interface(&params);
  251. +
  252. if(lastsock>=0) close(lastsock);
  253. if (background) {
  254. @@ -268,11 +275,11 @@
  255. }
  256. - create_pidfile(itfnum);
  257. + create_pidfile(params.itfnum);
  258. signal(SIGINT, int_signal);
  259. signal(SIGTERM, int_signal);
  260. - syslog (LOG_INFO, "RFC 1483/2684 bridge daemon started\n");
  261. + syslog (LOG_INFO, "RFC 1483/2684 bridge daemon started");
  262. atexit (exitFunc);
  263. while (1) pause(); /* to keep the sockets... */