5 #include <linux/atmdev.h>
6 #include <linux/atmbr2684.h>
7 +#ifndef BR2684_FLAG_ROUTED
8 +#warning "Kernel missing routed support for br2684"
9 +#define BR2684_FLAG_ROUTED (1<<16) /* payload is routed, not bridged */
12 /* Written by Marcell GAL <cell@sch.bme.hu> to make use of the */
13 /* ioctls defined in the br2684... kernel patch */
15 #define LOG_OPTION LOG_PERROR|LOG_PID
16 #define LOG_FACILITY LOG_LOCAL2
18 +struct br2684_params {
23 + char *astr; /* temporary */
24 + struct atm_qos reqqos;
28 int lastsock, lastitf;
31 -void fatal(const char *str, int i)
32 +void fatal(const char *str, int err)
34 - syslog (LOG_ERR,"Fatal: %s",str);
35 + syslog (LOG_ERR,"Fatal: %s; %s", str, strerror(err));
42 - syslog (LOG_NOTICE,"Daemon terminated\n");
43 + syslog (LOG_NOTICE,"Daemon terminated");
47 void int_signal(int dummy)
49 - syslog (LOG_INFO,"Killed by a signal\n");
50 + syslog (LOG_INFO,"Killed by a signal");
54 @@ -58,7 +71,7 @@ int create_pidfile(int num)
56 if (num < 0) return -1;
58 - snprintf(name, 20, "/var/run/nas%d.pid", num);
59 + snprintf(name, 32, "/var/run/br2684ctl-nas%d.pid", num);
60 pidfile = fopen(name, "w");
61 if (pidfile == NULL) return -1;
62 fprintf(pidfile, "%d", getpid());
63 @@ -67,9 +80,9 @@ int create_pidfile(int num)
67 -int create_br(char *nstr)
68 +int create_br(int itfnum, int payload)
74 lastsock = socket(PF_ATMPVC, SOCK_DGRAM, ATM_AAL5);
75 @@ -78,31 +91,36 @@ int create_br(char *nstr)
76 syslog(LOG_ERR, "socket creation failed: %s",strerror(errno));
78 /* create the device with ioctl: */
80 - if( num>=0 && num<1234567890){
81 + if( itfnum>=0 && itfnum<1234567890){
82 struct atm_newif_br2684 ni;
83 ni.backend_num = ATM_BACKEND_BR2684;
84 ni.media = BR2684_MEDIA_ETHERNET;
85 +#ifdef BR2684_FLAG_ROUTED
87 + ni.media |= BR2684_FLAG_ROUTED;
90 - sprintf(ni.ifname, "nas%d", num);
91 + sprintf(ni.ifname, "nas%d", itfnum);
92 err=ioctl (lastsock, ATM_NEWBACKENDIF, &ni);
95 - syslog(LOG_NOTICE, "Interface \"%s\" created sucessfully\n",ni.ifname);
96 + syslog(LOG_NOTICE, "Interface \"%s\" created sucessfully",ni.ifname);
98 - syslog(LOG_INFO, "Interface \"%s\" could not be created, reason: %s\n",
99 + syslog(LOG_INFO, "Interface \"%s\" could not be created, reason: %s",
102 - lastitf=num; /* even if we didn't create, because existed, assign_vcc wil want to know it! */
103 + lastitf=itfnum; /* even if we didn't create, because existed,
104 + assign_vcc wil want to know it! */
106 - syslog(LOG_ERR,"err: strange interface number %d", num );
107 + syslog(LOG_ERR,"err: strange interface number %d", itfnum );
114 -int assign_vcc(char *astr, int encap, int bufsize, struct atm_qos qos)
115 +int assign_vcc(char *astr, int encap, int payload,
116 + int bufsize, struct atm_qos qos)
119 struct sockaddr_atmpvc addr;
120 @@ -112,21 +130,17 @@ int assign_vcc(char *astr, int encap, in
121 memset(&addr, 0, sizeof(addr));
122 err=text2atm(astr,(struct sockaddr *)(&addr), sizeof(addr), T2A_PVC);
124 - syslog(LOG_ERR,"Could not parse ATM parameters (error=%d)\n",err);
125 + syslog(LOG_ERR,"Could not parse ATM parameters (error=%d)",err);
128 - addr.sap_family = AF_ATMPVC;
129 - addr.sap_addr.itf = itf;
130 - addr.sap_addr.vpi = 0;
131 - addr.sap_addr.vci = vci;
133 - syslog(LOG_NOTICE,"Communicating over ATM %d.%d.%d, encapsulation: %s\n", addr.sap_addr.itf,
134 + syslog(LOG_NOTICE,"Communicating over ATM %d.%d.%d, encapsulation: %s",
138 encap?"VC mux":"LLC");
140 if ((fd = socket(PF_ATMPVC, SOCK_DGRAM, ATM_AAL5)) < 0)
141 - syslog(LOG_ERR,"failed to create socket %d, reason: %s", errno,strerror(errno));
142 + syslog(LOG_ERR,"failed to create socket %d, reason: %s",
143 + errno,strerror(errno));
147 @@ -137,7 +151,7 @@ int assign_vcc(char *astr, int encap, in
150 if ( (err=setsockopt(fd,SOL_SOCKET,SO_SNDBUF, &bufsize ,sizeof(bufsize))) )
151 - syslog(LOG_ERR,"setsockopt SO_SNDBUF: (%d) %s\n",err, strerror(err));
152 + syslog(LOG_ERR,"setsockopt SO_SNDBUF: (%d) %s",err, strerror(err));
154 if (setsockopt(fd, SOL_ATM, SO_ATMQOS, &qos, sizeof(qos)) < 0)
155 syslog(LOG_ERR,"setsockopt SO_ATMQOS %d", errno);
156 @@ -145,7 +159,7 @@ int assign_vcc(char *astr, int encap, in
157 err = connect(fd, (struct sockaddr*)&addr, sizeof(struct sockaddr_atmpvc));
160 - fatal("failed to connect on socket", err);
161 + fatal("failed to connect on socket", errno);
163 /* attach the vcc to device: */
165 @@ -169,10 +183,30 @@ int assign_vcc(char *astr, int encap, in
169 +void start_interface(struct br2684_params* params)
171 + if (params->astr==NULL) {
172 + syslog(LOG_ERR, "Required ATM parameters not specified.");
176 + create_br(params->itfnum, params->payload);
177 + assign_vcc(params->astr, params->encap, params->payload, params->sndbuf,
184 - printf("usage: %s [-b] [[-c number] [-e 0|1] [-s sndbuf] [-q qos] [-a [itf.]vpi.vci]*]*\n", s);
185 + printf("usage: %s [-b] [[-c number] [-e 0|1] [-s sndbuf] [-q qos] [-p 0|1] "
186 + "[-a [itf.]vpi.vci]*]*\n"
187 + " -b = run in background (daemonize)\n"
188 + " -c <num> = use interface nas<num>\n"
189 + " -e 0|1 = encapsulation (0=LLC, 1=VC Mux)\n"
190 + " -p 0|1 = payload type (0=routed,1=bridged)\n"
191 + " -s <num> = set sndbuf (send buffer) size (default 8192)\n"
192 + " -a [itf.]vpi.vci = ATM interface no, VPI, VCI\n",
197 @@ -180,47 +214,63 @@ void usage(char *s)
199 int main (int argc, char **argv)
201 - int c, background=0, encap=0, sndbuf=8192;
202 - struct atm_qos reqqos;
204 + int c, background=0;
206 + struct br2684_params params;
209 + params.sndbuf=8192;
212 + memset(¶ms.reqqos, 0, sizeof(params.reqqos));
218 - memset(&reqqos, 0, sizeof(reqqos));
220 openlog (LOG_NAME,LOG_OPTION,LOG_FACILITY);
222 - while ((c = getopt(argc, argv,"q:a:bc:e:s:?h")) !=EOF)
223 + while ((c = getopt(argc, argv,"q:a:bc:e:s:p:?h")) !=EOF)
226 printf ("optarg : %s",optarg);
227 - if (text2qos(optarg,&reqqos,0)) fprintf(stderr,"QOS parameter invalid\n");
228 + if (text2qos(optarg,¶ms.reqqos,0))
229 + fprintf(stderr,"QOS parameter invalid\n");
232 - assign_vcc(optarg, encap, sndbuf, reqqos);
233 + params.astr=optarg;
240 - itfnum = atoi(optarg);
241 + /* temporary, to make it work with multiple interfaces: */
242 + if (params.itfnum>=0) start_interface(¶ms);
243 + params.itfnum= atoi(optarg);
246 - encap=(atoi(optarg));
248 - syslog (LOG_ERR, "invalid encapsulation: %s:\n",optarg);
250 + params.encap=(atoi(optarg));
251 + if(params.encap<0){
252 + syslog (LOG_ERR, "invalid encapsulation: %s:",optarg);
257 - sndbuf=(atoi(optarg));
259 - syslog(LOG_ERR, "Invalid sndbuf: %s, using size of 8192 instead\n",optarg);
261 + params.sndbuf=(atoi(optarg));
262 + if(params.sndbuf<0){
263 + syslog(LOG_ERR, "Invalid sndbuf: %s, using size of 8192 instead",
265 + params.sndbuf=8192;
268 + case 'p': /* payload type: routed (0) or bridged (1) */
269 +#ifdef BR2684_FLAG_ROUTED
270 + params.payload = atoi(optarg);
273 + syslog(LOG_ERR, "payload option not supported.");
278 @@ -231,6 +281,8 @@ int main (int argc, char **argv)
280 if (argc != optind) usage(argv[0]);
282 + start_interface(¶ms);
284 if(lastsock>=0) close(lastsock);
287 @@ -268,11 +320,11 @@ int main (int argc, char **argv)
291 - create_pidfile(itfnum);
292 + create_pidfile(params.itfnum);
293 signal(SIGINT, int_signal);
294 signal(SIGTERM, int_signal);
296 - syslog (LOG_INFO, "RFC 1483/2684 bridge daemon started\n");
297 + syslog (LOG_INFO, "RFC 1483/2684 bridge daemon started");
300 while (1) pause(); /* to keep the sockets... */