[package] mac80211: fix compat-wireless-old md5sum
[openwrt.git] / package / br2684ctl / patches / 101-routed_support.patch
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
13 /* Written by Marcell GAL <cell@sch.bme.hu> to make use of the */
14 /* ioctls defined in the br2684... kernel patch */
15 @@ -28,26 +32,35 @@
16 #define LOG_OPTION LOG_PERROR|LOG_PID
17 #define LOG_FACILITY LOG_LOCAL2
18
19 +struct br2684_params {
20 + int itfnum;
21 + int encap;
22 + int sndbuf;
23 + int payload;
24 + char *astr; /* temporary */
25 + struct atm_qos reqqos;
26 +};
27 +
28
29 int lastsock, lastitf;
30
31
32 -void fatal(const char *str, int i)
33 +void fatal(const char *str, int err)
34 {
35 - syslog (LOG_ERR,"Fatal: %s",str);
36 + syslog (LOG_ERR,"Fatal: %s; %s", str, strerror(err));
37 exit(-2);
38 };
39
40
41 void exitFunc(void)
42 {
43 - syslog (LOG_NOTICE,"Daemon terminated\n");
44 + syslog (LOG_NOTICE,"Daemon terminated");
45 }
46
47
48 void int_signal(int dummy)
49 {
50 - syslog (LOG_INFO,"Killed by a signal\n");
51 + syslog (LOG_INFO,"Killed by a signal");
52 exit(0);
53 }
54
55 @@ -58,7 +71,7 @@
56
57 if (num < 0) return -1;
58
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());
64 @@ -67,9 +80,9 @@
65 return 0;
66 }
67
68 -int create_br(char *nstr)
69 +int create_br(int itfnum, int payload)
70 {
71 - int num, err;
72 + int err;
73
74 if(lastsock<0) {
75 lastsock = socket(PF_ATMPVC, SOCK_DGRAM, ATM_AAL5);
76 @@ -78,31 +91,36 @@
77 syslog(LOG_ERR, "socket creation failed: %s",strerror(errno));
78 } else {
79 /* create the device with ioctl: */
80 - num=atoi(nstr);
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
87 + if (payload == 0)
88 + ni.media |= BR2684_FLAG_ROUTED;
89 +#endif
90 ni.mtu = 1500;
91 - sprintf(ni.ifname, "nas%d", num);
92 + sprintf(ni.ifname, "nas%d", itfnum);
93 err=ioctl (lastsock, ATM_NEWBACKENDIF, &ni);
94
95 if (err == 0)
96 - syslog(LOG_NOTICE, "Interface \"%s\" created sucessfully\n",ni.ifname);
97 + syslog(LOG_NOTICE, "Interface \"%s\" created sucessfully",ni.ifname);
98 else
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",
101 ni.ifname,
102 strerror(errno));
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! */
106 } else {
107 - syslog(LOG_ERR,"err: strange interface number %d", num );
108 + syslog(LOG_ERR,"err: strange interface number %d", itfnum );
109 }
110 }
111 return 0;
112 }
113
114
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)
118 {
119 int err;
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);
124 if (err!=0)
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);
127
128 -#if 0
129 - addr.sap_family = AF_ATMPVC;
130 - addr.sap_addr.itf = itf;
131 - addr.sap_addr.vpi = 0;
132 - addr.sap_addr.vci = vci;
133 -#endif
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",
136 + addr.sap_addr.itf,
137 addr.sap_addr.vpi,
138 addr.sap_addr.vci,
139 encap?"VC mux":"LLC");
140
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));
145
146 if (qos.aal == 0) {
147 qos.aal = ATM_AAL5;
148 @@ -137,7 +151,7 @@
149 }
150
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));
154
155 if (setsockopt(fd, SOL_ATM, SO_ATMQOS, &qos, sizeof(qos)) < 0)
156 syslog(LOG_ERR,"setsockopt SO_ATMQOS %d", errno);
157 @@ -145,7 +159,7 @@
158 err = connect(fd, (struct sockaddr*)&addr, sizeof(struct sockaddr_atmpvc));
159
160 if (err < 0)
161 - fatal("failed to connect on socket", err);
162 + fatal("failed to connect on socket", errno);
163
164 /* attach the vcc to device: */
165
166 @@ -169,10 +183,30 @@
167 return fd ;
168 }
169
170 +void start_interface(struct br2684_params* params)
171 +{
172 + if (params->astr==NULL) {
173 + syslog(LOG_ERR, "Required ATM parameters not specified.");
174 + exit(1);
175 + }
176 +
177 + create_br(params->itfnum, params->payload);
178 + assign_vcc(params->astr, params->encap, params->payload, params->sndbuf,
179 + params->reqqos);
180 +}
181 +
182
183 void usage(char *s)
184 {
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",
194 + s);
195 exit(1);
196 }
197
198 @@ -180,47 +214,63 @@
199
200 int main (int argc, char **argv)
201 {
202 - int c, background=0, encap=0, sndbuf=8192;
203 - struct atm_qos reqqos;
204 - int itfnum;
205 + int c, background=0;
206 +
207 + struct br2684_params params;
208 + params.itfnum=-1;
209 + params.encap=0;
210 + params.sndbuf=8192;
211 + params.payload=1;
212 + params.astr=NULL;
213 + memset(&params.reqqos, 0, sizeof(params.reqqos));
214 +
215 lastsock=-1;
216 lastitf=0;
217
218 /* st qos to 0 */
219 - memset(&reqqos, 0, sizeof(reqqos));
220
221 openlog (LOG_NAME,LOG_OPTION,LOG_FACILITY);
222 if (argc>1)
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)
225 switch (c) {
226 case 'q':
227 printf ("optarg : %s",optarg);
228 - if (text2qos(optarg,&reqqos,0)) fprintf(stderr,"QOS parameter invalid\n");
229 + if (text2qos(optarg,&params.reqqos,0))
230 + fprintf(stderr,"QOS parameter invalid\n");
231 break;
232 case 'a':
233 - assign_vcc(optarg, encap, sndbuf, reqqos);
234 + params.astr=optarg;
235 break;
236 case 'b':
237 background=1;
238 break;
239 case 'c':
240 - create_br(optarg);
241 - itfnum = atoi(optarg);
242 + /* temporary, to make it work with multiple interfaces: */
243 + if (params.itfnum>=0) start_interface(&params);
244 + params.itfnum= atoi(optarg);
245 break;
246 case 'e':
247 - encap=(atoi(optarg));
248 - if(encap<0){
249 - syslog (LOG_ERR, "invalid encapsulation: %s:\n",optarg);
250 - encap=0;
251 + params.encap=(atoi(optarg));
252 + if(params.encap<0){
253 + syslog (LOG_ERR, "invalid encapsulation: %s:",optarg);
254 + params.encap=0;
255 }
256 break;
257 case 's':
258 - sndbuf=(atoi(optarg));
259 - if(sndbuf<0){
260 - syslog(LOG_ERR, "Invalid sndbuf: %s, using size of 8192 instead\n",optarg);
261 - sndbuf=8192;
262 + params.sndbuf=(atoi(optarg));
263 + if(params.sndbuf<0){
264 + syslog(LOG_ERR, "Invalid sndbuf: %s, using size of 8192 instead",
265 + optarg);
266 + params.sndbuf=8192;
267 }
268 break;
269 + case 'p': /* payload type: routed (0) or bridged (1) */
270 +#ifdef BR2684_FLAG_ROUTED
271 + params.payload = atoi(optarg);
272 + break;
273 +#else
274 + syslog(LOG_ERR, "payload option not supported.");
275 +#endif
276 case '?':
277 case 'h':
278 default:
279 @@ -231,6 +281,8 @@
280
281 if (argc != optind) usage(argv[0]);
282
283 + start_interface(&params);
284 +
285 if(lastsock>=0) close(lastsock);
286
287 if (background) {
288 @@ -268,11 +275,11 @@
289
290 }
291
292 - create_pidfile(itfnum);
293 + create_pidfile(params.itfnum);
294 signal(SIGINT, int_signal);
295 signal(SIGTERM, int_signal);
296
297 - syslog (LOG_INFO, "RFC 1483/2684 bridge daemon started\n");
298 + syslog (LOG_INFO, "RFC 1483/2684 bridge daemon started");
299 atexit (exitFunc);
300
301 while (1) pause(); /* to keep the sockets... */
This page took 0.054796 seconds and 5 git commands to generate.