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
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 */
13 /* Written by Marcell GAL <cell@sch.bme.hu> to make use of the */
14 /* ioctls defined in the br2684... kernel patch */
16 #define LOG_OPTION LOG_PERROR|LOG_PID
17 #define LOG_FACILITY LOG_LOCAL2
19 +struct br2684_params {
24 + char *astr; /* temporary */
25 + struct atm_qos reqqos;
29 int lastsock, lastitf;
32 -void fatal(const char *str, int i)
33 +void fatal(const char *str, int err)
35 - syslog (LOG_ERR,"Fatal: %s",str);
36 + syslog (LOG_ERR,"Fatal: %s; %s", str, strerror(err));
43 - syslog (LOG_NOTICE,"Daemon terminated\n");
44 + syslog (LOG_NOTICE,"Daemon terminated");
48 void int_signal(int dummy)
50 - syslog (LOG_INFO,"Killed by a signal\n");
51 + syslog (LOG_INFO,"Killed by a signal");
57 if (num < 0) return -1;
59 - snprintf(name, 20, "/var/run/nas%d.pid", num);
60 + snprintf(name, 32, "/var/run/br2684ctl-nas%d.pid", num);
61 pidfile = fopen(name, "w");
62 if (pidfile == NULL) return -1;
63 fprintf(pidfile, "%d", getpid());
68 -int create_br(char *nstr)
69 +int create_br(int itfnum, int payload)
75 lastsock = socket(PF_ATMPVC, SOCK_DGRAM, ATM_AAL5);
77 syslog(LOG_ERR, "socket creation failed: %s",strerror(errno));
79 /* create the device with ioctl: */
81 - if( num>=0 && num<1234567890){
82 + if( itfnum>=0 && itfnum<1234567890){
83 struct atm_newif_br2684 ni;
84 ni.backend_num = ATM_BACKEND_BR2684;
85 ni.media = BR2684_MEDIA_ETHERNET;
86 +#ifdef BR2684_FLAG_ROUTED
88 + ni.media |= BR2684_FLAG_ROUTED;
91 - sprintf(ni.ifname, "nas%d", num);
92 + sprintf(ni.ifname, "nas%d", itfnum);
93 err=ioctl (lastsock, ATM_NEWBACKENDIF, &ni);
96 - syslog(LOG_NOTICE, "Interface \"%s\" created sucessfully\n",ni.ifname);
97 + syslog(LOG_NOTICE, "Interface \"%s\" created sucessfully",ni.ifname);
99 - syslog(LOG_INFO, "Interface \"%s\" could not be created, reason: %s\n",
100 + syslog(LOG_INFO, "Interface \"%s\" could not be created, reason: %s",
103 - lastitf=num; /* even if we didn't create, because existed, assign_vcc wil want to know it! */
104 + lastitf=itfnum; /* even if we didn't create, because existed,
105 + assign_vcc wil want to know it! */
107 - syslog(LOG_ERR,"err: strange interface number %d", num );
108 + syslog(LOG_ERR,"err: strange interface number %d", itfnum );
115 -int assign_vcc(char *astr, int encap, int bufsize, struct atm_qos qos)
116 +int assign_vcc(char *astr, int encap, int payload,
117 + int bufsize, struct atm_qos qos)
120 struct sockaddr_atmpvc addr;
121 @@ -112,21 +130,17 @@
122 memset(&addr, 0, sizeof(addr));
123 err=text2atm(astr,(struct sockaddr *)(&addr), sizeof(addr), T2A_PVC);
125 - syslog(LOG_ERR,"Could not parse ATM parameters (error=%d)\n",err);
126 + syslog(LOG_ERR,"Could not parse ATM parameters (error=%d)",err);
129 - addr.sap_family = AF_ATMPVC;
130 - addr.sap_addr.itf = itf;
131 - addr.sap_addr.vpi = 0;
132 - addr.sap_addr.vci = vci;
134 - syslog(LOG_NOTICE,"Communicating over ATM %d.%d.%d, encapsulation: %s\n", addr.sap_addr.itf,
135 + syslog(LOG_NOTICE,"Communicating over ATM %d.%d.%d, encapsulation: %s",
139 encap?"VC mux":"LLC");
141 if ((fd = socket(PF_ATMPVC, SOCK_DGRAM, ATM_AAL5)) < 0)
142 - syslog(LOG_ERR,"failed to create socket %d, reason: %s", errno,strerror(errno));
143 + syslog(LOG_ERR,"failed to create socket %d, reason: %s",
144 + errno,strerror(errno));
151 if ( (err=setsockopt(fd,SOL_SOCKET,SO_SNDBUF, &bufsize ,sizeof(bufsize))) )
152 - syslog(LOG_ERR,"setsockopt SO_SNDBUF: (%d) %s\n",err, strerror(err));
153 + syslog(LOG_ERR,"setsockopt SO_SNDBUF: (%d) %s",err, strerror(err));
155 if (setsockopt(fd, SOL_ATM, SO_ATMQOS, &qos, sizeof(qos)) < 0)
156 syslog(LOG_ERR,"setsockopt SO_ATMQOS %d", errno);
158 err = connect(fd, (struct sockaddr*)&addr, sizeof(struct sockaddr_atmpvc));
161 - fatal("failed to connect on socket", err);
162 + fatal("failed to connect on socket", errno);
164 /* attach the vcc to device: */
166 @@ -169,10 +183,30 @@
170 +void start_interface(struct br2684_params* params)
172 + if (params->astr==NULL) {
173 + syslog(LOG_ERR, "Required ATM parameters not specified.");
177 + create_br(params->itfnum, params->payload);
178 + assign_vcc(params->astr, params->encap, params->payload, params->sndbuf,
185 - printf("usage: %s [-b] [[-c number] [-e 0|1] [-s sndbuf] [-q qos] [-a [itf.]vpi.vci]*]*\n", s);
186 + printf("usage: %s [-b] [[-c number] [-e 0|1] [-s sndbuf] [-q qos] [-p 0|1] "
187 + "[-a [itf.]vpi.vci]*]*\n"
188 + " -b = run in background (daemonize)\n"
189 + " -c <num> = use interface nas<num>\n"
190 + " -e 0|1 = encapsulation (0=LLC, 1=VC Mux)\n"
191 + " -p 0|1 = payload type (0=routed,1=bridged)\n"
192 + " -s <num> = set sndbuf (send buffer) size (default 8192)\n"
193 + " -a [itf.]vpi.vci = ATM interface no, VPI, VCI\n",
198 @@ -180,47 +214,63 @@
200 int main (int argc, char **argv)
202 - int c, background=0, encap=0, sndbuf=8192;
203 - struct atm_qos reqqos;
205 + int c, background=0;
207 + struct br2684_params params;
210 + params.sndbuf=8192;
213 + memset(¶ms.reqqos, 0, sizeof(params.reqqos));
219 - memset(&reqqos, 0, sizeof(reqqos));
221 openlog (LOG_NAME,LOG_OPTION,LOG_FACILITY);
223 - while ((c = getopt(argc, argv,"q:a:bc:e:s:?h")) !=EOF)
224 + while ((c = getopt(argc, argv,"q:a:bc:e:s:p:?h")) !=EOF)
227 printf ("optarg : %s",optarg);
228 - if (text2qos(optarg,&reqqos,0)) fprintf(stderr,"QOS parameter invalid\n");
229 + if (text2qos(optarg,¶ms.reqqos,0))
230 + fprintf(stderr,"QOS parameter invalid\n");
233 - assign_vcc(optarg, encap, sndbuf, reqqos);
234 + params.astr=optarg;
241 - itfnum = atoi(optarg);
242 + /* temporary, to make it work with multiple interfaces: */
243 + if (params.itfnum>=0) start_interface(¶ms);
244 + params.itfnum= atoi(optarg);
247 - encap=(atoi(optarg));
249 - syslog (LOG_ERR, "invalid encapsulation: %s:\n",optarg);
251 + params.encap=(atoi(optarg));
252 + if(params.encap<0){
253 + syslog (LOG_ERR, "invalid encapsulation: %s:",optarg);
258 - sndbuf=(atoi(optarg));
260 - syslog(LOG_ERR, "Invalid sndbuf: %s, using size of 8192 instead\n",optarg);
262 + params.sndbuf=(atoi(optarg));
263 + if(params.sndbuf<0){
264 + syslog(LOG_ERR, "Invalid sndbuf: %s, using size of 8192 instead",
266 + params.sndbuf=8192;
269 + case 'p': /* payload type: routed (0) or bridged (1) */
270 +#ifdef BR2684_FLAG_ROUTED
271 + params.payload = atoi(optarg);
274 + syslog(LOG_ERR, "payload option not supported.");
281 if (argc != optind) usage(argv[0]);
283 + start_interface(¶ms);
285 if(lastsock>=0) close(lastsock);
288 @@ -268,11 +275,11 @@
292 - create_pidfile(itfnum);
293 + create_pidfile(params.itfnum);
294 signal(SIGINT, int_signal);
295 signal(SIGTERM, int_signal);
297 - syslog (LOG_INFO, "RFC 1483/2684 bridge daemon started\n");
298 + syslog (LOG_INFO, "RFC 1483/2684 bridge daemon started");
301 while (1) pause(); /* to keep the sockets... */