ip_fil.c (5e985db5) | ip_fil.c (ab25eeb5) |
---|---|
1/* 2 * Copyright (C) 1993-2001, 2003 by Darren Reed. 3 * 4 * See the IPFILTER.LICENCE file for details on licencing. 5 * | 1/* 2 * Copyright (C) 1993-2001, 2003 by Darren Reed. 3 * 4 * See the IPFILTER.LICENCE file for details on licencing. 5 * |
6 * Copyright 2005 Sun Microsystems, Inc. All rights reserved. | 6 * Copyright 2006 Sun Microsystems, Inc. All rights reserved. |
7 * Use is subject to license terms. 8 */ 9 10#pragma ident "%Z%%M% %I% %E% SMI" 11 12#if !defined(lint) | 7 * Use is subject to license terms. 8 */ 9 10#pragma ident "%Z%%M% %I% %E% SMI" 11 12#if !defined(lint) |
13static const char rcsid[] = "@(#)$Id: ip_fil.c,v 2.121 2003/06/28 17:01:55 darrenr Exp $"; | 13static const char sccsid[] = "@(#)ip_fil.c 2.41 6/5/96 (C) 1993-2000 Darren Reed"; 14static const char rcsid[] = "@(#)$Id: ip_fil.c,v 2.133.2.9 2005/01/08 14:22:18 darrenr Exp $"; |
14#endif 15 16#ifndef SOLARIS 17#define SOLARIS (defined(sun) && (defined(__svr4__) || defined(__SVR4))) 18#endif 19 | 15#endif 16 17#ifndef SOLARIS 18#define SOLARIS (defined(sun) && (defined(__svr4__) || defined(__SVR4))) 19#endif 20 |
20#if defined(KERNEL) || defined(_KERNEL) 21# undef KERNEL 22# undef _KERNEL 23# define KERNEL 1 24# define _KERNEL 1 25#endif | |
26#include <sys/param.h> 27#if defined(__FreeBSD__) && !defined(__FreeBSD_version) 28# if defined(IPFILTER_LKM) 29# ifndef __FreeBSD_cc_version 30# include <osreldate.h> 31# else 32# if __FreeBSD_cc_version < 430000 33# include <osreldate.h> 34# endif 35# endif 36# endif 37#endif 38#include <sys/errno.h> | 21#include <sys/param.h> 22#if defined(__FreeBSD__) && !defined(__FreeBSD_version) 23# if defined(IPFILTER_LKM) 24# ifndef __FreeBSD_cc_version 25# include <osreldate.h> 26# else 27# if __FreeBSD_cc_version < 430000 28# include <osreldate.h> 29# endif 30# endif 31# endif 32#endif 33#include <sys/errno.h> |
34#if defined(__hpux) && (HPUXREV >= 1111) && !defined(_KERNEL) 35# include <sys/kern_svcs.h> 36#endif |
|
39#include <sys/types.h> | 37#include <sys/types.h> |
40 41#ifdef _KERNEL 42# include <sys/systm.h> 43# include <sys/fcntl.h> 44#else 45# define _KERNEL 46# ifdef __OpenBSD__ | 38#define _KERNEL 39#define KERNEL 40#ifdef __OpenBSD__ |
47struct file; | 41struct file; |
48# endif 49 50# include <sys/uio.h> 51# undef _KERNEL | |
52#endif | 42#endif |
53 | 43#include <sys/uio.h> 44#undef _KERNEL 45#undef KERNEL |
54#include <sys/file.h> 55#include <sys/ioctl.h> | 46#include <sys/file.h> 47#include <sys/ioctl.h> |
56 57#include <stdio.h> 58#include <string.h> 59#include <stdlib.h> 60#include <ctype.h> 61#include <fcntl.h> 62 | |
63#ifdef __sgi 64# include <sys/ptimers.h> 65#endif 66#include <sys/time.h> 67#if !SOLARIS 68# if (NetBSD > 199609) || (OpenBSD > 199603) || (__FreeBSD_version >= 300000) 69# include <sys/dirent.h> 70# else 71# include <sys/dir.h> 72# endif 73#else 74# include <sys/filio.h> 75#endif | 48#ifdef __sgi 49# include <sys/ptimers.h> 50#endif 51#include <sys/time.h> 52#if !SOLARIS 53# if (NetBSD > 199609) || (OpenBSD > 199603) || (__FreeBSD_version >= 300000) 54# include <sys/dirent.h> 55# else 56# include <sys/dir.h> 57# endif 58#else 59# include <sys/filio.h> 60#endif |
76#include <sys/protosw.h> | 61#ifndef linux 62# include <sys/protosw.h> 63#endif |
77#include <sys/socket.h> 78 79#include <stdio.h> 80#include <string.h> 81#include <stdlib.h> 82#include <ctype.h> 83#include <fcntl.h> | 64#include <sys/socket.h> 65 66#include <stdio.h> 67#include <string.h> 68#include <stdlib.h> 69#include <ctype.h> 70#include <fcntl.h> |
71#include <arpa/inet.h> |
|
84 85#ifdef __hpux 86# define _NET_ROUTE_INCLUDED 87#endif 88#include <net/if.h> 89#ifdef sun 90# include <net/af.h> 91#endif 92#if __FreeBSD_version >= 300000 93# include <net/if_var.h> 94#endif 95#ifdef __sgi 96#include <sys/debug.h> 97# ifdef IFF_DRVRLOCK /* IRIX6 */ 98#include <sys/hashing.h> 99# endif 100#endif | 72 73#ifdef __hpux 74# define _NET_ROUTE_INCLUDED 75#endif 76#include <net/if.h> 77#ifdef sun 78# include <net/af.h> 79#endif 80#if __FreeBSD_version >= 300000 81# include <net/if_var.h> 82#endif 83#ifdef __sgi 84#include <sys/debug.h> 85# ifdef IFF_DRVRLOCK /* IRIX6 */ 86#include <sys/hashing.h> 87# endif 88#endif |
89#if defined(__FreeBSD__) 90# include "radix_ipf.h" 91#endif |
|
101#include <net/route.h> 102#include <netinet/in.h> 103#if !(defined(__sgi) && !defined(IFF_DRVRLOCK)) /* IRIX < 6 */ && \ | 92#include <net/route.h> 93#include <netinet/in.h> 94#if !(defined(__sgi) && !defined(IFF_DRVRLOCK)) /* IRIX < 6 */ && \ |
104 !defined(__hpux) | 95 !defined(__hpux) && !defined(linux) |
105# include <netinet/in_var.h> 106#endif 107#include <netinet/in_systm.h> 108#include <netinet/ip.h> | 96# include <netinet/in_var.h> 97#endif 98#include <netinet/in_systm.h> 99#include <netinet/ip.h> |
109#include <netinet/ip_var.h> | 100#if !defined(linux) 101# include <netinet/ip_var.h> 102#endif |
110#include <netinet/tcp.h> 111#if defined(__osf__) 112# include <netinet/tcp_timer.h> 113#endif | 103#include <netinet/tcp.h> 104#if defined(__osf__) 105# include <netinet/tcp_timer.h> 106#endif |
107#if defined(__osf__) || defined(__hpux) || defined(__sgi) 108# include "radix_ipf_local.h" 109# define _RADIX_H_ 110#endif |
|
114#include <netinet/udp.h> 115#include <netinet/tcpip.h> 116#include <netinet/ip_icmp.h> 117#include <unistd.h> 118#include <syslog.h> 119#ifdef __hpux 120# undef _NET_ROUTE_INCLUDED 121#endif | 111#include <netinet/udp.h> 112#include <netinet/tcpip.h> 113#include <netinet/ip_icmp.h> 114#include <unistd.h> 115#include <syslog.h> 116#ifdef __hpux 117# undef _NET_ROUTE_INCLUDED 118#endif |
122#if SOLARIS2 >= 10 123#include "ip_compat.h" 124#include "ip_fil.h" 125#include "ip_nat.h" 126#include "ip_frag.h" 127#include "ip_state.h" 128#include "ip_proxy.h" 129#include "ip_auth.h" 130#else | |
131#include "netinet/ip_compat.h" 132#include "netinet/ip_fil.h" 133#include "netinet/ip_nat.h" 134#include "netinet/ip_frag.h" 135#include "netinet/ip_state.h" 136#include "netinet/ip_proxy.h" 137#include "netinet/ip_auth.h" | 119#include "netinet/ip_compat.h" 120#include "netinet/ip_fil.h" 121#include "netinet/ip_nat.h" 122#include "netinet/ip_frag.h" 123#include "netinet/ip_state.h" 124#include "netinet/ip_proxy.h" 125#include "netinet/ip_auth.h" |
138#endif | |
139#ifdef IPFILTER_SYNC 140#include "netinet/ip_sync.h" 141#endif 142#ifdef IPFILTER_SCAN 143#include "netinet/ip_scan.h" 144#endif | 126#ifdef IPFILTER_SYNC 127#include "netinet/ip_sync.h" 128#endif 129#ifdef IPFILTER_SCAN 130#include "netinet/ip_scan.h" 131#endif |
145#if SOLARIS2 >= 10 146#include "ip_pool.h" 147#else | |
148#include "netinet/ip_pool.h" | 132#include "netinet/ip_pool.h" |
149#endif | |
150#ifdef IPFILTER_COMPILED 151# include "netinet/ip_rules.h" 152#endif 153#if defined(__FreeBSD_version) && (__FreeBSD_version >= 300000) 154# include <sys/malloc.h> 155#endif 156#ifdef __hpux 157struct rtentry; 158#endif | 133#ifdef IPFILTER_COMPILED 134# include "netinet/ip_rules.h" 135#endif 136#if defined(__FreeBSD_version) && (__FreeBSD_version >= 300000) 137# include <sys/malloc.h> 138#endif 139#ifdef __hpux 140struct rtentry; 141#endif |
142#include "md5.h" |
|
159 | 143 |
160#include <sys/md5.h> | |
161 162#if !defined(__osf__) 163extern struct protosw inetsw[]; 164#endif 165 166#include "ipt.h" 167static struct ifnet **ifneta = NULL; 168static int nifs = 0; 169 170static int frzerostats __P((caddr_t)); | 144 145#if !defined(__osf__) 146extern struct protosw inetsw[]; 147#endif 148 149#include "ipt.h" 150static struct ifnet **ifneta = NULL; 151static int nifs = 0; 152 153static int frzerostats __P((caddr_t)); |
154static void fr_setifpaddr __P((struct ifnet *, char *)); |
|
171void init_ifp __P((void)); | 155void init_ifp __P((void)); |
172#if defined(__sgi) && (IRIX < 605) | 156#if defined(__sgi) && (IRIX < 60500) |
173static int no_output __P((struct ifnet *, struct mbuf *, 174 struct sockaddr *)); 175static int write_output __P((struct ifnet *, struct mbuf *, 176 struct sockaddr *)); 177#else 178# if TRU64 >= 1885 179static int no_output __P((struct ifnet *, struct mbuf *, 180 struct sockaddr *, struct rtentry *, char *)); --- 34 unchanged lines hidden (view full) --- 215 return EFAULT; 216 217 bzero((char *)frstats, sizeof(*frstats) * 2); 218 219 return 0; 220} 221 222 | 157static int no_output __P((struct ifnet *, struct mbuf *, 158 struct sockaddr *)); 159static int write_output __P((struct ifnet *, struct mbuf *, 160 struct sockaddr *)); 161#else 162# if TRU64 >= 1885 163static int no_output __P((struct ifnet *, struct mbuf *, 164 struct sockaddr *, struct rtentry *, char *)); --- 34 unchanged lines hidden (view full) --- 199 return EFAULT; 200 201 bzero((char *)frstats, sizeof(*frstats) * 2); 202 203 return 0; 204} 205 206 |
223 | |
224/* 225 * Filter ioctl interface. 226 */ 227int iplioctl(dev, cmd, data, mode) 228int dev; | 207/* 208 * Filter ioctl interface. 209 */ 210int iplioctl(dev, cmd, data, mode) 211int dev; |
229#if defined(__NetBSD__) || defined(__OpenBSD__) || \ 230 (_BSDI_VERSION >= 199701) || (__FreeBSD_version >= 300000) 231u_long cmd; 232#else 233int cmd; 234#endif | 212ioctlcmd_t cmd; |
235caddr_t data; 236int mode; 237{ 238 int error = 0, unit = 0, tmp; 239 friostat_t fio; 240 241 unit = dev; 242 --- 12 unchanged lines hidden (view full) --- 255 error = fr_state_ioctl(data, cmd, mode); 256 else 257 error = EIO; 258 SPL_X(s); 259 return error; 260 } 261 if (unit == IPL_LOGAUTH) { 262 if (fr_running > 0) { | 213caddr_t data; 214int mode; 215{ 216 int error = 0, unit = 0, tmp; 217 friostat_t fio; 218 219 unit = dev; 220 --- 12 unchanged lines hidden (view full) --- 233 error = fr_state_ioctl(data, cmd, mode); 234 else 235 error = EIO; 236 SPL_X(s); 237 return error; 238 } 239 if (unit == IPL_LOGAUTH) { 240 if (fr_running > 0) { |
263 if ((cmd == SIOCADAFR) || (cmd == SIOCRMAFR)) { | 241 if ((cmd == (ioctlcmd_t)SIOCADAFR) || 242 (cmd == (ioctlcmd_t)SIOCRMAFR)) { |
264 if (!(mode & FWRITE)) { 265 error = EPERM; 266 } else { 267 error = frrequest(unit, cmd, data, 268 fr_active, 1); 269 } 270 } else { 271 error = fr_auth_ioctl(data, mode, cmd); --- 48 unchanged lines hidden (view full) --- 320 if (error) 321 break; 322 if (tmp) 323 error = iplattach(); 324 else 325 error = ipldetach(); 326 } 327 break; | 243 if (!(mode & FWRITE)) { 244 error = EPERM; 245 } else { 246 error = frrequest(unit, cmd, data, 247 fr_active, 1); 248 } 249 } else { 250 error = fr_auth_ioctl(data, mode, cmd); --- 48 unchanged lines hidden (view full) --- 299 if (error) 300 break; 301 if (tmp) 302 error = iplattach(); 303 else 304 error = ipldetach(); 305 } 306 break; |
307 case SIOCIPFSET : 308 if (!(mode & FWRITE)) { 309 error = EPERM; 310 break; 311 } 312 case SIOCIPFGETNEXT : 313 case SIOCIPFGET : 314 error = fr_ipftune(cmd, (void *)data); 315 break; |
|
328 case SIOCSETFF : 329 if (!(mode & FWRITE)) 330 error = EPERM; 331 else 332 error = COPYIN(data, &fr_flags, sizeof(fr_flags)); 333 break; 334 case SIOCGETFF : 335 error = COPYOUT(&fr_flags, data, sizeof(fr_flags)); --- 81 unchanged lines hidden (view full) --- 417#endif /* IPFILTER_LOG */ 418 case SIOCGFRST : 419 error = fr_outobj(data, fr_fragstats(), IPFOBJ_FRAGSTAT); 420 break; 421 case SIOCFRSYN : 422 if (!(mode & FWRITE)) 423 error = EPERM; 424 else { | 316 case SIOCSETFF : 317 if (!(mode & FWRITE)) 318 error = EPERM; 319 else 320 error = COPYIN(data, &fr_flags, sizeof(fr_flags)); 321 break; 322 case SIOCGETFF : 323 error = COPYOUT(&fr_flags, data, sizeof(fr_flags)); --- 81 unchanged lines hidden (view full) --- 405#endif /* IPFILTER_LOG */ 406 case SIOCGFRST : 407 error = fr_outobj(data, fr_fragstats(), IPFOBJ_FRAGSTAT); 408 break; 409 case SIOCFRSYN : 410 if (!(mode & FWRITE)) 411 error = EPERM; 412 else { |
425 frsync(); | 413 frsync(NULL); |
426 } 427 break; 428 default : 429 error = EINVAL; 430 break; 431 } 432 SPL_X(s); 433 return error; --- 32 unchanged lines hidden (view full) --- 466 if (f->fr_ifa == ifp) 467 f->fr_ifa = (void *)-1; 468#endif 469 RWLOCK_EXIT(&ipf_mutex); 470 fr_natsync(ifp); 471} 472 473 | 414 } 415 break; 416 default : 417 error = EINVAL; 418 break; 419 } 420 SPL_X(s); 421 return error; --- 32 unchanged lines hidden (view full) --- 454 if (f->fr_ifa == ifp) 455 f->fr_ifa = (void *)-1; 456#endif 457 RWLOCK_EXIT(&ipf_mutex); 458 fr_natsync(ifp); 459} 460 461 |
474void fr_resolvdest(fdp, v) | 462void fr_resolvedest(fdp, v) |
475frdest_t *fdp; 476int v; 477{ 478 fdp->fd_ifp = NULL; 479 480 if (*fdp->fd_ifname) { 481 fdp->fd_ifp = GETIFP(fdp->fd_ifname, v); 482 if (!fdp->fd_ifp) 483 fdp->fd_ifp = (struct ifnet *)-1; 484 } 485} 486 487 | 463frdest_t *fdp; 464int v; 465{ 466 fdp->fd_ifp = NULL; 467 468 if (*fdp->fd_ifname) { 469 fdp->fd_ifp = GETIFP(fdp->fd_ifname, v); 470 if (!fdp->fd_ifp) 471 fdp->fd_ifp = (struct ifnet *)-1; 472 } 473} 474 475 |
488#if defined(__sgi) && (IRIX < 605) | 476#if defined(__sgi) && (IRIX < 60500) |
489static int no_output(ifp, m, s) 490#else 491# if TRU64 >= 1885 492static int no_output (ifp, m, s, rt, cp) 493char *cp; 494# else 495static int no_output(ifp, m, s, rt) 496# endif 497struct rtentry *rt; 498#endif 499struct ifnet *ifp; 500struct mbuf *m; 501struct sockaddr *s; 502{ 503 return 0; 504} 505 506 | 477static int no_output(ifp, m, s) 478#else 479# if TRU64 >= 1885 480static int no_output (ifp, m, s, rt, cp) 481char *cp; 482# else 483static int no_output(ifp, m, s, rt) 484# endif 485struct rtentry *rt; 486#endif 487struct ifnet *ifp; 488struct mbuf *m; 489struct sockaddr *s; 490{ 491 return 0; 492} 493 494 |
507#if defined(__sgi) && (IRIX < 605) | 495#if defined(__sgi) && (IRIX < 60500) |
508static int write_output(ifp, m, s) 509#else 510# if TRU64 >= 1885 511static int write_output (ifp, m, s, rt, cp) 512char *cp; 513# else 514static int write_output(ifp, m, s, rt) 515# endif --- 7 unchanged lines hidden (view full) --- 523 mb_t *mb; 524 ip_t *ip; 525 int fd; 526 527 mb = (mb_t *)m; 528 ip = MTOD(mb, ip_t *); 529 530#if (defined(NetBSD) && (NetBSD <= 1991011) && (NetBSD >= 199606)) || \ | 496static int write_output(ifp, m, s) 497#else 498# if TRU64 >= 1885 499static int write_output (ifp, m, s, rt, cp) 500char *cp; 501# else 502static int write_output(ifp, m, s, rt) 503# endif --- 7 unchanged lines hidden (view full) --- 511 mb_t *mb; 512 ip_t *ip; 513 int fd; 514 515 mb = (mb_t *)m; 516 ip = MTOD(mb, ip_t *); 517 518#if (defined(NetBSD) && (NetBSD <= 1991011) && (NetBSD >= 199606)) || \ |
531 (defined(OpenBSD) && (OpenBSD >= 199603)) | 519 (defined(OpenBSD) && (OpenBSD >= 199603)) || defined(linux) || \ 520 (defined(__FreeBSD__) && (__FreeBSD_version >= 501113)) |
532 sprintf(fname, "/tmp/%s", ifp->if_xname); 533#else 534 sprintf(fname, "/tmp/%s%d", ifp->if_name, ifp->if_unit); 535#endif 536 fd = open(fname, O_WRONLY|O_APPEND); 537 if (fd == -1) { 538 perror("open"); 539 return -1; 540 } 541 write(fd, (char *)ip, ntohs(ip->ip_len)); 542 close(fd); 543 return 0; 544} 545 546 | 521 sprintf(fname, "/tmp/%s", ifp->if_xname); 522#else 523 sprintf(fname, "/tmp/%s%d", ifp->if_name, ifp->if_unit); 524#endif 525 fd = open(fname, O_WRONLY|O_APPEND); 526 if (fd == -1) { 527 perror("open"); 528 return -1; 529 } 530 write(fd, (char *)ip, ntohs(ip->ip_len)); 531 close(fd); 532 return 0; 533} 534 535 |
536static void fr_setifpaddr(ifp, addr) 537struct ifnet *ifp; 538char *addr; 539{ 540#ifdef __sgi 541 struct in_ifaddr *ifa; 542#else 543 struct ifaddr *ifa; 544#endif 545 546#if defined(__NetBSD__) || defined(__OpenBSD__) || defined(__FreeBSD__) 547 if (ifp->if_addrlist.tqh_first != NULL) 548#else 549# ifdef __sgi 550 if (ifp->in_ifaddr != NULL) 551# else 552 if (ifp->if_addrlist != NULL) 553# endif 554#endif 555 return; 556 557 ifa = (struct ifaddr *)malloc(sizeof(*ifa)); 558#if defined(__NetBSD__) || defined(__OpenBSD__) || defined(__FreeBSD__) 559 ifp->if_addrlist.tqh_first = ifa; 560#else 561# ifdef __sgi 562 ifp->in_ifaddr = ifa; 563# else 564 ifp->if_addrlist = ifa; 565# endif 566#endif 567 568 if (ifa != NULL) { 569 struct sockaddr_in *sin; 570 571#ifdef __sgi 572 sin = (struct sockaddr_in *)&ifa->ia_addr; 573#else 574 sin = (struct sockaddr_in *)&ifa->ifa_addr; 575#endif 576 sin->sin_addr.s_addr = inet_addr(addr); 577 if (sin->sin_addr.s_addr == 0) 578 abort(); 579 } 580} 581 |
|
547struct ifnet *get_unit(name, v) 548char *name; 549int v; 550{ | 582struct ifnet *get_unit(name, v) 583char *name; 584int v; 585{ |
551 struct ifnet *ifp, **ifa, **old_ifneta; | 586 struct ifnet *ifp, **ifpp, **old_ifneta; 587 char *addr; |
552#if (defined(NetBSD) && (NetBSD <= 1991011) && (NetBSD >= 199606)) || \ | 588#if (defined(NetBSD) && (NetBSD <= 1991011) && (NetBSD >= 199606)) || \ |
553 (defined(OpenBSD) && (OpenBSD >= 199603)) | 589 (defined(OpenBSD) && (OpenBSD >= 199603)) || defined(linux) || \ 590 (defined(__FreeBSD__) && (__FreeBSD_version >= 501113)) |
554 555 if (name == NULL) 556 name = "anon0"; 557 | 591 592 if (name == NULL) 593 name = "anon0"; 594 |
558 for (ifa = ifneta; ifa && (ifp = *ifa); ifa++) { 559 if (!strcmp(name, ifp->if_xname)) | 595 addr = strchr(name, '='); 596 if (addr != NULL) 597 *addr++ = '\0'; 598 599 for (ifpp = ifneta; ifpp && (ifp = *ifpp); ifpp++) { 600 if (!strcmp(name, ifp->if_xname)) { 601 if (addr != NULL) 602 fr_setifpaddr(ifp, addr); |
560 return ifp; | 603 return ifp; |
604 } |
|
561 } 562#else 563 char *s, ifname[LIFNAMSIZ+1]; 564 565 if (name == NULL) 566 name = "anon0"; 567 | 605 } 606#else 607 char *s, ifname[LIFNAMSIZ+1]; 608 609 if (name == NULL) 610 name = "anon0"; 611 |
568 for (ifa = ifneta; ifa && (ifp = *ifa); ifa++) { | 612 addr = strchr(name, '='); 613 if (addr != NULL) 614 *addr++ = '\0'; 615 616 for (ifpp = ifneta; ifpp && (ifp = *ifpp); ifpp++) { |
569 COPYIFNAME(ifp, ifname); | 617 COPYIFNAME(ifp, ifname); |
570 if (!strcmp(name, ifname)) | 618 if (!strcmp(name, ifname)) { 619 if (addr != NULL) 620 fr_setifpaddr(ifp, addr); |
571 return ifp; | 621 return ifp; |
622 } |
|
572 } 573#endif 574 575 if (!ifneta) { 576 ifneta = (struct ifnet **)malloc(sizeof(ifp) * 2); 577 if (!ifneta) 578 return NULL; 579 ifneta[1] = NULL; 580 ifneta[0] = (struct ifnet *)calloc(1, sizeof(*ifp)); 581 if (!ifneta[0]) { 582 free(ifneta); 583 return NULL; 584 } 585 nifs = 1; 586 } else { 587 old_ifneta = ifneta; 588 nifs++; 589 ifneta = (struct ifnet **)realloc(ifneta, | 623 } 624#endif 625 626 if (!ifneta) { 627 ifneta = (struct ifnet **)malloc(sizeof(ifp) * 2); 628 if (!ifneta) 629 return NULL; 630 ifneta[1] = NULL; 631 ifneta[0] = (struct ifnet *)calloc(1, sizeof(*ifp)); 632 if (!ifneta[0]) { 633 free(ifneta); 634 return NULL; 635 } 636 nifs = 1; 637 } else { 638 old_ifneta = ifneta; 639 nifs++; 640 ifneta = (struct ifnet **)realloc(ifneta, |
590 (nifs + 1) * sizeof(*ifa)); | 641 (nifs + 1) * sizeof(ifp)); |
591 if (!ifneta) { 592 free(old_ifneta); 593 nifs = 0; 594 return NULL; 595 } 596 ifneta[nifs] = NULL; 597 ifneta[nifs - 1] = (struct ifnet *)malloc(sizeof(*ifp)); 598 if (!ifneta[nifs - 1]) { 599 nifs--; 600 return NULL; 601 } 602 } 603 ifp = ifneta[nifs - 1]; 604 605#if (defined(NetBSD) && (NetBSD <= 1991011) && (NetBSD >= 199606)) || \ | 642 if (!ifneta) { 643 free(old_ifneta); 644 nifs = 0; 645 return NULL; 646 } 647 ifneta[nifs] = NULL; 648 ifneta[nifs - 1] = (struct ifnet *)malloc(sizeof(*ifp)); 649 if (!ifneta[nifs - 1]) { 650 nifs--; 651 return NULL; 652 } 653 } 654 ifp = ifneta[nifs - 1]; 655 656#if (defined(NetBSD) && (NetBSD <= 1991011) && (NetBSD >= 199606)) || \ |
606 (defined(OpenBSD) && (OpenBSD >= 199603)) 607 strncpy(ifp->if_xname, name, sizeof(ifp->if_xname)); | 657 (defined(OpenBSD) && (OpenBSD >= 199603)) || defined(linux) || \ 658 (defined(__FreeBSD__) && (__FreeBSD_version >= 501113)) 659 (void) strncpy(ifp->if_xname, name, sizeof(ifp->if_xname)); |
608#else | 660#else |
609 for (s = name; *s && !isdigit(*s); s++) | 661 for (s = name; *s && !ISDIGIT(*s); s++) |
610 ; | 662 ; |
611 if (*s && isdigit(*s)) { | 663 if (*s && ISDIGIT(*s)) { |
612 ifp->if_unit = atoi(s); 613 ifp->if_name = (char *)malloc(s - name + 1); 614 if (ifp->if_name == NULL) { 615 /* 616 * XXX do it more elegantly: free up mem, 617 * return NULL 618 */ 619 perror("malloc"); 620 exit(1); 621 } | 664 ifp->if_unit = atoi(s); 665 ifp->if_name = (char *)malloc(s - name + 1); 666 if (ifp->if_name == NULL) { 667 /* 668 * XXX do it more elegantly: free up mem, 669 * return NULL 670 */ 671 perror("malloc"); 672 exit(1); 673 } |
622 strncpy(ifp->if_name, name, s - name); | 674 (void) strncpy(ifp->if_name, name, s - name); |
623 ifp->if_name[s - name] = '\0'; 624 } else { 625 ifp->if_name = strdup(name); 626 ifp->if_unit = -1; 627 } 628#endif 629 ifp->if_output = no_output; | 675 ifp->if_name[s - name] = '\0'; 676 } else { 677 ifp->if_name = strdup(name); 678 ifp->if_unit = -1; 679 } 680#endif 681 ifp->if_output = no_output; |
682 683 if (addr != NULL) { 684 fr_setifpaddr(ifp, addr); 685 } 686 |
|
630 return ifp; 631} 632 633 634char *get_ifname(ifp) 635struct ifnet *ifp; 636{ 637 static char ifname[LIFNAMSIZ]; 638 | 687 return ifp; 688} 689 690 691char *get_ifname(ifp) 692struct ifnet *ifp; 693{ 694 static char ifname[LIFNAMSIZ]; 695 |
639#if defined(__OpenBSD__) || defined(__NetBSD__) | 696#if defined(__OpenBSD__) || defined(__NetBSD__) || defined(linux) || \ 697 (defined(__FreeBSD__) && (__FreeBSD_version >= 501113)) |
640 sprintf(ifname, "%s", ifp->if_xname); 641#else 642 sprintf(ifname, "%s%d", ifp->if_name, ifp->if_unit); 643#endif 644 return ifname; 645} 646 647 648 649void init_ifp() 650{ | 698 sprintf(ifname, "%s", ifp->if_xname); 699#else 700 sprintf(ifname, "%s%d", ifp->if_name, ifp->if_unit); 701#endif 702 return ifname; 703} 704 705 706 707void init_ifp() 708{ |
651 struct ifnet *ifp, **ifa; | 709 struct ifnet *ifp, **ifpp; |
652 char fname[32]; 653 int fd; 654 655#if (defined(NetBSD) && (NetBSD <= 1991011) && (NetBSD >= 199606)) || \ | 710 char fname[32]; 711 int fd; 712 713#if (defined(NetBSD) && (NetBSD <= 1991011) && (NetBSD >= 199606)) || \ |
656 (defined(OpenBSD) && (OpenBSD >= 199603)) 657 for (ifa = ifneta; ifa && (ifp = *ifa); ifa++) { | 714 (defined(OpenBSD) && (OpenBSD >= 199603)) || defined(linux) || \ 715 (defined(__FreeBSD__) && (__FreeBSD_version >= 501113)) 716 for (ifpp = ifneta; ifpp && (ifp = *ifpp); ifpp++) { |
658 ifp->if_output = write_output; 659 sprintf(fname, "/tmp/%s", ifp->if_xname); 660 fd = open(fname, O_WRONLY|O_CREAT|O_EXCL|O_TRUNC, 0600); 661 if (fd == -1) 662 perror("open"); 663 else 664 close(fd); 665 } 666#else 667 | 717 ifp->if_output = write_output; 718 sprintf(fname, "/tmp/%s", ifp->if_xname); 719 fd = open(fname, O_WRONLY|O_CREAT|O_EXCL|O_TRUNC, 0600); 720 if (fd == -1) 721 perror("open"); 722 else 723 close(fd); 724 } 725#else 726 |
668 for (ifa = ifneta; ifa && (ifp = *ifa); ifa++) { | 727 for (ifpp = ifneta; ifpp && (ifp = *ifpp); ifpp++) { |
669 ifp->if_output = write_output; 670 sprintf(fname, "/tmp/%s%d", ifp->if_name, ifp->if_unit); 671 fd = open(fname, O_WRONLY|O_CREAT|O_EXCL|O_TRUNC, 0600); 672 if (fd == -1) 673 perror("open"); 674 else 675 close(fd); 676 } --- 10 unchanged lines hidden (view full) --- 687 ip_t *ip = fin->fin_ip; 688 689 if (!ifp) 690 return 0; /* no routing table out here */ 691 692 ip->ip_len = htons((u_short)ip->ip_len); 693 ip->ip_off = htons((u_short)(ip->ip_off | IP_MF)); 694 ip->ip_sum = 0; | 728 ifp->if_output = write_output; 729 sprintf(fname, "/tmp/%s%d", ifp->if_name, ifp->if_unit); 730 fd = open(fname, O_WRONLY|O_CREAT|O_EXCL|O_TRUNC, 0600); 731 if (fd == -1) 732 perror("open"); 733 else 734 close(fd); 735 } --- 10 unchanged lines hidden (view full) --- 746 ip_t *ip = fin->fin_ip; 747 748 if (!ifp) 749 return 0; /* no routing table out here */ 750 751 ip->ip_len = htons((u_short)ip->ip_len); 752 ip->ip_off = htons((u_short)(ip->ip_off | IP_MF)); 753 ip->ip_sum = 0; |
695#if defined(__sgi) && (IRIX < 605) | 754#if defined(__sgi) && (IRIX < 60500) |
696 (*ifp->if_output)(ifp, (void *)ip, NULL); 697# if TRU64 >= 1885 698 (*ifp->if_output)(ifp, (void *)m, NULL, 0, 0); 699# else 700 (*ifp->if_output)(ifp, (void *)m, NULL, 0); 701# endif 702#endif 703 return 0; --- 8 unchanged lines hidden (view full) --- 712} 713 714 715int fr_send_icmp_err(type, fin, dst) 716int type; 717fr_info_t *fin; 718int dst; 719{ | 755 (*ifp->if_output)(ifp, (void *)ip, NULL); 756# if TRU64 >= 1885 757 (*ifp->if_output)(ifp, (void *)m, NULL, 0, 0); 758# else 759 (*ifp->if_output)(ifp, (void *)m, NULL, 0); 760# endif 761#endif 762 return 0; --- 8 unchanged lines hidden (view full) --- 771} 772 773 774int fr_send_icmp_err(type, fin, dst) 775int type; 776fr_info_t *fin; 777int dst; 778{ |
720 verbose("- TCP RST sent\n"); | 779 verbose("- ICMP unreachable sent\n"); |
721 return 0; 722} 723 724 | 780 return 0; 781} 782 783 |
725void frsync() | 784void frsync(ifp) 785void *ifp; |
726{ 727 return; 728} 729 730 731void m_freem(m) 732mb_t *m; 733{ --- 121 unchanged lines hidden (view full) --- 855#ifdef USE_INET6 856INLINE void fr_checkv6sum(fin) 857fr_info_t *fin; 858{ 859 if (fr_checkl4sum(fin) == -1) 860 fin->fin_flx |= FI_BAD; 861} 862#endif | 786{ 787 return; 788} 789 790 791void m_freem(m) 792mb_t *m; 793{ --- 121 unchanged lines hidden (view full) --- 915#ifdef USE_INET6 916INLINE void fr_checkv6sum(fin) 917fr_info_t *fin; 918{ 919 if (fr_checkl4sum(fin) == -1) 920 fin->fin_flx |= FI_BAD; 921} 922#endif |
923 924 925/* 926 * See above for description, except that all addressing is in user space. 927 */ 928int copyoutptr(src, dst, size) 929void *src, *dst; 930size_t size; 931{ 932 caddr_t ca; 933 934 bcopy(dst, (char *)&ca, sizeof(ca)); 935 bcopy(src, ca, size); 936 return 0; 937} 938 939 940/* 941 * See above for description, except that all addressing is in user space. 942 */ 943int copyinptr(src, dst, size) 944void *src, *dst; 945size_t size; 946{ 947 caddr_t ca; 948 949 bcopy(src, (char *)&ca, sizeof(ca)); 950 bcopy(ca, dst, size); 951 return 0; 952} 953 954 955/* 956 * return the first IP Address associated with an interface 957 */ 958int fr_ifpaddr(v, atype, ifptr, inp, inpmask) 959int v, atype; 960void *ifptr; 961struct in_addr *inp, *inpmask; 962{ 963 struct ifnet *ifp = ifptr; 964#ifdef __sgi 965 struct in_ifaddr *ifa; 966#else 967 struct ifaddr *ifa; 968#endif 969 970#if defined(__NetBSD__) || defined(__OpenBSD__) || defined(__FreeBSD__) 971 ifa = ifp->if_addrlist.tqh_first; 972#else 973# ifdef __sgi 974 ifa = (struct in_ifaddr *)ifp->in_ifaddr; 975# else 976 ifa = ifp->if_addrlist; 977# endif 978#endif 979 if (ifa != NULL) { 980 struct sockaddr_in *sin, mask; 981 982 mask.sin_addr.s_addr = 0xffffffff; 983 984#ifdef __sgi 985 sin = (struct sockaddr_in *)&ifa->ia_addr; 986#else 987 sin = (struct sockaddr_in *)&ifa->ifa_addr; 988#endif 989 990 return fr_ifpfillv4addr(atype, sin, &mask, inp, inpmask); 991 } 992 return 0; 993} |
|