From d83f547d7de9bac87258dc97c95f6bbfe97b8c70 Mon Sep 17 00:00:00 2001 From: ms Date: Mon, 8 Oct 2007 18:34:12 +0000 Subject: [PATCH] br2684ctl... git-svn-id: http://svn.ipfire.org/svn/ipfire/trunk@957 ea5c0bd1-69bd-2848-81d8-4f18e57aeed8 --- config/rootfiles/common/br2684ctl | 1 + doc/packages-list.txt | 1 + html/cgi-bin/credits.cgi | 2 +- lfs/br2684ctl | 54 ++++++ make.sh | 1 + src/br2684ctl/br2684ctl.c | 271 ++++++++++++++++++++++++++++++ 6 files changed, 329 insertions(+), 1 deletion(-) create mode 100644 config/rootfiles/common/br2684ctl create mode 100644 lfs/br2684ctl create mode 100644 src/br2684ctl/br2684ctl.c diff --git a/config/rootfiles/common/br2684ctl b/config/rootfiles/common/br2684ctl new file mode 100644 index 0000000000..7ce61a985b --- /dev/null +++ b/config/rootfiles/common/br2684ctl @@ -0,0 +1 @@ +usr/bin/br2684ctl diff --git a/doc/packages-list.txt b/doc/packages-list.txt index 19ea8c2e75..18acba41af 100644 --- a/doc/packages-list.txt +++ b/doc/packages-list.txt @@ -44,6 +44,7 @@ * bind-9.3.2 * binutils-2.16.1 * bison-2.2 +* br2684ctl * bridge-utils-1.1 * busybox-1.2.2 * bwm-ng-0.6 diff --git a/html/cgi-bin/credits.cgi b/html/cgi-bin/credits.cgi index ec0f2020a1..82630c73ac 100644 --- a/html/cgi-bin/credits.cgi +++ b/html/cgi-bin/credits.cgi @@ -58,7 +58,7 @@ Vice Project Leader - Christian Schmidt Developer - Heiner Schmeling (cm\@ipfire.org)
Developer - Sven Nierlein -(affect\@versatel.de)
+(affect\@versatel.de)
Developer - Arne Fitzenreiter (arne\@ipfire.org)
Sponsor - Detlef Lampart diff --git a/lfs/br2684ctl b/lfs/br2684ctl new file mode 100644 index 0000000000..c0cfcc544e --- /dev/null +++ b/lfs/br2684ctl @@ -0,0 +1,54 @@ +############################################################################### +# # +# IPFire.org - A linux based firewall # +# Copyright (C) 2007 Michael Tremer & Christian Schmidt # +# # +# This program is free software: you can redistribute it and/or modify # +# it under the terms of the GNU General Public License as published by # +# the Free Software Foundation, either version 3 of the License, or # +# (at your option) any later version. # +# # +# This program is distributed in the hope that it will be useful, # +# but WITHOUT ANY WARRANTY; without even the implied warranty of # +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # +# GNU General Public License for more details. # +# # +# You should have received a copy of the GNU General Public License # +# along with this program. If not, see . # +# # +############################################################################### + +############################################################################### +# Definitions +############################################################################### + +include Config + +VER = ipfire + +THISAPP = br2684ctl +TARGET = $(DIR_INFO)/$(THISAPP) + +############################################################################### +# Top-level Rules +############################################################################### + +install : $(TARGET) + +check : + +download : + +md5 : + +############################################################################### +# Installation Details +############################################################################### + +$(TARGET) : $(patsubst %,$(DIR_DL)/%,$(objects)) + @$(PREBUILD) + @rm -rf $(DIR_SRC)/br2684ctl + cd $(DIR_SRC) && gcc $(CFLAGS) -latm $(DIR_SRC)/src/br2684ctl/br2684ctl.c -o br2684ctl + cd $(DIR_SRC) && install -v -m 755 br2684ctl /usr/bin/br2684ctl + @rm -rf $(DIR_SRC)/br2684ctl + @$(POSTBUILD) diff --git a/make.sh b/make.sh index cd054d0561..89c7be3a8a 100755 --- a/make.sh +++ b/make.sh @@ -529,6 +529,7 @@ buildipfire() { ipfiremake which ipfiremake lsof ipfiremake centerim + ipfiremake br2684ctl } buildinstaller() { diff --git a/src/br2684ctl/br2684ctl.c b/src/br2684ctl/br2684ctl.c new file mode 100644 index 0000000000..a8a71b8932 --- /dev/null +++ b/src/br2684ctl/br2684ctl.c @@ -0,0 +1,271 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/* Written by Marcell GAL to make use of the */ +/* ioctls defined in the br2684... kernel patch */ +/* Compile with cc -o br2684ctl br2684ctl.c -latm */ + +/* + Modified feb 2001 by Stephen Aaskov (saa@lasat.com) + - Added daemonization code + - Added syslog + + TODO: Delete interfaces after exit? +*/ + + +#define LOG_NAME "RFC1483/2684 bridge" +#define LOG_OPTION LOG_PERROR +#define LOG_FACILITY LOG_LOCAL0 + + +int lastsock, lastitf; + + +void fatal(const char *str, int i) +{ + syslog (LOG_ERR,"Fatal: %s",str); + exit(-2); +}; + + +void exitFunc(void) +{ + syslog (LOG_PID,"Daemon terminated\n"); +} + + +int create_pidfile(int num) +{ + FILE *pidfile = NULL; + char name[32]; + + if (num < 0) return -1; + + snprintf(name, 20, "/var/run/nas%d.pid", num); + pidfile = fopen(name, "w"); + if (pidfile == NULL) return -1; + fprintf(pidfile, "%d", getpid()); + fclose(pidfile); + + return 0; +} + +int create_br(char *nstr) +{ + int num, err; + + if(lastsock<0) { + lastsock = socket(PF_ATMPVC, SOCK_DGRAM, ATM_AAL5); + } + if (lastsock<0) { + syslog(LOG_ERR, "socket creation failed: %s",strerror(errno)); + } else { + /* create the device with ioctl: */ + num=atoi(nstr); + if( num>=0 && num<1234567890){ + struct atm_newif_br2684 ni; + ni.backend_num = ATM_BACKEND_BR2684; + ni.media = BR2684_MEDIA_ETHERNET; + ni.mtu = 1500; + sprintf(ni.ifname, "nas%d", num); + err=ioctl (lastsock, ATM_NEWBACKENDIF, &ni); + + if (err == 0) + syslog(LOG_INFO, "Interface \"%s\" created sucessfully\n",ni.ifname); + else + syslog(LOG_INFO, "Interface \"%s\" could not be created, reason: %s\n", + ni.ifname, + strerror(errno)); + lastitf=num; /* even if we didn't create, because existed, assign_vcc wil want to know it! */ + } else { + syslog(LOG_ERR,"err: strange interface number %d", num ); + } + } + return 0; +} + + +int assign_vcc(char *astr, int encap, int bufsize, struct atm_qos qos) +{ + int err; + struct sockaddr_atmpvc addr; + int fd; + struct atm_backend_br2684 be; + + memset(&addr, 0, sizeof(addr)); + err=text2atm(astr,(struct sockaddr *)(&addr), sizeof(addr), T2A_PVC); + if (err!=0) + syslog(LOG_ERR,"Could not parse ATM parameters (error=%d)\n",err); + +#if 0 + addr.sap_family = AF_ATMPVC; + addr.sap_addr.itf = itf; + addr.sap_addr.vpi = 0; + addr.sap_addr.vci = vci; +#endif + syslog(LOG_INFO,"Communicating over ATM %d.%d.%d, encapsulation: %s\n", addr.sap_addr.itf, + addr.sap_addr.vpi, + addr.sap_addr.vci, + encap?"VC mux":"LLC"); + + if ((fd = socket(PF_ATMPVC, SOCK_DGRAM, ATM_AAL5)) < 0) + syslog(LOG_ERR,"failed to create socket %d, reason: %s", errno,strerror(errno)); + + if (qos.aal == 0) { + qos.aal = ATM_AAL5; + qos.txtp.traffic_class = ATM_UBR; + qos.txtp.max_sdu = 1524; + qos.txtp.pcr = ATM_MAX_PCR; + qos.rxtp = qos.txtp; + } + + if ( (err=setsockopt(fd,SOL_SOCKET,SO_SNDBUF, &bufsize ,sizeof(bufsize))) ) + syslog(LOG_ERR,"setsockopt SO_SNDBUF: (%d) %s\n",err, strerror(err)); + + if (setsockopt(fd, SOL_ATM, SO_ATMQOS, &qos, sizeof(qos)) < 0) + syslog(LOG_ERR,"setsockopt SO_ATMQOS %d", errno); + + err = connect(fd, (struct sockaddr*)&addr, sizeof(struct sockaddr_atmpvc)); + + if (err < 0) + fatal("failed to connect on socket", err); + + /* attach the vcc to device: */ + + be.backend_num = ATM_BACKEND_BR2684; + be.ifspec.method = BR2684_FIND_BYIFNAME; + sprintf(be.ifspec.spec.ifname, "nas%d", lastitf); + be.fcs_in = BR2684_FCSIN_NO; + be.fcs_out = BR2684_FCSOUT_NO; + be.fcs_auto = 0; + be.encaps = encap ? BR2684_ENCAPS_VC : BR2684_ENCAPS_LLC; + be.has_vpiid = 0; + be.send_padding = 0; + be.min_size = 0; + err=ioctl (fd, ATM_SETBACKEND, &be); + if (err == 0) + syslog (LOG_INFO,"Interface configured"); + else { + syslog (LOG_ERR,"Could not configure interface:%s",strerror(errno)); + exit(2); + } + return fd ; +} + + +void usage(char *s) +{ + printf("usage: %s [-b] [[-c number] [-e 0|1] [-s sndbuf] [-q qos] [-a [itf.]vpi.vci]*]*\n", s); + exit(1); +} + + + +int main (int argc, char **argv) +{ + int c, background=0, encap=0, sndbuf=8192; + struct atm_qos reqqos; + int itfnum; + lastsock=-1; + lastitf=0; + + /* st qos to 0 */ + memset(&reqqos, 0, sizeof(reqqos)); + + openlog (LOG_NAME,LOG_OPTION,LOG_FACILITY); + if (argc>1) + while ((c = getopt(argc, argv,"q:a:bc:e:s:?h")) !=EOF) + switch (c) { + case 'q': + printf ("optarg : %s",optarg); + if (text2qos(optarg,&reqqos,0)) fprintf(stderr,"QOS parameter invalid\n"); + break; + case 'a': + assign_vcc(optarg, encap, sndbuf, reqqos); + break; + case 'b': + background=1; + break; + case 'c': + create_br(optarg); + itfnum = atoi(optarg); + break; + case 'e': + encap=(atoi(optarg)); + if(encap<0){ + syslog (LOG_ERR, "invalid encapsulation: %s:\n",optarg); + encap=0; + } + break; + case 's': + sndbuf=(atoi(optarg)); + if(sndbuf<0){ + syslog(LOG_ERR, "Invalid sndbuf: %s, using size of 8192 instead\n",optarg); + sndbuf=8192; + } + break; + case '?': + case 'h': + default: + usage(argv[0]); + } + else + usage(argv[0]); + + if (argc != optind) usage(argv[0]); + + if(lastsock>=0) close(lastsock); + + if (background) { + pid_t pid; + + pid=fork(); + if (pid < 0) { + fprintf(stderr,"Error detaching\n"); + exit(2); + } else if (pid) + exit(0); // This is the parent + + // Become a process group and session group leader + if (setsid()<0) { + fprintf (stderr,"Could not set process group\n"); + exit(2); + } + + // Fork again to let process group leader exit + pid = fork(); + if (pid < 0) { + fprintf(stderr,"Error detaching during second fork\n"); + exit(2); + } else if (pid) + exit(0); // This is the parent + + // Now we're ready for buisness + chdir("/"); // Don't keep directories in use + close(0); close(1); close(2); // Close stdin, -out and -error + /* + Note that this implementation does not keep an open + stdout/err. + If we need them they can be opened now + */ + + } + + create_pidfile(itfnum); + + syslog (LOG_INFO, "RFC 1483/2684 bridge daemon started\n"); + atexit (exitFunc); + + while (1) sleep(30); /* to keep the sockets... */ + return 0; +} + -- 2.39.2