parprouted-0.7/0000775000076400007640000000000010747216200013062 5ustar hazardhazardparprouted-0.7/CHANGELOG0000644000076400007640000000533510747216200014300 0ustar hazardhazardWed 02 Jan 2008 12:12:51 AM EET parprouted 0.7: Many improvements/bug fixes to make parprouted handle mobile hosts moving across Ethernet interfaces. Credit for most of the improvements goes to: Norbert Unterberg and Christian Knecht . Changes to make parprouted cross-compile on ARM, submitted by: Zhouzhi' . ------------------------------------------------------------------------ Sun 26 Aug 2007 03:38:29 PM EEST parprouted 0.65: Fix a problem with incorrect handling of a case when there are two entries for the same IP, incomplete and correct one. This can happen when machine running parprouted is rebooted. Credit for the fix goes to Dennis Borgmann and Matthias Huning . ------------------------------------------------------------------------ Sun 14 Jan 2007 06:22:43 PM EET parprouted 0.64: Don't send ARP requests for incomplete records. Thanks to Ben Pfountz for patch. ------------------------------------------------------------------------ Mon 24 May 2004 09:38:44 PM EEST parprouted 0.63: Fix memory leak reported by Doug Bostrom : in case request queue was full the oldest entry wasn't actually freed. ------------------------------------------------------------------------ Tue 20 Apr 2004 07:37:20 AM EEST parprouted 0.62: Fix problem with systems checking for IP address conflicts, such as Windows XP. Sun 11 Jan 2004 01:38:43 PM EET parprouted 0.6: Now ARP queries from the local host are resolved as well. Various small updates to code and documentation. ------------------------------------------------------------------------ Tue 06 Jan 2004 09:22:09 PM EET parprouted 0.50: Much improved performance and robustness. Request queue is now kept for all received ARP requests, ensuring that all new requests get answered quickly (around 60 ms in my test). ------------------------------------------------------------------------ Wed 18 Sep 2002 11:10:41 AM EEST parprouted 0.42: Fixed incorrect route installation using unfinished ARP entry. More aggressive use of mutexes. ------------------------------------------------------------------------ Sun 07 Jul 2002 10:20:16 PM EEST parprouted 0.4: Refresh ARP entries by ARP pinging them. Or make permanent ARP entries if "-p" switch is given. ------------------------------------------------------------------------ Sun 07 Jul 2002 12:51:36 AM EEST parprouted 0.3: Critical bugfix. Previous parprouted failed in networks of any considerable complexity. Almost complete rewrite. parprouted now is multithreaded and does everything in userspace (including ARP relaying, spoofing and listening). No need to set proxy_arp in kernel anymore. parprouted-0.7/README0000644000076400007640000000067110736536527013763 0ustar hazardhazardparprouted, (C) 2008 Vladimir Ivaschenko ------------------------------------------------------- 1) Installation: Typing "make all && make install" will install parprouted into /usr/local hierarchy. Manual can be found by typing "man parprouted". 2) Contact/copyright: GPLv2, (C) 2008, Vladimir Ivaschenko 3) Acknowledgements: tarpd v1.6 by tricky@cs.hut.fi watchdog by Michael Meskes parprouted-0.7/parprouted.80000644000076400007640000001553610674501464015360 0ustar hazardhazard.\" Automatically generated by Pod::Man v1.34, Pod::Parser v1.13 .\" .\" Standard preamble: .\" ======================================================================== .de Sh \" Subsection heading .br .if t .Sp .ne 5 .PP \fB\\$1\fR .PP .. .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. | will give a .\" real vertical bar. \*(C+ will give a nicer C++. Capital omega is used to .\" do unbreakable dashes and therefore won't be available. \*(C` and \*(C' .\" expand to `' in nroff, nothing in troff, for use with C<>. .tr \(*W-|\(bv\*(Tr .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' 'br\} .\" .\" If the F register is turned on, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.Sh), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . nr % 0 . rr F .\} .\" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .hy 0 .if n .na .\" .\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2). .\" Fear. Run. Save yourself. No user-serviceable parts. . \" fudge factors for nroff and troff .if n \{\ . ds #H 0 . ds #V .8m . ds #F .3m . ds #[ \f1 . ds #] \fP .\} .if t \{\ . ds #H ((1u-(\\\\n(.fu%2u))*.13m) . ds #V .6m . ds #F 0 . ds #[ \& . ds #] \& .\} . \" simple accents for nroff and troff .if n \{\ . ds ' \& . ds ` \& . ds ^ \& . ds , \& . ds ~ ~ . ds / .\} .if t \{\ . ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u" . ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u' . ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u' . ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u' . ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u' . ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u' .\} . \" troff and (daisy-wheel) nroff accents .ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V' .ds 8 \h'\*(#H'\(*b\h'-\*(#H' .ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#] .ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H' .ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u' .ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#] .ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#] .ds ae a\h'-(\w'a'u*4/10)'e .ds Ae A\h'-(\w'A'u*4/10)'E . \" corrections for vroff .if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u' .if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u' . \" for low resolution devices (crt and lpr) .if \n(.H>23 .if \n(.V>19 \ \{\ . ds : e . ds 8 ss . ds o a . ds d- d\h'-1'\(ga . ds D- D\h'-1'\(hy . ds th \o'bp' . ds Th \o'LP' . ds ae ae . ds Ae AE .\} .rm #[ #] #H #V #F C .\" ======================================================================== .\" .IX Title "PARPROUTED 8" .TH PARPROUTED 8 "January 2004" "parprouted" "Proxy ARP Bridging Daemon" .SH "NAME" \&\fBparprouted\fR \- Proxy ARP IP bridging daemon .SH "SYNOPSIS" .IX Header "SYNOPSIS" \&\fBparprouted\fR [\fB\-d\fR] [\fB\-p\fR] \fBinterface\fR [\fBinterface\fR] .SH "DESCRIPTION" .IX Header "DESCRIPTION" parprouted is a daemon for transparent \s-1IP\s0 (Layer 3) proxy \s-1ARP\s0 bridging. Unlike standard bridging, proxy \s-1ARP\s0 bridging allows to bridge Ethernet networks behind wireless nodes. Normal L2 bridging does not work between wireless nodes because wireless does not know about \s-1MAC\s0 addresses used in the wired Ethernet networks. Also this daemon is useful for making transparent firewalls. .PP The daemon listens for incoming \s-1ARP\s0 requests, and in case the location of the requested \s-1IP\s0 address is unknown, forwards them to other interfaces, as well as updates kernel \s-1ARP\s0 table with the received replies. When necessary, the daemon generates an \s-1ARP\s0 reply itself, which causes the stations to send traffic to the host daemon is running on. By automatically adding appropriate /32 routes to Linux kernel \s-1IP\s0 routing table for the hosts learned via \s-1ARP\s0, daemon ensures that the Linux kernel will be able to route the packets to the destination host when it receives them without any need routing/subnetting manually. .PP All routes entered by the daemon have a metric of 50. .PP Unless you use \fB\-p\fR switch, all entries in the \s-1ARP\s0 table will be refreshed (rechecked by sending \s-1ARP\s0 requests) every 50 seconds. This keeps them from being expired by kernel. .PP Normally it takes about 60 ms for a bridge to update all its tables and start sending packets to the destination. .SH "REQUIREMENTS" .IX Header "REQUIREMENTS" This daemon can be used for unicast traffic only. I.e., \s-1DHCP\s0 is not supported. Use software such as dhcrelay to \*(L"bridge\*(R" \s-1DHCP\s0. .PP You should have an \s-1IP\s0 address assigned on all of your interfaces that you do bridging on. There is no need for this address to be from the same networks as the bridged networks. Any dummy address will do. .PP The system should have correct default route. .PP parprouted requires \*(L"ip\*(R" program from iproute2 tools to be installed in /sbin. If it is installed in another location, please replace \*(L"/sbin/ip\*(R" occurances in the source with the correct path. As well you should have proc filesystem mounted in /proc because the daemon uses /proc/net/arp. .PP parprouted is designed for and tested only with Linux 2.4.x kernels. .SH "OPTIONS" .IX Header "OPTIONS" The list of interfaces to do bridging on should be given via the command line. .PP The daemon accepts the following switches: .PP \&\fB\-d\fR, which stands for debugging. If you run it in debugging mode the daemon will not go to background and will print additional debugging information to stdout/stderr. .PP \&\fB\-p\fR, which makes all \s-1ARP\s0 entries to be permanent. This will also result in that \s-1ARP\s0 tables will not be refreshed by \s-1ARP\s0 pings. .SH "EXAMPLE" .IX Header "EXAMPLE" To bridge between wlan0 and eth0: \fBparprouted eth0 wlan0\fR .SH "AUTHOR" .IX Header "AUTHOR" .Vb 2 \& (C) 2004, Vladimir Ivaschenko \& http://www.hazard.maks.net .Ve parprouted-0.7/parprouted.c0000644000076400007640000003213710747215431015424 0ustar hazardhazard/* parprouted: ProxyARP routing daemon. * (C) 2008 Vladimir Ivaschenko * * This application is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public * License as published by the Free Software Foundation; either * version 2 of the License. * * This software 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 * Library General Public License for more details. * * You should have received a copy of the GNU Library General Public * License along with this library; if not, write to the * Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. * */ #include "parprouted.h" char *progname; int debug=0; int verbose=0; int option_arpperm=0; static int perform_shutdown=0; char *errstr; pthread_t my_threads[MAX_IFACES+1]; int last_thread_idx=-1; char * ifaces[MAX_IFACES]; int last_iface_idx=-1; ARPTAB_ENTRY **arptab; pthread_mutex_t arptab_mutex; ARPTAB_ENTRY * replace_entry(struct in_addr ipaddr, char *dev) { ARPTAB_ENTRY * cur_entry=*arptab; ARPTAB_ENTRY * prev_entry=NULL; while (cur_entry != NULL && ( ipaddr.s_addr != cur_entry->ipaddr_ia.s_addr || ( strncmp(cur_entry->ifname,dev,strlen(dev)) != 0 ) ) ) { prev_entry = cur_entry; cur_entry = cur_entry->next; }; if (cur_entry == NULL) { if (debug) printf("Creating new arptab entry %s(%s)\n", inet_ntoa(ipaddr), dev); if ((cur_entry = (ARPTAB_ENTRY *) malloc(sizeof(ARPTAB_ENTRY))) == NULL) { errstr = strerror(errno); syslog(LOG_INFO, "No memory: %s", errstr); } else { if (prev_entry == NULL) { *arptab=cur_entry; } else { prev_entry->next = cur_entry; } cur_entry->next = NULL; cur_entry->ifname[0] = '\0'; cur_entry->route_added = 0; cur_entry->want_route = 1; } } return cur_entry; } int findentry(struct in_addr ipaddr) { ARPTAB_ENTRY * cur_entry=*arptab; ARPTAB_ENTRY * prev_entry=NULL; while (cur_entry != NULL && ipaddr.s_addr != cur_entry->ipaddr_ia.s_addr) { prev_entry = cur_entry; cur_entry = cur_entry->next; }; if (cur_entry == NULL) return 0; else return 1; } /* Remove all entires in arptab where ipaddr is NOT on interface dev */ int remove_other_routes(struct in_addr ipaddr, const char* dev) { ARPTAB_ENTRY * cur_entry; int removed = 0; for (cur_entry=*arptab; cur_entry != NULL; cur_entry = cur_entry->next) { if (ipaddr.s_addr == cur_entry->ipaddr_ia.s_addr && strcmp(dev, cur_entry->ifname) != 0) { if (debug && cur_entry->want_route) printf("Marking entry %s(%s) for removal\n", inet_ntoa(ipaddr), cur_entry->ifname); cur_entry->want_route = 0; ++removed; } } return removed; } /* Remove route from kernel */ int route_remove(ARPTAB_ENTRY* cur_entry) { char routecmd_str[ROUTE_CMD_LEN]; int success = 1; if (snprintf(routecmd_str, ROUTE_CMD_LEN-1, "/sbin/ip route del %s/32 metric 50 dev %s scope link", inet_ntoa(cur_entry->ipaddr_ia), cur_entry->ifname) > ROUTE_CMD_LEN-1) { syslog(LOG_INFO, "ip route command too large to fit in buffer!"); } else { if (system(routecmd_str) != 0) { syslog(LOG_INFO, "'%s' unsuccessful!", routecmd_str); if (debug) printf("%s failed\n", routecmd_str); success = 0; } else { if (debug) printf("%s success\n", routecmd_str); success = 1; } } if (success) cur_entry->route_added = 0; return success; } /* Add route into kernel */ int route_add(ARPTAB_ENTRY* cur_entry) { char routecmd_str[ROUTE_CMD_LEN]; int success = 1; if (snprintf(routecmd_str, ROUTE_CMD_LEN-1, "/sbin/ip route add %s/32 metric 50 dev %s scope link", inet_ntoa(cur_entry->ipaddr_ia), cur_entry->ifname) > ROUTE_CMD_LEN-1) { syslog(LOG_INFO, "ip route command too large to fit in buffer!"); } else { if (system(routecmd_str) != 0) { syslog(LOG_INFO, "'%s' unsuccessful, will try to remove!", routecmd_str); if (debug) printf("%s failed\n", routecmd_str); route_remove(cur_entry); success = 0; } else { if (debug) printf("%s success\n", routecmd_str); success = 1; } } if (success) cur_entry->route_added = 1; return success; } void processarp(int in_cleanup) { ARPTAB_ENTRY *cur_entry=*arptab, *prev_entry=NULL; /* First loop to remove unwanted routes */ while (cur_entry != NULL) { if (debug && verbose) printf("Working on route %s(%s) tstamp %u want_route %d\n", inet_ntoa(cur_entry->ipaddr_ia), cur_entry->ifname, (int) cur_entry->tstamp, cur_entry->want_route); if ( !cur_entry->want_route || time(NULL) - cur_entry->tstamp > ARP_TABLE_ENTRY_TIMEOUT || in_cleanup) { if (cur_entry->route_added) route_remove(cur_entry); /* remove from arp list */ if (debug) printf("Delete arp %s(%s)\n", inet_ntoa(cur_entry->ipaddr_ia), cur_entry->ifname); if (prev_entry != NULL) { prev_entry->next = cur_entry->next; free(cur_entry); cur_entry=prev_entry->next; } else { *arptab = cur_entry->next; free(cur_entry); cur_entry=*arptab; } } else { prev_entry = cur_entry; cur_entry = cur_entry->next; } } /* while loop */ /* Now loop to add new routes */ cur_entry=*arptab; while (cur_entry != NULL) { if (time(NULL) - cur_entry->tstamp <= ARP_TABLE_ENTRY_TIMEOUT && cur_entry->want_route && !cur_entry->route_added && !in_cleanup) { /* add route to the kernel */ route_add(cur_entry); } cur_entry = cur_entry->next; } /* while loop */ } void parseproc() { FILE *arpf; int firstline; ARPTAB_ENTRY *entry; char line[ARP_LINE_LEN]; struct in_addr ipaddr; int incomplete=0; int i; char *ip, *mac, *dev, *hw, *flags, *mask; /* Parse /proc/net/arp table */ if ((arpf = fopen(PROC_ARP, "r")) == NULL) { errstr = strerror(errno); syslog(LOG_INFO, "Error during ARP table open: %s", errstr); } firstline=1; while (!feof(arpf)) { if (fgets(line, ARP_LINE_LEN, arpf) == NULL) { if (!ferror(arpf)) break; else { errstr = strerror(errno); syslog(LOG_INFO, "Error during ARP table open: %s", errstr); } } else { if (firstline) { firstline=0; continue; } if (debug && verbose) printf("read ARP line %s", line); incomplete=0; /* Incomplete ARP entries with MAC 00:00:00:00:00:00 */ if (strstr(line, "00:00:00:00:00:00") != NULL) incomplete=1; /* Incomplete entries having flag 0x0 */ if (strstr(line, "0x0") != NULL) incomplete=1; ip=strtok(line, " "); if ((inet_aton(ip, &ipaddr)) == -1) syslog(LOG_INFO, "Error parsing IP address %s", ip); /* if IP address is marked as undiscovered and does not exist in arptab, send ARP request to all ifaces */ if (incomplete &! findentry(ipaddr) ) { if (debug) printf("incomplete entry %s found, request on all interfaces\n", inet_ntoa(ipaddr)); for (i=0; i <= last_iface_idx; i++) arp_req(ifaces[i], ipaddr, 0); } /* Hardware type */ hw=strtok(NULL, " "); /* flags */ flags=strtok(NULL, " "); /* MAC address */ mac=strtok(NULL, " "); /* Mask */ mask=strtok(NULL, " "); /* Device */ dev=strtok(NULL, " "); if (dev[strlen(dev)-1] == '\n') { dev[strlen(dev)-1] = '\0'; } entry=replace_entry(ipaddr, dev); if (entry->incomplete != incomplete && debug) printf("change entry %s(%s) to incomplete=%d\n", ip, dev, incomplete); entry->ipaddr_ia.s_addr = ipaddr.s_addr; entry->incomplete = incomplete; if (strlen(mac) < ARP_TABLE_ENTRY_LEN) strncpy(entry->hwaddr, mac, ARP_TABLE_ENTRY_LEN); else syslog(LOG_INFO, "Error during ARP table parsing"); if (strlen(dev) < ARP_TABLE_ENTRY_LEN) strncpy(entry->ifname, dev, ARP_TABLE_ENTRY_LEN); else syslog(LOG_INFO, "Error during ARP table parsing"); /* do not add routes for incomplete entries */ if (debug && entry->want_route != !incomplete) printf("%s(%s): set want_route %d\n", inet_ntoa(entry->ipaddr_ia), entry->ifname, !incomplete); entry->want_route = !incomplete; /* Remove route from kernel if it already exists through a different interface */ if (entry->want_route) { if (remove_other_routes(entry->ipaddr_ia, entry->ifname) > 0) if (debug) printf("Found ARP entry %s(%s), removed entries via other interfaces\n", inet_ntoa(entry->ipaddr_ia), entry->ifname); } time(&entry->tstamp); if (debug && !entry->route_added && entry->want_route) { printf("arptab entry: '%s' HWAddr: '%s' Dev: '%s' route_added:%d want_route:%d\n", inet_ntoa(entry->ipaddr_ia), entry->hwaddr, entry->ifname, entry->route_added, entry->want_route); } } } if (fclose(arpf)) { errstr = strerror(errno); syslog(LOG_INFO, "Error during ARP table open: %s", errstr); } } void cleanup() { /* FIXME: I think this is a wrong way to do it ... */ syslog(LOG_INFO, "Received signal; cleaning up."); /* for (i=0; i <= last_thread_idx; i++) { pthread_cancel(my_threads[i]); } */ pthread_mutex_trylock(&arptab_mutex); processarp(1); syslog(LOG_INFO, "Terminating."); exit(1); } void sighandler() { /* FIXME: I think this is a wrong way to do it ... */ perform_shutdown=1; } void *main_thread() { time_t last_refresh; signal(SIGINT, sighandler); signal(SIGTERM, sighandler); signal(SIGHUP, sighandler); pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL); pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, NULL); pthread_cleanup_push(cleanup, NULL); while (1) { if (perform_shutdown) { pthread_exit(0); } pthread_testcancel(); pthread_mutex_lock(&arptab_mutex); parseproc(); processarp(0); pthread_mutex_unlock(&arptab_mutex); usleep(SLEEPTIME); if (!option_arpperm && time(NULL)-last_refresh > REFRESHTIME) { pthread_mutex_lock(&arptab_mutex); refresharp(*arptab); pthread_mutex_unlock(&arptab_mutex); time(&last_refresh); } } /* required since pthread_cleanup_* are implemented as macros */ pthread_cleanup_pop(0); } int main (int argc, char **argv) { pid_t child_pid; int i, help=1; progname = (char *) basename(argv[0]); for (i = 1; i < argc; i++) { if (!strcmp(argv[i],"-d")) { debug=1; help=0; } else if (!strcmp(argv[i],"-p")) { option_arpperm=1; help=0; } else if (!strcmp(argv[i],"-h") || !strcmp(argv[i],"--help")) { break; } else { last_iface_idx++; ifaces[last_iface_idx]=argv[i]; help=0; } } if (help || last_iface_idx <= -1) { printf("parprouted: proxy ARP routing daemon, version %s.\n", VERSION); printf("(C) 2007 Vladimir Ivaschenko , GPL2 license.\n"); printf("Usage: parprouted [-d] [-p] interface [interface]\n"); exit(1); } if (!debug) { /* fork to go into the background */ if ((child_pid = fork()) < 0) { fprintf(stderr, "could not fork(): %s", strerror(errno)); exit(1); } else if (child_pid > 0) { /* fork was ok, wait for child to exit */ if (waitpid(child_pid, NULL, 0) != child_pid) { perror(progname); exit(1); } /* and exit myself */ exit(0); } /* and fork again to make sure we inherit all rights from init */ if ((child_pid = fork()) < 0) { perror(progname); exit(1); } else if (child_pid > 0) exit(0); /* create our own session */ setsid(); /* close stdin/stdout/stderr */ close(0); close(1); close(2); } openlog(progname, LOG_PID | LOG_CONS | LOG_PERROR, LOG_DAEMON); syslog(LOG_INFO, "Starting."); signal(SIGINT, sighandler); signal(SIGTERM, sighandler); signal(SIGHUP, sighandler); if ((arptab = (ARPTAB_ENTRY **) malloc(sizeof(ARPTAB_ENTRY **))) == NULL) { errstr = strerror(errno); syslog(LOG_INFO, "No memory: %s", errstr); } *arptab = NULL; pthread_mutex_init(&arptab_mutex, NULL); pthread_mutex_init(&req_queue_mutex, NULL); if (pthread_create(&my_threads[++last_thread_idx], NULL, main_thread, NULL)) { syslog(LOG_ERR, "Error creating main thread."); abort(); } for (i=0; i <= last_iface_idx; i++) { if (pthread_create(&my_threads[++last_thread_idx], NULL, (void *) arp, (void *) ifaces[i])) { syslog(LOG_ERR, "Error creating ARP thread for %s.",ifaces[i]); abort(); } if (debug) printf("Created ARP thread for %s.\n",ifaces[i]); } if (pthread_join(my_threads[0], NULL)) { syslog(LOG_ERR, "Error joining thread."); abort(); } while (waitpid(-1, NULL, WNOHANG)) { } exit(1); } parprouted-0.7/Makefile0000644000076400007640000000117010747202342014521 0ustar hazardhazardEXTRA_CFLAGS = #CC = gcc CFLAGS = -g -O2 -Wall $(EXTRA_CFLAGS) # For ARM: # CFLAGS = -Wall $(EXTRA_CFLAGS) LDFLAGS = OBJS = parprouted.o arp.o LIBS = -lpthread all: parprouted install: all install parprouted /usr/local/sbin install parprouted.8 /usr/local/man/man8 clean: rm -f $(OBJS) parprouted core parprouted: ${OBJS} ${CC} -g -o parprouted ${OBJS} ${CFLAGS} ${LDFLAGS} ${LIBS} parprouted.8: parprouted.pod pod2man --section=8 --center="Proxy ARP Bridging Daemon" parprouted.pod --release "parprouted" --date "`date '+%B %Y'`" > parprouted.8 parprouted.o : parprouted.c parprouted.h arp.o : arp.c parprouted.h parprouted-0.7/arp.c0000644000076400007640000002760310747213451014023 0ustar hazardhazard/* parprouted: ProxyARP routing daemon. * (C) 2008 Vladimir Ivaschenko * * This application is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public * License as published by the Free Software Foundation; either * version 2 of the License. * * This software 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 * Library General Public License for more details. * * You should have received a copy of the GNU Library General Public * License along with this library; if not, write to the * Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. */ #include #include #include #include #include #include #include "parprouted.h" typedef struct _ether_arp_frame { struct ether_header ether_hdr; struct ether_arp arp; } __attribute__ ((packed)) ether_arp_frame; typedef struct _req_struct { ether_arp_frame req_frame; struct sockaddr_ll req_if; struct _req_struct *next; } RQ_ENTRY; RQ_ENTRY *req_queue = NULL; RQ_ENTRY *req_queue_tail = NULL; int req_queue_len = 0; pthread_mutex_t req_queue_mutex; /* Check if the IP address exists in the arptab */ int ipaddr_known(ARPTAB_ENTRY *list, struct in_addr addr, char *ifname) { while (list != NULL) { /* If we have this address in the table and ARP request comes from a different interface, then we can reply */ if ( addr.s_addr == list->ipaddr_ia.s_addr && strcmp(ifname, list->ifname) && list->incomplete == 0) { return 1; } list = list->next; } if (debug) printf ("Did not find match for %s(%s)\n", inet_ntoa(addr), ifname); return 0; } /* Wait for an ARP packet */ int arp_recv(int sock, ether_arp_frame *frame) { char packet[4096]; int nread; memset(frame, 0, sizeof(ether_arp_frame)); nread=recv(sock, &packet, sizeof(packet), 0); if (nread > sizeof(ether_arp_frame)) { nread=sizeof(ether_arp_frame); } memcpy(frame, &packet, nread); return nread; } /* Send ARP is-at reply */ void arp_reply(ether_arp_frame *reqframe, struct sockaddr_ll *ifs) { struct ether_arp *arp = &reqframe->arp; unsigned char ip[4]; int sock; sock = socket(AF_PACKET, SOCK_RAW, htons(ETH_P_ARP)); if (bind(sock, (struct sockaddr *) ifs, sizeof(struct sockaddr_ll)) < 0) { fprintf(stderr, "arp_reply() bind: %s\n", strerror(errno)); abort(); } memcpy(&reqframe->ether_hdr.ether_dhost, &arp->arp_sha, ETH_ALEN); memcpy(&reqframe->ether_hdr.ether_shost, ifs->sll_addr, ETH_ALEN); memcpy(&arp->arp_tha, &arp->arp_sha, ETH_ALEN); memcpy(&arp->arp_sha, ifs->sll_addr, ETH_ALEN); memcpy(ip, &arp->arp_spa, 4); memcpy(&arp->arp_spa, &arp->arp_tpa, 4); memcpy(&arp->arp_tpa, ip, 4); arp->arp_op = htons(ARPOP_REPLY); if (debug) { struct in_addr sia; struct in_addr dia; sia.s_addr = *((long *)arp->arp_spa); dia.s_addr = *((long *)arp->arp_tpa); printf("Replying to %s faking %s\n", inet_ntoa(sia), inet_ntoa(dia)); } sendto(sock, reqframe, sizeof(ether_arp_frame), 0, (struct sockaddr *)ifs, sizeof(struct sockaddr_ll)); close(sock); } /* Send ARP who-has request */ void arp_req(char *ifname, struct in_addr remaddr, int gratuitous) { ether_arp_frame frame; struct ether_arp *arp = &frame.arp; int sock; struct sockaddr_ll ifs; struct ifreq ifr; unsigned long ifaddr; struct sockaddr_in *sin; /* Make sure that interface is not empty */ if (strcmp(ifname, "") == 0) return; sock = socket(AF_PACKET, SOCK_RAW, htons(ETH_P_ARP)); /* Get the hwaddr and ifindex of the interface */ memset(ifr.ifr_name, 0, IFNAMSIZ); strncpy(ifr.ifr_name, (char *) ifname, IFNAMSIZ); if(ioctl(sock, SIOCGIFHWADDR, &ifr) < 0) { syslog(LOG_ERR, "error in arp_req(): ioctl SIOCGIFHWADDR for %s: %s\n", (char *) ifname, strerror(errno)); abort(); } memset(ifs.sll_addr, 0, ETH_ALEN); memcpy(ifs.sll_addr, ifr.ifr_hwaddr.sa_data, ETH_ALEN); if(ioctl(sock, SIOCGIFINDEX, &ifr) < 0) { syslog(LOG_ERR, "error in arp_req(): ioctl SIOCGIFINDEX for %s: %s", (char *) ifname, strerror(errno)); return; } ifs.sll_family = AF_PACKET; ifs.sll_protocol = htons(ETH_P_ARP); ifs.sll_ifindex = ifr.ifr_ifindex; ifs.sll_hatype = ARPHRD_ETHER; ifs.sll_pkttype = PACKET_BROADCAST; ifs.sll_halen = ETH_ALEN; if (ioctl(sock, SIOCGIFADDR, &ifr) == 0) { sin = (struct sockaddr_in *) &ifr.ifr_addr; ifaddr = sin->sin_addr.s_addr; } else { syslog(LOG_ERR, "error: ioctl SIOCGIFADDR for %s: %s", (char *) ifname, strerror(errno)); return; } memset(&frame.ether_hdr.ether_dhost, 0xFF, ETH_ALEN); memcpy(&frame.ether_hdr.ether_shost, ifs.sll_addr, ETH_ALEN); frame.ether_hdr.ether_type = htons(ETHERTYPE_ARP); arp->arp_hrd = htons(ARPHRD_ETHER); arp->arp_pro = htons(ETH_P_IP); arp->arp_hln = 6; arp->arp_pln = 4; memset(&arp->arp_tha, 0, ETH_ALEN); memcpy(&arp->arp_sha, ifs.sll_addr, ETH_ALEN); memcpy(&arp->arp_tpa, &remaddr.s_addr, 4); if (gratuitous) memcpy(&arp->arp_spa, &remaddr.s_addr, 4); else memcpy(&arp->arp_spa, &ifaddr, 4); arp->arp_op = htons(ARPOP_REQUEST); if (debug) printf("Sending ARP request for %s to %s\n", inet_ntoa(remaddr), ifname); sendto(sock, &frame, sizeof(ether_arp_frame), 0, (struct sockaddr *) &ifs, sizeof(struct sockaddr_ll)); close(sock); } /* ARP ping all entries in the table */ void refresharp(ARPTAB_ENTRY *list) { if (debug) printf("Refreshing ARP entries.\n"); while(list != NULL) { arp_req(list->ifname, list->ipaddr_ia, 0); list = list->next; } } int rq_add(ether_arp_frame *req_frame, struct sockaddr_ll *req_if) { RQ_ENTRY *new_entry; if ((new_entry = (RQ_ENTRY *) malloc(sizeof(RQ_ENTRY))) == NULL) { syslog(LOG_INFO, "No memory: %s", strerror(errno)); return 0; } pthread_mutex_lock(&req_queue_mutex); req_queue_len++; /* Check if the list has more entries than MAX_RQ_SIZE, * and delete the oldest entry */ if (req_queue_len > MAX_RQ_SIZE) { RQ_ENTRY *temp; if (debug) printf("Request queue has grown too large, deleting last element\n"); temp = req_queue; req_queue = req_queue->next; req_queue_len--; free(temp); } /* Add entry to the list */ if (req_queue != NULL) req_queue_tail->next = new_entry; else req_queue = new_entry; req_queue_tail = new_entry; new_entry->next = NULL; memcpy(&new_entry->req_frame, req_frame, sizeof(ether_arp_frame)); memcpy(&new_entry->req_if, req_if, sizeof(struct sockaddr_ll)); pthread_mutex_unlock(&req_queue_mutex); return 1; } void rq_process(struct in_addr ipaddr, int ifindex) { RQ_ENTRY *cur_entry; RQ_ENTRY *prev_entry = NULL; pthread_mutex_lock(&arptab_mutex); parseproc(); processarp(0); pthread_mutex_unlock(&arptab_mutex); pthread_mutex_lock(&req_queue_mutex); cur_entry = req_queue; /* Walk through the list */ while (cur_entry != NULL) { if ( ipaddr.s_addr == *((long *) cur_entry->req_frame.arp.arp_tpa) && ifindex != cur_entry->req_if.sll_ifindex ) { if (debug) printf("Found %s in request queue\n", inet_ntoa(ipaddr)); arp_reply(&cur_entry->req_frame, &cur_entry->req_if); /* Delete entry from the linked list */ if (cur_entry == req_queue_tail) req_queue_tail = prev_entry; if (prev_entry != NULL) prev_entry->next = cur_entry->next; else req_queue = cur_entry->next; free(cur_entry); cur_entry = prev_entry; req_queue_len--; } if (cur_entry != NULL) { prev_entry = cur_entry; cur_entry = cur_entry->next; } } pthread_mutex_unlock(&req_queue_mutex); } void *arp(char *ifname) { int sock,i; struct sockaddr_ll ifs; struct ifreq ifr; pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL); pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, NULL); sock = socket(AF_PACKET, SOCK_RAW, htons(ETH_P_ARP)); if(sock == -1) { fprintf(stderr, "Socket error %d.\n", errno); exit(1); } /* Get the hwaddr and ifindex of the interface */ memset(ifr.ifr_name, 0, IFNAMSIZ); strncpy(ifr.ifr_name, (char *) ifname, IFNAMSIZ); if(ioctl(sock, SIOCGIFHWADDR, &ifr) < 0) { syslog(LOG_ERR, "error: ioctl SIOCGIFHWADDR for %s: %s\n", (char *) ifname, strerror(errno)); abort(); } memset(ifs.sll_addr, 0, ETH_ALEN); memcpy(ifs.sll_addr, ifr.ifr_hwaddr.sa_data, ETH_ALEN); if(ioctl(sock, SIOCGIFINDEX, &ifr) < 0) { syslog(LOG_ERR, "error: ioctl SIOCGIFINDEX for %s: %s", (char *) ifname, strerror(errno)); abort(); } ifs.sll_family = AF_PACKET; ifs.sll_protocol = htons(ETH_P_ARP); ifs.sll_ifindex = ifr.ifr_ifindex; ifs.sll_hatype = ARPHRD_ETHER; ifs.sll_pkttype = PACKET_BROADCAST; ifs.sll_halen = ETH_ALEN; if(bind(sock, (struct sockaddr *)&ifs, sizeof(struct sockaddr_ll)) < 0) { fprintf(stderr, "Bind %s: %d\n", (char *) ifname, errno); abort(); } while (1) { ether_arp_frame frame; unsigned long src; unsigned long dst; struct in_addr sia; struct in_addr dia; do { pthread_testcancel(); /* Sleep a bit in order not to overload the system */ usleep(300); if (arp_recv(sock, &frame) <= 0) continue; /* Insert all the replies into ARP table */ if (frame.arp.arp_op == ntohs(ARPOP_REPLY)) { /* Received frame is an ARP reply */ struct arpreq k_arpreq; int arpsock; struct sockaddr_in *sin; if ((arpsock = socket(AF_INET, SOCK_DGRAM, 0)) < 0) { syslog(LOG_ERR, "error: ARP socket for %s: %s", (char *) ifname, strerror(errno)); continue; } k_arpreq.arp_ha.sa_family = ARPHRD_ETHER; memcpy(&k_arpreq.arp_ha.sa_data, &frame.arp.arp_sha, sizeof(frame.arp.arp_sha)); k_arpreq.arp_flags = ATF_COM; if (option_arpperm) k_arpreq.arp_flags = k_arpreq.arp_flags | ATF_PERM; strncpy(k_arpreq.arp_dev, ifname, sizeof(k_arpreq.arp_dev)); k_arpreq.arp_pa.sa_family = AF_INET; sin = (struct sockaddr_in *) &k_arpreq.arp_pa; memcpy(&sin->sin_addr.s_addr, &frame.arp.arp_spa, sizeof(sin->sin_addr)); /* Update kernel ARP table with the data from reply */ if (debug) printf("Received reply: updating kernel ARP table for %s(%s).\n", inet_ntoa(sin->sin_addr), (char *) ifname); if (ioctl(arpsock, SIOCSARP, &k_arpreq) < 0) { syslog(LOG_ERR, "error: ioctl SIOCSARP for %s(%s): %s", inet_ntoa(sin->sin_addr), (char *) ifname, strerror(errno)); close(arpsock); continue; } close(arpsock); /* Check if reply is for one of the requests in request queue */ rq_process(sin->sin_addr, ifs.sll_ifindex); /* send gratuitous arp request to all other interfaces to let them * update their ARP tables quickly */ for (i=0; i <= last_iface_idx; i++) { if (strcmp(ifaces[i], ifname)) { arp_req(ifaces[i], sin->sin_addr, 1); } } } } while (frame.arp.arp_op != htons(ARPOP_REQUEST)); /* Received frame is an ARP request */ memcpy(&src,(char *)frame.arp.arp_spa,4); memcpy(&dst,(char *)frame.arp.arp_tpa,4); dia.s_addr = dst; sia.s_addr = src; if (debug) printf("Received ARP request for %s on iface %s\n", inet_ntoa(dia), (char *) ifname); if (memcmp(&dia,&sia,sizeof(dia)) && dia.s_addr != 0) { pthread_mutex_lock(&arptab_mutex); /* Relay the ARP request to all other interfaces */ for (i=0; i <= last_iface_idx; i++) { if (strcmp(ifaces[i], ifname)) { arp_req(ifaces[i], dia, 0); } } /* Add the request to the request queue */ if (debug) printf("Adding %s to request queue\n", inet_ntoa(sia)); rq_add(&frame, &ifs); pthread_mutex_unlock(&arptab_mutex); } } } parprouted-0.7/parprouted.pod0000644000076400007640000000552010736536545015772 0ustar hazardhazard =pod =head1 NAME B - Proxy ARP IP bridging daemon =head1 SYNOPSIS B [B<-d>] [B<-p>] B [B] =head1 DESCRIPTION parprouted is a daemon for transparent IP (Layer 3) proxy ARP bridging. Unlike standard bridging, proxy ARP bridging allows to bridge Ethernet networks behind wireless nodes. Normal L2 bridging does not work between wireless nodes because wireless does not know about MAC addresses used in the wired Ethernet networks. Also this daemon is useful for making transparent firewalls. The daemon listens for incoming ARP requests, and in case the location of the requested IP address is unknown, forwards them to other interfaces, as well as updates kernel ARP table with the received replies. When necessary, the daemon generates an ARP reply itself, which causes the stations to send traffic to the host daemon is running on. By automatically adding appropriate /32 routes to Linux kernel IP routing table for the hosts learned via ARP, daemon ensures that the Linux kernel will be able to route the packets to the destination host when it receives them without any need routing/subnetting manually. All routes entered by the daemon have a metric of 50. Unless you use B<-p> switch, all entries in the ARP table will be refreshed (rechecked by sending ARP requests) every 50 seconds. This keeps them from being expired by kernel. Normally it takes about 60 ms for a bridge to update all its tables and start sending packets to the destination. =head1 REQUIREMENTS This daemon can be used for unicast traffic only. I.e., DHCP is not supported. Use software such as dhcrelay to "bridge" DHCP. You should have an IP address assigned on all of your interfaces that you do bridging on. There is no need for this address to be from the same networks as the bridged networks. Any dummy address will do. The system should have correct default route. parprouted requires "ip" program from iproute2 tools to be installed in /sbin. If it is installed in another location, please replace "/sbin/ip" occurances in the source with the correct path. As well you should have proc filesystem mounted in /proc because the daemon uses /proc/net/arp. parprouted is designed for and tested only with Linux 2.4.x kernels. =head1 OPTIONS The list of interfaces to do bridging on should be given via the command line. The daemon accepts the following switches: B<-d>, which stands for debugging. If you run it in debugging mode the daemon will not go to background and will print additional debugging information to stdout/stderr. B<-p>, which makes all ARP entries to be permanent. This will also result in that ARP tables will not be refreshed by ARP pings. =head1 EXAMPLE To bridge between wlan0 and eth0: B =head1 AUTHOR (C) 2008, Vladimir Ivaschenko http://www.hazard.maks.net parprouted-0.7/parprouted.h0000644000076400007640000000426510747212424015431 0ustar hazardhazard/* parprouted: ProxyARP routing daemon. * (C) 2008 Vladimir Ivaschenko * * This application is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public * License as published by the Free Software Foundation; either * version 2 of the License. * * This software 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 * Library General Public License for more details. * * You should have received a copy of the GNU Library General Public * License along with this library; if not, write to the * Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. */ #define PROC_ARP "/proc/net/arp" #define ARP_LINE_LEN 255 #define ARP_TABLE_ENTRY_LEN 20 #define ARP_TABLE_ENTRY_TIMEOUT 60 /* seconds */ #define ROUTE_CMD_LEN 255 #define SLEEPTIME 1000000 /* ms */ #define REFRESHTIME 50 /* seconds */ #define MAX_IFACES 10 #define MAX_RQ_SIZE 50 /* maximum size of request queue */ #define VERSION "0.7" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include typedef struct arptab_entry { struct in_addr ipaddr_ia; char hwaddr[ARP_TABLE_ENTRY_LEN]; char ifname[ARP_TABLE_ENTRY_LEN]; time_t tstamp; int route_added; int incomplete; int want_route; struct arptab_entry *next; } ARPTAB_ENTRY; extern int debug; extern int verbose; extern int option_arpperm; extern ARPTAB_ENTRY **arptab; extern pthread_mutex_t arptab_mutex; extern pthread_mutex_t req_queue_mutex; extern char * ifaces[MAX_IFACES]; extern int last_iface_idx; extern void *arp(char *ifname); extern void refresharp(ARPTAB_ENTRY *list); extern void arp_req(char *ifname, struct in_addr remaddr, int gratuitous); extern void parseproc(); extern void processarp(int cleanup); parprouted-0.7/COPYING0000644000076400007640000004312710674501464014132 0ustar hazardhazard GNU GENERAL PUBLIC LICENSE Version 2, June 1991 Copyright (C) 1989, 1991 Free Software Foundation, Inc. 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This General Public License applies to most of the Free Software Foundation's software and to any other program whose authors commit to using it. (Some other Free Software Foundation software is covered by the GNU Library General Public License instead.) You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. For example, if you distribute copies of such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. Finally, any free program is threatened constantly by software patents. We wish to avoid the danger that redistributors of a free program will individually obtain patent licenses, in effect making the program proprietary. To prevent this, we have made it clear that any patent must be licensed for everyone's free use or not licensed at all. The precise terms and conditions for copying, distribution and modification follow. GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any derivative work under copyright law: that is to say, a work containing the Program or a portion of it, either verbatim or with modifications and/or translated into another language. (Hereinafter, translation is included without limitation in the term "modification".) Each licensee is addressed as "you". Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running the Program is not restricted, and the output from the Program is covered only if its contents constitute a work based on the Program (independent of having been made by running the Program). Whether that is true depends on what the Program does. 1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and give any other recipients of the Program a copy of this License along with the Program. You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. 2. You may modify your copy or copies of the Program or any portion of it, thus forming a work based on the Program, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: a) You must cause the modified files to carry prominent notices stating that you changed the files and the date of any change. b) You must cause any work that you distribute or publish, that in whole or in part contains or is derived from the Program or any part thereof, to be licensed as a whole at no charge to all third parties under the terms of this License. c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the most ordinary way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this License. (Exception: if the Program itself is interactive but does not normally print such an announcement, your work based on the Program is not required to print an announcement.) These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Program, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Program, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Program. In addition, mere aggregation of another work not based on the Program with the Program (or with a work based on the Program) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. 3. You may copy and distribute the Program (or a work based on it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you also do one of the following: a) Accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, b) Accompany it with a written offer, valid for at least three years, to give any third party, for a charge no more than your cost of physically performing source distribution, a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, c) Accompany it with the information you received as to the offer to distribute corresponding source code. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form with such an offer, in accord with Subsection b above.) The source code for a work means the preferred form of the work for making modifications to it. For an executable work, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the executable. However, as a special exception, the source code distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. If distribution of executable or object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place counts as distribution of the source code, even though third parties are not compelled to copy the source along with the object code. 4. You may not copy, modify, sublicense, or distribute the Program except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense or distribute the Program is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. 5. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Program or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Program (or any work based on the Program), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Program or works based on it. 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties to this License. 7. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Program at all. For example, if a patent license would not permit royalty-free redistribution of the Program by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Program. If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply and the section as a whole is intended to apply in other circumstances. It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system, which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. 8. If the distribution and/or use of the Program is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Program under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. 9. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of this License, you may choose any version ever published by the Free Software Foundation. 10. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) 19yy 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 2 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, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Also add information on how to contact you by electronic and paper mail. If the program is interactive, make it output a short notice like this when it starts in an interactive mode: Gnomovision version 69, Copyright (C) 19yy name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here is a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (which makes passes at compilers) written by James Hacker. , 1 April 1989 Ty Coon, President of Vice This General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Library General Public License instead of this License.