diff options
author | Federico G. Schwindt <fgsch@cvs.openbsd.org> | 2001-01-17 06:01:28 +0000 |
---|---|---|
committer | Federico G. Schwindt <fgsch@cvs.openbsd.org> | 2001-01-17 06:01:28 +0000 |
commit | c67f44fa2629f6f91d78058ce671d7113007bb22 (patch) | |
tree | 28dd7e9da83f6bc5a58e7a33cd87cd6c50682c96 /usr.sbin | |
parent | bf383cd8b01ace1511e5268fae78582cc3c22406 (diff) |
2nd part of the ipf code; need more testing.
Diffstat (limited to 'usr.sbin')
30 files changed, 478 insertions, 829 deletions
diff --git a/usr.sbin/ipftest/Makefile b/usr.sbin/ipftest/Makefile index 786be621aca..a7c087a9a78 100644 --- a/usr.sbin/ipftest/Makefile +++ b/usr.sbin/ipftest/Makefile @@ -1,10 +1,10 @@ -# $OpenBSD: Makefile,v 1.8 1999/12/16 07:38:45 kjell Exp $ +# $OpenBSD: Makefile,v 1.9 2001/01/17 06:01:21 fgsch Exp $ PROG= ipftest MAN= ipftest.1 SRCS= ipt.c fil.c ipft_hx.c ipft_sn.c ipft_ef.c ipft_td.c ipft_pc.c \ ipft_tx.c misc.c parse.c opt.c ip_frag.c ip_nat.c ip_state.c \ - ip_auth.c ip_fil.c ip_proxy.c facpri.c natparse.c ifaddr.c + ip_auth.c ip_fil.c ip_proxy.c facpri.c natparse.c common.c ifaddr.c .PATH: ${.CURDIR}/../../sbin/ipf ${.CURDIR}/../../sbin/ipfstat \ ${.CURDIR}/../../sys/netinet ${.CURDIR}/../../sbin/ipnat @@ -12,5 +12,4 @@ SRCS= ipt.c fil.c ipft_hx.c ipft_sn.c ipft_ef.c ipft_td.c ipft_pc.c \ CFLAGS+=-I${.CURDIR}/../../sbin/ipf \ -I${.CURDIR} - .include <bsd.prog.mk> diff --git a/usr.sbin/ipftest/ipft_ef.c b/usr.sbin/ipftest/ipft_ef.c index 15f6ae1c44c..4ac6cf70525 100644 --- a/usr.sbin/ipftest/ipft_ef.c +++ b/usr.sbin/ipftest/ipft_ef.c @@ -1,7 +1,7 @@ -/* $OpenBSD: ipft_ef.c,v 1.14 2000/03/13 23:40:20 kjell Exp $ */ +/* $OpenBSD: ipft_ef.c,v 1.15 2001/01/17 06:01:22 fgsch Exp $ */ /* - * Copyright (C) 1993-1998 by Darren Reed. + * Copyright (C) 1993-2000 by Darren Reed. * * Redistribution and use in source and binary forms are permitted * provided that this notice is preserved and due credit is given @@ -46,14 +46,14 @@ etherfind -n -t #include <netinet/ip_icmp.h> #include <net/if.h> #include <netdb.h> -#include <netinet/ip_fil_compat.h> +#include <netinet/ip_compat.h> #include <netinet/tcpip.h> #include "ipf.h" #include "ipt.h" #if !defined(lint) static const char sccsid[] = "@(#)ipft_ef.c 1.6 2/4/96 (C)1995 Darren Reed"; -static const char rcsid[] = "@(#)$IPFilter: ipft_ef.c,v 2.1 1999/08/04 17:30:02 darrenr Exp $"; +static const char rcsid[] = "@(#)$IPFilter: ipft_ef.c,v 2.2 2000/03/13 22:10:24 darrenr Exp $"; #endif static int etherf_open __P((char *)); diff --git a/usr.sbin/ipftest/ipft_hx.c b/usr.sbin/ipftest/ipft_hx.c index 46d00dafd3d..0a0299a7a4d 100644 --- a/usr.sbin/ipftest/ipft_hx.c +++ b/usr.sbin/ipftest/ipft_hx.c @@ -1,7 +1,7 @@ -/* $OpenBSD: ipft_hx.c,v 1.12 2000/03/13 23:40:20 kjell Exp $ */ +/* $OpenBSD: ipft_hx.c,v 1.13 2001/01/17 06:01:22 fgsch Exp $ */ /* - * Copyright (C) 1995-1998 by Darren Reed. + * Copyright (C) 1995-2000 by Darren Reed. * * Redistribution and use in source and binary forms are permitted * provided that this notice is preserved and due credit is given @@ -37,14 +37,14 @@ #include <netdb.h> #include <arpa/nameser.h> #include <resolv.h> -#include <netinet/ip_fil_compat.h> +#include <netinet/ip_compat.h> #include <netinet/tcpip.h> #include "ipf.h" #include "ipt.h" #if !defined(lint) static const char sccsid[] = "@(#)ipft_hx.c 1.1 3/9/96 (C) 1996 Darren Reed"; -static const char rcsid[] = "@(#)$IPFilter: ipft_hx.c,v 2.1 1999/08/04 17:30:03 darrenr Exp $"; +static const char rcsid[] = "@(#)$IPFilter: ipft_hx.c,v 2.2 2000/03/13 22:10:24 darrenr Exp $"; #endif extern int opts; diff --git a/usr.sbin/ipftest/ipft_pc.c b/usr.sbin/ipftest/ipft_pc.c index 425a89efaa7..e80d13fe0b8 100644 --- a/usr.sbin/ipftest/ipft_pc.c +++ b/usr.sbin/ipftest/ipft_pc.c @@ -1,7 +1,7 @@ -/* $OpenBSD: ipft_pc.c,v 1.16 2000/03/13 23:40:20 kjell Exp $ */ +/* $OpenBSD: ipft_pc.c,v 1.17 2001/01/17 06:01:22 fgsch Exp $ */ /* - * Copyright (C) 1993-1998 by Darren Reed. + * Copyright (C) 1993-2000 by Darren Reed. * * Redistribution and use in source and binary forms are permitted * provided that this notice is preserved and due credit is given @@ -28,14 +28,14 @@ #include <netinet/ip.h> #include <netinet/tcp.h> #include <net/if.h> -#include <netinet/ip_fil_compat.h> +#include <netinet/ip_compat.h> #include <netinet/tcpip.h> #include "ipf.h" #include "pcap.h" #include "ipt.h" #if !defined(lint) -static const char rcsid[] = "@(#)$IPFilter: ipft_pc.c,v 2.1 1999/08/04 17:30:03 darrenr Exp $"; +static const char rcsid[] = "@(#)$IPFilter: ipft_pc.c,v 2.2 2000/03/13 22:10:24 darrenr Exp $"; #endif struct llc { @@ -48,9 +48,9 @@ struct llc { * While many of these maybe the same, some do have different header formats * which make this useful. */ -#define DLT_MAX 14 +#define DLT_MAX 10 -static struct llc llcs[DLT_MAX] = { +static struct llc llcs[DLT_MAX+1] = { { 0, 0, 0 }, /* DLT_NULL */ { 14, 12, 2 }, /* DLT_E10MB */ { 0, 0, 0 }, /* DLT_EN3MB */ @@ -61,10 +61,7 @@ static struct llc llcs[DLT_MAX] = { { 0, 0, 0 }, /* DLT_ARCNET */ { 0, 0, 0 }, /* DLT_SLIP */ { 0, 0, 0 }, /* DLT_PPP */ - { 0, 0, 0 }, /* DLT_FDDI */ - { 0, 0, 0 }, /* DLT_ATMRFC1483 */ - { 0, 0, 0 }, /* DLT_LOOP */ - { 0, 0, 0 } /* DLT_ENC */ + { 0, 0, 0 } /* DLT_FDDI */ }; static int pcap_open __P((char *)); @@ -119,7 +116,7 @@ char *fname; swap_hdr(&ph); } - if (ph.pc_v_maj != PCAP_VERSION_MAJ || ph.pc_type >= DLT_MAX) { + if (ph.pc_v_maj != PCAP_VERSION_MAJ || ph.pc_type > DLT_MAX) { (void) close(fd); return -2; } diff --git a/usr.sbin/ipftest/ipft_sn.c b/usr.sbin/ipftest/ipft_sn.c index f9dd995ec09..fa7e7201239 100644 --- a/usr.sbin/ipftest/ipft_sn.c +++ b/usr.sbin/ipftest/ipft_sn.c @@ -1,7 +1,7 @@ -/* $OpenBSD: ipft_sn.c,v 1.13 2000/03/13 23:40:20 kjell Exp $ */ +/* $OpenBSD: ipft_sn.c,v 1.14 2001/01/17 06:01:22 fgsch Exp $ */ /* - * Copyright (C) 1993-1998 by Darren Reed. + * Copyright (C) 1993-2000 by Darren Reed. * * Redistribution and use in source and binary forms are permitted * provided that this notice is preserved and due credit is given @@ -32,14 +32,14 @@ #include <netinet/ip.h> #include <netinet/tcp.h> #include <net/if.h> -#include <netinet/ip_fil_compat.h> +#include <netinet/ip_compat.h> #include <netinet/tcpip.h> #include "ipf.h" #include "snoop.h" #include "ipt.h" #if !defined(lint) -static const char rcsid[] = "@(#)$IPFilter: ipft_sn.c,v 2.1 1999/08/04 17:30:04 darrenr Exp $"; +static const char rcsid[] = "@(#)$IPFilter: ipft_sn.c,v 2.2 2000/03/13 22:10:24 darrenr Exp $"; #endif struct llc { diff --git a/usr.sbin/ipftest/ipft_td.c b/usr.sbin/ipftest/ipft_td.c index 1129f836f47..f79c4649da5 100644 --- a/usr.sbin/ipftest/ipft_td.c +++ b/usr.sbin/ipftest/ipft_td.c @@ -1,7 +1,7 @@ -/* $OpenBSD: ipft_td.c,v 1.14 2000/03/13 23:40:20 kjell Exp $ */ +/* $OpenBSD: ipft_td.c,v 1.15 2001/01/17 06:01:22 fgsch Exp $ */ /* - * Copyright (C) 1993-1998 by Darren Reed. + * Copyright (C) 1993-2000 by Darren Reed. * * Redistribution and use in source and binary forms are permitted * provided that this notice is preserved and due credit is given @@ -55,14 +55,14 @@ tcpdump -nqte #include <netinet/ip_icmp.h> #include <net/if.h> #include <netdb.h> -#include <netinet/ip_fil_compat.h> +#include <netinet/ip_compat.h> #include <netinet/tcpip.h> #include "ipf.h" #include "ipt.h" #if !defined(lint) static const char sccsid[] = "@(#)ipft_td.c 1.8 2/4/96 (C)1995 Darren Reed"; -static const char rcsid[] = "@(#)$IPFilter: ipft_td.c,v 2.1 1999/08/04 17:30:04 darrenr Exp $"; +static const char rcsid[] = "@(#)$IPFilter: ipft_td.c,v 2.2 2000/03/13 22:10:24 darrenr Exp $"; #endif static int tcpd_open __P((char *)); diff --git a/usr.sbin/ipftest/ipft_tx.c b/usr.sbin/ipftest/ipft_tx.c index 23397c5319a..d00d9c71d68 100644 --- a/usr.sbin/ipftest/ipft_tx.c +++ b/usr.sbin/ipftest/ipft_tx.c @@ -1,7 +1,7 @@ -/* $OpenBSD: ipft_tx.c,v 1.16 2000/03/13 23:40:20 kjell Exp $ */ +/* $OpenBSD: ipft_tx.c,v 1.17 2001/01/17 06:01:22 fgsch Exp $ */ /* - * Copyright (C) 1995-1998 by Darren Reed. + * Copyright (C) 1995-2000 by Darren Reed. * * Redistribution and use in source and binary forms are permitted * provided that this notice is preserved and due credit is given @@ -38,14 +38,14 @@ #include <netdb.h> #include <arpa/nameser.h> #include <resolv.h> -#include <netinet/ip_fil_compat.h> +#include <netinet/ip_compat.h> #include <netinet/tcpip.h> #include "ipf.h" #include "ipt.h" #if !defined(lint) static const char sccsid[] = "@(#)ipft_tx.c 1.7 6/5/96 (C) 1993 Darren Reed"; -static const char rcsid[] = "@(#)$IPFilter: ipft_tx.c,v 2.1 1999/08/04 17:30:05 darrenr Exp $"; +static const char rcsid[] = "@(#)$IPFilter: ipft_tx.c,v 2.3 2000/03/13 22:10:24 darrenr Exp $"; #endif extern int opts; @@ -56,8 +56,8 @@ static int text_open __P((char *)), text_close __P((void)); static int text_readip __P((char *, int, char **, int *)); static int parseline __P((char *, ip_t *, char **, int *)); -static char tcp_flagset[] = "FSRPAU"; -static u_char tcp_flags[] = { TH_FIN, TH_SYN, TH_RST, TH_PUSH, +static char _tcp_flagset[] = "FSRPAU"; +static u_char _tcp_flags[] = { TH_FIN, TH_SYN, TH_RST, TH_PUSH, TH_ACK, TH_URG }; struct ipread iptext = { text_open, text_close, text_readip }; @@ -303,13 +303,13 @@ int *out; ip->ip_dst.s_addr = tx_hostnum(*cpp, &r); cpp++; if (*cpp && ip->ip_p == IPPROTO_TCP) { - extern char tcp_flagset[]; - extern u_char tcp_flags[]; + extern char _tcp_flagset[]; + extern u_char _tcp_flags[]; char *s, *t; for (s = *cpp; *s; s++) - if ((t = index(tcp_flagset, *s))) - tcp->th_flags |= tcp_flags[t - tcp_flagset]; + if ((t = index(_tcp_flagset, *s))) + tcp->th_flags |= _tcp_flags[t - _tcp_flagset]; if (tcp->th_flags) cpp++; assert(tcp->th_flags != 0); diff --git a/usr.sbin/ipftest/ipt.c b/usr.sbin/ipftest/ipt.c index 4e6f6aa60f6..755f1552df9 100644 --- a/usr.sbin/ipftest/ipt.c +++ b/usr.sbin/ipftest/ipt.c @@ -1,7 +1,7 @@ -/* $OpenBSD: ipt.c,v 1.17 2000/03/13 23:40:20 kjell Exp $ */ +/* $OpenBSD: ipt.c,v 1.18 2001/01/17 06:01:22 fgsch Exp $ */ /* - * Copyright (C) 1993-1998 by Darren Reed. + * Copyright (C) 1993-2000 by Darren Reed. * * Redistribution and use in source and binary forms are permitted * provided that this notice is preserved and due credit is given @@ -47,7 +47,7 @@ #include <arpa/inet.h> #include <resolv.h> #include <ctype.h> -#include <netinet/ip_fil_compat.h> +#include <netinet/ip_compat.h> #include <netinet/tcpip.h> #include <netinet/ip_fil.h> #include <netinet/ip_nat.h> @@ -56,19 +56,22 @@ #include "ipt.h" #if !defined(lint) -static const char sccsid[] = "@(#)ipt.c 1.19 6/3/96 (C) 1993-1996 Darren Reed"; -static const char rcsid[] = "@(#)$IPFilter: ipt.c,v 2.1.2.1 2000/01/24 14:49:11 darrenr Exp $"; +static const char sccsid[] = "@(#)ipt.c 1.19 6/3/96 (C) 1993-2000 Darren Reed"; +static const char rcsid[] = "@(#)$IPFilter: ipt.c,v 2.6 2000/03/13 22:10:25 darrenr Exp $"; #endif extern char *optarg; extern struct frentry *ipfilter[2][2]; extern struct ipread snoop, etherf, tcpd, pcap, iptext, iphex; -extern struct ifnet *get_unit __P((char *)); +extern struct ifnet *get_unit __P((char *, int)); extern void init_ifp __P((void)); extern ipnat_t *natparse __P((char *, int)); extern int fr_running; int opts = 0; +#ifdef USE_INET6 +int use_inet6 = 0; +#endif int main __P((int, char *[])); int main(argc,argv) @@ -82,9 +85,14 @@ char *argv[]; ip_t *ip; int fd, i, dir = 0, c; - while ((c = getopt(argc, argv, "bdEHi:I:NoPr:STvX")) != -1) + while ((c = getopt(argc, argv, "6bdEHi:I:NoPr:STvX")) != -1) switch (c) { +#ifdef USE_INET6 + case '6' : + use_inet6 = 1; + break; +#endif case 'b' : opts |= OPT_BRIEF; break; @@ -177,7 +185,8 @@ char *argv[]; if (!(fr = natparse(line, linenum))) continue; i = IPL_EXTERN(ioctl)(IPL_LOGNAT, SIOCADNAT, - fr, FWRITE|FREAD); + (caddr_t)&fr, + FWRITE|FREAD); if (opts & OPT_DEBUG) fprintf(stderr, "iplioctl(ADNAT,%p,1) = %d\n", @@ -185,11 +194,12 @@ char *argv[]; } else { if (!(fr = parse(line, linenum))) continue; - i = IPL_EXTERN(ioctl)(0, SIOCADDFR, fr, + i = IPL_EXTERN(ioctl)(0, SIOCADAFR, + (caddr_t)&fr, FWRITE|FREAD); if (opts & OPT_DEBUG) fprintf(stderr, - "iplioctl(ADDFR,%p,1) = %d\n", + "iplioctl(ADAFR,%p,1) = %d\n", fr, i); } } @@ -210,7 +220,7 @@ char *argv[]; ip = (ip_t *)buf; while ((i = (*r->r_readip)((char *)buf, sizeof(buf), &iface, &dir)) > 0) { - ifp = iface ? get_unit(iface) : NULL; + ifp = iface ? get_unit(iface, ip->ip_v) : NULL; ip->ip_off = ntohs(ip->ip_off); ip->ip_len = ntohs(ip->ip_len); i = fr_check(ip, ip->ip_hl << 2, ifp, dir, (mb_t **)&buf); diff --git a/usr.sbin/ipftest/ipt.h b/usr.sbin/ipftest/ipt.h index 8b1fc4297f3..73d4bd0309d 100644 --- a/usr.sbin/ipftest/ipt.h +++ b/usr.sbin/ipftest/ipt.h @@ -1,12 +1,12 @@ -/* $OpenBSD: ipt.h,v 1.10 2000/03/13 23:40:20 kjell Exp $ */ +/* $OpenBSD: ipt.h,v 1.11 2001/01/17 06:01:23 fgsch Exp $ */ /* - * Copyright (C) 1993-1998 by Darren Reed. + * Copyright (C) 1993-2000 by Darren Reed. * * Redistribution and use in source and binary forms are permitted * provided that this notice is preserved and due credit is given * to the original author and the contributors. - * $IPFilter: ipt.h,v 2.1 1999/08/04 17:30:08 darrenr Exp $ + * $IPFilter: ipt.h,v 2.2 2000/03/13 22:10:25 darrenr Exp $ */ #ifndef __IPT_H__ diff --git a/usr.sbin/ipftest/misc.c b/usr.sbin/ipftest/misc.c index cc2aa4ce5c5..f1b7f94a49a 100644 --- a/usr.sbin/ipftest/misc.c +++ b/usr.sbin/ipftest/misc.c @@ -1,7 +1,7 @@ -/* $OpenBSD: misc.c,v 1.12 2000/03/13 23:40:20 kjell Exp $ */ +/* $OpenBSD: misc.c,v 1.13 2001/01/17 06:01:23 fgsch Exp $ */ /* - * Copyright (C) 1993-1998 by Darren Reed. + * Copyright (C) 1993-2000 by Darren Reed. * * Redistribution and use in source and binary forms are permitted * provided that this notice is preserved and due credit is given @@ -46,7 +46,7 @@ #include <netdb.h> #include <arpa/nameser.h> #include <resolv.h> -#include <netinet/ip_fil_compat.h> +#include <netinet/ip_compat.h> #include <netinet/tcpip.h> #include <netinet/ip_fil.h> #include "ipf.h" @@ -54,7 +54,7 @@ #if !defined(lint) static const char sccsid[] = "@(#)misc.c 1.3 2/4/96 (C) 1995 Darren Reed"; -static const char rcsid[] = "@(#)$IPFilter: misc.c,v 2.1 1999/08/04 17:30:11 darrenr Exp $"; +static const char rcsid[] = "@(#)$IPFilter: misc.c,v 2.2 2000/03/13 22:10:25 darrenr Exp $"; #endif extern int opts; diff --git a/usr.sbin/ipftest/pcap.h b/usr.sbin/ipftest/pcap.h index cd30a4f85f8..2496ac09e65 100644 --- a/usr.sbin/ipftest/pcap.h +++ b/usr.sbin/ipftest/pcap.h @@ -1,12 +1,12 @@ -/* $OpenBSD: pcap.h,v 1.10 2000/03/13 23:40:20 kjell Exp $ */ +/* $OpenBSD: pcap.h,v 1.11 2001/01/17 06:01:23 fgsch Exp $ */ /* - * Copyright (C) 1993-1998 by Darren Reed. + * Copyright (C) 1993-2000 by Darren Reed. * * Redistribution and use in source and binary forms are permitted * provided that this notice is preserved and due credit is given * to the original author and the contributors. - * $IPFilter: pcap.h,v 2.1 1999/08/04 17:30:17 darrenr Exp $ + * $IPFilter: pcap.h,v 2.2 2000/03/13 22:10:27 darrenr Exp $ */ /* * This header file is constructed to match the version described by diff --git a/usr.sbin/ipftest/snoop.h b/usr.sbin/ipftest/snoop.h index a7847ca8ff6..cbed990015c 100644 --- a/usr.sbin/ipftest/snoop.h +++ b/usr.sbin/ipftest/snoop.h @@ -1,7 +1,7 @@ -/* $OpenBSD: snoop.h,v 1.9 2000/03/13 23:40:20 kjell Exp $ */ +/* $OpenBSD: snoop.h,v 1.10 2001/01/17 06:01:23 fgsch Exp $ */ /* - * Copyright (C) 1993-1998 by Darren Reed. + * Copyright (C) 1993-2000 by Darren Reed. * * Redistribution and use in source and binary forms are permitted * provided that this notice is preserved and due credit is given @@ -13,7 +13,7 @@ /* * written to comply with the RFC (1761) from Sun. - * $IPFilter: snoop.h,v 2.1 1999/08/04 17:30:19 darrenr Exp $ + * $IPFilter: snoop.h,v 2.2 2000/03/13 22:10:27 darrenr Exp $ */ struct snoophdr { char s_id[8]; diff --git a/usr.sbin/ipsend/common/44arp.c b/usr.sbin/ipsend/common/44arp.c index 290e676d514..751a03549d3 100644 --- a/usr.sbin/ipsend/common/44arp.c +++ b/usr.sbin/ipsend/common/44arp.c @@ -1,3 +1,5 @@ +/* $OpenBSD: 44arp.c,v 1.3 2001/01/17 06:01:24 fgsch Exp $ */ + /* * Based upon 4.4BSD's /usr/sbin/arp */ @@ -26,6 +28,7 @@ # include <net/if_var.h> #endif #include "ipsend.h" +#include "iplang.h" /* @@ -65,6 +68,11 @@ char *addr, *eaddr; struct sockaddr_inarp *sin; struct sockaddr_dl *sdl; +#ifdef IPSEND + if (arp_getipv4(addr, ether) == 0) + return 0; +#endif + mib[0] = CTL_NET; mib[1] = PF_ROUTE; mib[2] = 0; diff --git a/usr.sbin/ipsend/common/dltest.h b/usr.sbin/ipsend/common/dltest.h deleted file mode 100644 index 4c32c30eb1b..00000000000 --- a/usr.sbin/ipsend/common/dltest.h +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Common DLPI Test Suite header file - * - */ - -/* - * Maximum control/data buffer size (in long's !!) for getmsg(). - */ -#define MAXDLBUF 8192 - -/* - * Maximum number of seconds we'll wait for any - * particular DLPI acknowledgment from the provider - * after issuing a request. - */ -#define MAXWAIT 15 - -/* - * Maximum address buffer length. - */ -#define MAXDLADDR 1024 - - -/* - * Handy macro. - */ -#define OFFADDR(s, n) (u_char*)((char*)(s) + (int)(n)) - -/* - * externs go here - */ -extern void sigalrm(); diff --git a/usr.sbin/ipsend/common/ip.c b/usr.sbin/ipsend/common/ip.c index ede14cf1cc9..86bd2fef8b9 100644 --- a/usr.sbin/ipsend/common/ip.c +++ b/usr.sbin/ipsend/common/ip.c @@ -1,5 +1,7 @@ +/* $OpenBSD: ip.c,v 1.6 2001/01/17 06:01:24 fgsch Exp $ */ + /* - * ip.c (C) 1995-1997 Darren Reed + * ip.c (C) 1995-1998 Darren Reed * * Redistribution and use in source and binary forms are permitted * provided that this notice is preserved and due credit is given @@ -7,7 +9,7 @@ */ #if !defined(lint) static const char sccsid[] = "%W% %G% (C)1995"; -static const char rcsid[] = "@(#)$Id: ip.c,v 1.5 1998/01/26 04:16:50 dgregor Exp $"; +static const char rcsid[] = "@(#)$IPFilter: ip.c,v 2.1 1999/08/04 17:31:04 darrenr Exp $"; #endif #include <errno.h> #include <stdio.h> @@ -117,7 +119,6 @@ int frag; last_gw.s_addr = gwip.s_addr; iplen = ip->ip_len; ip->ip_len = htons(iplen); - ip->ip_off = htons(ip->ip_off); if (!(frag & 2)) { if (!ip->ip_v) ip->ip_v = IPVERSION; @@ -260,7 +261,7 @@ struct in_addr gwip; i = sizeof(struct tcpiphdr) / sizeof(long); - if ((ti->ti_flags == TH_SYN) && !ip->ip_off && + if ((ti->ti_flags == TH_SYN) && !ntohs(ip->ip_off) && (lbuf[i] != htonl(0x020405b4))) { lbuf[i] = htonl(0x020405b4); bcopy((char *)ip + hlen + thlen, (char *)ip + hlen + thlen + 4, diff --git a/usr.sbin/ipsend/common/ip_compat.h b/usr.sbin/ipsend/common/ip_compat.h deleted file mode 100644 index c600f17e258..00000000000 --- a/usr.sbin/ipsend/common/ip_compat.h +++ /dev/null @@ -1,201 +0,0 @@ -/* - * (C)opyright 1995 by Darren Reed. - * - * This code may be freely distributed as long as it retains this notice - * and is not changed in any way. The author accepts no responsibility - * for the use of this software. I hate legaleese, don't you ? - * - * @(#)ip_compat.h 1.2 12/7/95 - */ - -/* - * These #ifdef's are here mainly for linux, but who knows, they may - * not be in other places or maybe one day linux will grow up and some - * of these will turn up there too. - */ -#ifndef ICMP_UNREACH -# define ICMP_UNREACH ICMP_DEST_UNREACH -#endif -#ifndef ICMP_SOURCEQUENCH -# define ICMP_SOURCEQUENCH ICMP_SOURCE_QUENCH -#endif -#ifndef ICMP_TIMXCEED -# define ICMP_TIMXCEED ICMP_TIME_EXCEEDED -#endif -#ifndef ICMP_PARAMPROB -# define ICMP_PARAMPROB ICMP_PARAMETERPROB -#endif -#ifndef IPVERSION -# define IPVERSION 4 -#endif -#ifndef IPOPT_MINOFF -# define IPOPT_MINOFF 4 -#endif -#ifndef IPOPT_COPIED -# define IPOPT_COPIED(x) ((x)&0x80) -#endif -#ifndef IPOPT_EOL -# define IPOPT_EOL 0 -#endif -#ifndef IPOPT_NOP -# define IPOPT_NOP 1 -#endif -#ifndef IP_MF -# define IP_MF ((u_short)0x2000) -#endif -#ifndef ETHERTYPE_IP -# define ETHERTYPE_IP ((u_short)0x0800) -#endif -#ifndef TH_FIN -# define TH_FIN 0x01 -#endif -#ifndef TH_SYN -# define TH_SYN 0x02 -#endif -#ifndef TH_RST -# define TH_RST 0x04 -#endif -#ifndef TH_PUSH -# define TH_PUSH 0x08 -#endif -#ifndef TH_ACK -# define TH_ACK 0x10 -#endif -#ifndef TH_URG -# define TH_URG 0x20 -#endif -#ifndef IPOPT_EOL -# define IPOPT_EOL 0 -#endif -#ifndef IPOPT_NOP -# define IPOPT_NOP 1 -#endif -#ifndef IPOPT_RR -# define IPOPT_RR 7 -#endif -#ifndef IPOPT_TS -# define IPOPT_TS 68 -#endif -#ifndef IPOPT_SECURITY -# define IPOPT_SECURITY 130 -#endif -#ifndef IPOPT_LSRR -# define IPOPT_LSRR 131 -#endif -#ifndef IPOPT_SATID -# define IPOPT_SATID 136 -#endif -#ifndef IPOPT_SSRR -# define IPOPT_SSRR 137 -#endif -#ifndef IPOPT_SECUR_UNCLASS -# define IPOPT_SECUR_UNCLASS ((u_short)0x0000) -#endif -#ifndef IPOPT_SECUR_CONFID -# define IPOPT_SECUR_CONFID ((u_short)0xf135) -#endif -#ifndef IPOPT_SECUR_EFTO -# define IPOPT_SECUR_EFTO ((u_short)0x789a) -#endif -#ifndef IPOPT_SECUR_MMMM -# define IPOPT_SECUR_MMMM ((u_short)0xbc4d) -#endif -#ifndef IPOPT_SECUR_RESTR -# define IPOPT_SECUR_RESTR ((u_short)0xaf13) -#endif -#ifndef IPOPT_SECUR_SECRET -# define IPOPT_SECUR_SECRET ((u_short)0xd788) -#endif -#ifndef IPOPT_SECUR_TOPSECRET -# define IPOPT_SECUR_TOPSECRET ((u_short)0x6bc5) -#endif - -#ifdef linux -# define icmp icmphdr -# define icmp_type type -# define icmp_code code - -/* - * From /usr/include/netinet/ip_var.h - * !%@#!$@# linux... - */ -struct ipovly { - caddr_t ih_next, ih_prev; /* for protocol sequence q's */ - u_char ih_x1; /* (unused) */ - u_char ih_pr; /* protocol */ - short ih_len; /* protocol length */ - struct in_addr ih_src; /* source internet address */ - struct in_addr ih_dst; /* destination internet address */ -}; - -typedef struct { - __u16 th_sport; - __u16 th_dport; - __u32 th_seq; - __u32 th_ack; -# if defined(__i386__) || defined(__MIPSEL__) || defined(__alpha__) ||\ - defined(vax) - __u8 th_res:4; - __u8 th_off:4; -#else - __u8 th_off:4; - __u8 th_res:4; -#endif - __u8 th_flags; - __u16 th_win; - __u16 th_sum; - __u16 th_urp; -} tcphdr_t; - -typedef struct { - __u16 uh_sport; - __u16 uh_dport; - __s16 uh_ulen; - __u16 uh_sum; -} udphdr_t; - -typedef struct { -# if defined(__i386__) || defined(__MIPSEL__) || defined(__alpha__) ||\ - defined(vax) - __u8 ip_hl:4; - __u8 ip_v:4; -# else - __u8 ip_hl:4; - __u8 ip_v:4; -# endif - __u8 ip_tos; - __u16 ip_len; - __u16 ip_id; - __u16 ip_off; - __u8 ip_ttl; - __u8 ip_p; - __u16 ip_sum; - struct in_addr ip_src; - struct in_addr ip_dst; -} ip_t; - -typedef struct { - __u8 ether_dhost[6]; - __u8 ether_shost[6]; - __u16 ether_type; -} ether_header_t; - -# define bcopy(a,b,c) memmove(b,a,c) -# define bcmp(a,b,c) memcmp(a,b,c) - -# define ifnet device - -#else - -typedef struct udphdr udphdr_t; -typedef struct tcphdr tcphdr_t; -typedef struct ip ip_t; -typedef struct ether_header ether_header_t; - -#endif - -#if defined(__SVR4) || defined(__svr4__) -# define bcopy(a,b,c) memmove(b,a,c) -# define bcmp(a,b,c) memcmp(a,b,c) -# define bzero(a,b) memset(a,0,b) -#endif diff --git a/usr.sbin/ipsend/common/ip_var.h b/usr.sbin/ipsend/common/ip_var.h deleted file mode 100644 index 92eb38a0bef..00000000000 --- a/usr.sbin/ipsend/common/ip_var.h +++ /dev/null @@ -1,123 +0,0 @@ -/* @(#)ip_var.h 1.11 88/08/19 SMI; from UCB 7.1 6/5/86 */ - -/* - * Copyright (c) 1982, 1986 Regents of the University of California. - * All rights reserved. The Berkeley software License Agreement - * specifies the terms and conditions for redistribution. - */ - -/* - * Overlay for ip header used by other protocols (tcp, udp). - */ - -#ifndef _netinet_ip_var_h -#define _netinet_ip_var_h - -struct ipovly { - caddr_t ih_next, ih_prev; /* for protocol sequence q's */ - u_char ih_x1; /* (unused) */ - u_char ih_pr; /* protocol */ - short ih_len; /* protocol length */ - struct in_addr ih_src; /* source internet address */ - struct in_addr ih_dst; /* destination internet address */ -}; - -/* - * Ip reassembly queue structure. Each fragment - * being reassembled is attached to one of these structures. - * They are timed out after ipq_ttl drops to 0, and may also - * be reclaimed if memory becomes tight. - */ -struct ipq { - struct ipq *next,*prev; /* to other reass headers */ - u_char ipq_ttl; /* time for reass q to live */ - u_char ipq_p; /* protocol of this fragment */ - u_short ipq_id; /* sequence id for reassembly */ - struct ipasfrag *ipq_next,*ipq_prev; - /* to ip headers of fragments */ - struct in_addr ipq_src,ipq_dst; -}; - -/* - * Ip header, when holding a fragment. - * - * Note: ipf_next must be at same offset as ipq_next above - */ -struct ipasfrag { -#if defined(vax) || defined(i386) - u_char ip_hl:4, - ip_v:4; -#endif -#if defined(mc68000) || defined(sparc) - u_char ip_v:4, - ip_hl:4; -#endif - u_char ipf_mff; /* copied from (ip_off&IP_MF) */ - short ip_len; - u_short ip_id; - short ip_off; - u_char ip_ttl; - u_char ip_p; - u_short ip_sum; - struct ipasfrag *ipf_next; /* next fragment */ - struct ipasfrag *ipf_prev; /* previous fragment */ -}; - -/* - * Structure stored in mbuf in inpcb.ip_options - * and passed to ip_output when ip options are in use. - * The actual length of the options (including ipopt_dst) - * is in m_len. - */ -#define MAX_IPOPTLEN 40 - -struct ipoption { - struct in_addr ipopt_dst; /* first-hop dst if source routed */ - char ipopt_list[MAX_IPOPTLEN]; /* options proper */ -}; - -/* - * Structure stored in an mbuf attached to inpcb.ip_moptions and - * passed to ip_output when IP multicast options are in use. - */ -struct ip_moptions { - struct ifnet *imo_multicast_ifp; /* ifp for outgoing multicasts */ - u_char imo_multicast_ttl; /* TTL for outgoing multicasts */ - u_char imo_multicast_loop; /* 1 => hear sends if a member */ - u_short imo_num_memberships;/* no. memberships this socket */ - struct in_multi *imo_membership[IP_MAX_MEMBERSHIPS]; -#ifdef RSVP_ISI - long imo_multicast_vif; /* vif for outgoing multicasts */ -#endif /* RSVP_ISI */ -}; - -struct ipstat { - long ips_total; /* total packets received */ - long ips_badsum; /* checksum bad */ - long ips_tooshort; /* packet too short */ - long ips_toosmall; /* not enough data */ - long ips_badhlen; /* ip header length < data size */ - long ips_badlen; /* ip length < ip header length */ - long ips_fragments; /* fragments received */ - long ips_fragdropped; /* frags dropped (dups, out of space) */ - long ips_fragtimeout; /* fragments timed out */ - long ips_forward; /* packets forwarded */ - long ips_cantforward; /* packets rcvd for unreachable dest */ - long ips_redirectsent; /* packets forwarded on same net */ -}; - -#ifdef KERNEL -/* flags passed to ip_output as last parameter */ -#define IP_FORWARDING 0x1 /* most of ip header exists */ -#define IP_MULTICASTOPTS 0x2 /* multicast opts present */ -#define IP_ROUTETOIF SO_DONTROUTE /* bypass routing tables */ -#define IP_ALLOWBROADCAST SO_BROADCAST /* can send broadcast packets */ - -struct ipstat ipstat; -struct ipq ipq; /* ip reass. queue */ -u_short ip_id; /* ip packet ctr, for ids */ - -struct mbuf *ip_srcroute(); -#endif - -#endif /*!_netinet_ip_var_h*/ diff --git a/usr.sbin/ipsend/common/iplang.h b/usr.sbin/ipsend/common/iplang.h index a7a13f91503..e52fd4be33f 100644 --- a/usr.sbin/ipsend/common/iplang.h +++ b/usr.sbin/ipsend/common/iplang.h @@ -1,5 +1,7 @@ +/* $OpenBSD: iplang.h,v 1.2 2001/01/17 06:01:25 fgsch Exp $ */ + /* - * Copyright (C) 1997 by Darren Reed. + * Copyright (C) 1997-1998 by Darren Reed. * * Redistribution and use in source and binary forms are permitted * provided that this notice is preserved and due credit is given @@ -49,3 +51,6 @@ typedef struct aniphdr { #define ah_tcp ah_un.ahu_tcp #define ah_udp ah_un.ahu_udp #define ah_icmp ah_un.ahu_icmp + +extern int get_arpipv4 __P((char *, char *)); + diff --git a/usr.sbin/ipsend/common/ipsend.h b/usr.sbin/ipsend/common/ipsend.h index 460d6e2ccba..1404a056947 100644 --- a/usr.sbin/ipsend/common/ipsend.h +++ b/usr.sbin/ipsend/common/ipsend.h @@ -1,5 +1,7 @@ +/* $OpenBSD: ipsend.h,v 1.3 2001/01/17 06:01:25 fgsch Exp $ */ + /* - * ipsend.h (C) 1997 Darren Reed + * ipsend.h (C) 1997-1998 Darren Reed * * This was written to test what size TCP fragments would get through * various TCP/IP packet filters, as used in IP firewalls. In certain @@ -21,7 +23,7 @@ # endif #endif -#include "ip_fil_compat.h" +#include "ip_compat.h" #ifdef linux #include <linux/sockios.h> #endif @@ -64,6 +66,6 @@ extern int kmemcpy __P((char *, void *, int)); #define KMCPY(a,b,c) kmemcpy((char *)(a), (void *)(b), (int)(c)) -#ifndef OPT_RAW +#ifndef OPT_RAW #define OPT_RAW 0x80000 #endif diff --git a/usr.sbin/ipsend/common/sbpf.c b/usr.sbin/ipsend/common/sbpf.c index b8eba0b0450..fc4c0e85c2b 100644 --- a/usr.sbin/ipsend/common/sbpf.c +++ b/usr.sbin/ipsend/common/sbpf.c @@ -1,5 +1,7 @@ +/* $OpenBSD: sbpf.c,v 1.5 2001/01/17 06:01:25 fgsch Exp $ */ + /* - * (C)opyright 1995-1997 Darren Reed. (from tcplog) + * (C)opyright 1995-1998 Darren Reed. (from tcplog) * * Redistribution and use in source and binary forms are permitted * provided that this notice is preserved and due credit is given @@ -24,7 +26,11 @@ #if BSD < 199103 #include <sys/fcntlcom.h> #endif -#include <sys/dir.h> +#if (__FreeBSD_version >= 300000) +# include <sys/dirent.h> +#else +# include <sys/dir.h> +#endif #include <net/bpf.h> #include <net/if.h> @@ -39,11 +45,11 @@ #if !defined(lint) static const char sccsid[] = "@(#)sbpf.c 1.3 8/25/95 (C)1995 Darren Reed"; -static const char rcsid[] = "@(#)$Id: sbpf.c,v 1.4 1999/12/30 08:02:33 kjell Exp $"; +static const char rcsid[] = "@(#)$IPFilter: sbpf.c,v 2.1 1999/08/04 17:31:13 darrenr Exp $"; #endif /* - * the code herein is derived from libpcap. + * the code herein is dervied from libpcap. */ static u_char *buf = NULL; static int bufsize = 0, timeout = 1; @@ -59,6 +65,8 @@ int sport, tout; char bpfname[16]; int fd, i; + fd = 0; /* shutup gcc */ + for (i = 0; i < 16; i++) { (void) sprintf(bpfname, "/dev/bpf%d", i); diff --git a/usr.sbin/ipsend/common/sock.c b/usr.sbin/ipsend/common/sock.c index 53e2db08a60..8c169cef19a 100644 --- a/usr.sbin/ipsend/common/sock.c +++ b/usr.sbin/ipsend/common/sock.c @@ -1,5 +1,7 @@ +/* $OpenBSD: sock.c,v 1.4 2001/01/17 06:01:25 fgsch Exp $ */ + /* - * sock.c (C) 1995-1997 Darren Reed + * sock.c (C) 1995-1998 Darren Reed * * Redistribution and use in source and binary forms are permitted * provided that this notice is preserved and due credit is given @@ -7,7 +9,7 @@ */ #if !defined(lint) static const char sccsid[] = "@(#)sock.c 1.2 1/11/96 (C)1995 Darren Reed"; -static const char rcsid[] = "@(#)$Id: sock.c,v 1.3 1998/01/26 04:16:54 dgregor Exp $"; +static const char rcsid[] = "@(#)$IPFilter: sock.c,v 2.1.4.1 2000/12/16 21:05:44 darrenr Exp $"; #endif #include <stdio.h> #include <unistd.h> @@ -22,7 +24,11 @@ static const char rcsid[] = "@(#)$Id: sock.c,v 1.3 1998/01/26 04:16:54 dgregor E #ifndef ultrix #include <fcntl.h> #endif -#include <sys/dir.h> +#if (__FreeBSD_version >= 300000) +# include <sys/dirent.h> +#else +# include <sys/dir.h> +#endif #define _KERNEL #define KERNEL #ifdef ultrix @@ -278,12 +284,21 @@ struct tcpiphdr *ti; return NULL; fd = (struct filedesc *)malloc(sizeof(*fd)); +#if defined( __FreeBSD_version) && __FreeBSD_version >= 500013 + if (KMCPY(fd, p->ki_fd, sizeof(*fd)) == -1) + { + fprintf(stderr, "read(%#lx,%#lx) failed\n", + (u_long)p, (u_long)p->ki_fd); + return NULL; + } +#else if (KMCPY(fd, p->kp_proc.p_fd, sizeof(*fd)) == -1) { fprintf(stderr, "read(%#lx,%#lx) failed\n", (u_long)p, (u_long)p->kp_proc.p_fd); return NULL; } +#endif o = (struct file **)calloc(1, sizeof(*o) * (fd->fd_lastfile + 1)); if (KMCPY(o, fd->fd_ofiles, (fd->fd_lastfile + 1) * sizeof(*o)) == -1) diff --git a/usr.sbin/ipsend/common/tcpip.h b/usr.sbin/ipsend/common/tcpip.h deleted file mode 100644 index 72c8737f443..00000000000 --- a/usr.sbin/ipsend/common/tcpip.h +++ /dev/null @@ -1,91 +0,0 @@ -/* - * Copyright (c) 1982, 1986, 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * @(#)tcpip.h 8.1 (Berkeley) 6/10/93 - * $Id: tcpip.h,v 1.3 1998/01/26 04:16:55 dgregor Exp $ - */ - -#ifndef _NETINET_TCPIP_H_ -#define _NETINET_TCPIP_H_ - -# if defined(linux) && !defined(LINUX_IPOVLY) -# define LINUX_IPOVLY -struct ipovly { - caddr_t ih_next, ih_prev; /* for protocol sequence q's */ - u_char ih_x1; /* (unused) */ - u_char ih_pr; /* protocol */ - short ih_len; /* protocol length */ - struct in_addr ih_src; /* source internet address */ - struct in_addr ih_dst; /* destination internet address */ -}; -# endif - -/* - * Tcp+ip header, after ip options removed. - */ -struct tcpiphdr { - struct ipovly ti_i; /* overlaid ip structure */ -#ifdef linux - tcphdr_t ti_t; -#else - struct tcphdr ti_t; /* tcp header */ -#endif -}; -#ifdef notyet -/* - * Tcp+ip header, after ip options removed but including TCP options. - */ -struct full_tcpiphdr { - struct ipovly ti_i; /* overlaid ip structure */ - struct tcphdr ti_t; /* tcp header */ - char ti_o[TCP_MAXOLEN]; /* space for tcp options */ -}; -#endif /* notyet */ -#define ti_next ti_i.ih_next -#define ti_prev ti_i.ih_prev -#define ti_x1 ti_i.ih_x1 -#define ti_pr ti_i.ih_pr -#define ti_len ti_i.ih_len -#define ti_src ti_i.ih_src -#define ti_dst ti_i.ih_dst -#define ti_sport ti_t.th_sport -#define ti_dport ti_t.th_dport -#define ti_seq ti_t.th_seq -#define ti_ack ti_t.th_ack -#define ti_x2 ti_t.th_x2 -#define ti_off ti_t.th_off -#define ti_flags ti_t.th_flags -#define ti_win ti_t.th_win -#define ti_sum ti_t.th_sum -#define ti_urp ti_t.th_urp - -#endif diff --git a/usr.sbin/ipsend/ipresend/ipresend.c b/usr.sbin/ipsend/ipresend/ipresend.c index b4c4e1c8fd4..5a4c4ba4aeb 100644 --- a/usr.sbin/ipsend/ipresend/ipresend.c +++ b/usr.sbin/ipsend/ipresend/ipresend.c @@ -1,6 +1,7 @@ -/* $OpenBSD: ipresend.c,v 1.4 1999/03/31 05:50:19 deraadt Exp $ */ +/* $OpenBSD: ipresend.c,v 1.5 2001/01/17 06:01:25 fgsch Exp $ */ + /* - * ipresend.c (C) 1995-1997 Darren Reed + * ipresend.c (C) 1995-1998 Darren Reed * * This was written to test what size TCP fragments would get through * various TCP/IP packet filters, as used in IP firewalls. In certain @@ -13,7 +14,7 @@ */ #if !defined(lint) static const char sccsid[] = "%W% %G% (C)1995 Darren Reed"; -static const char rcsid[] = "@(#)$Id: ipresend.c,v 1.4 1999/03/31 05:50:19 deraadt Exp $"; +static const char rcsid[] = "@(#)$IPFilter: ipresend.c,v 2.1 1999/08/04 17:31:05 darrenr Exp $"; #endif #include <stdio.h> #include <stdlib.h> @@ -47,7 +48,7 @@ int opts = 0; # ifdef linux char default_device[] = "eth0"; # else -# if defined(sun) || defined(__OpenBSD__) +# ifdef sun char default_device[] = "le0"; # else # ifdef ultrix @@ -146,7 +147,7 @@ char **argv; usage(name); } - if (!ipr) + if (!ipr || !resend) usage(name); gwip.s_addr = 0; diff --git a/usr.sbin/ipsend/ipresend/resend.c b/usr.sbin/ipsend/ipresend/resend.c index 4beec1ac887..7890062250d 100644 --- a/usr.sbin/ipsend/ipresend/resend.c +++ b/usr.sbin/ipsend/ipresend/resend.c @@ -1,6 +1,7 @@ -/* $OpenBSD: resend.c,v 1.3 1998/01/26 04:16:59 dgregor Exp $ */ +/* $OpenBSD: resend.c,v 1.4 2001/01/17 06:01:26 fgsch Exp $ */ + /* - * resend.c (C) 1995-1997 Darren Reed + * resend.c (C) 1995-1998 Darren Reed * * This was written to test what size TCP fragments would get through * various TCP/IP packet filters, as used in IP firewalls. In certain @@ -13,7 +14,7 @@ */ #if !defined(lint) static const char sccsid[] = "@(#)resend.c 1.3 1/11/96 (C)1995 Darren Reed"; -static const char rcsid[] = "@(#)$Id: resend.c,v 1.3 1998/01/26 04:16:59 dgregor Exp $"; +static const char rcsid[] = "@(#)$IPFilter: resend.c,v 2.1 1999/08/04 17:31:12 darrenr Exp $"; #endif #include <stdio.h> #include <netdb.h> @@ -42,7 +43,7 @@ static const char rcsid[] = "@(#)$Id: resend.c,v 1.3 1998/01/26 04:16:59 dgregor extern int opts; -static u_char buf[65536]; /* 1 big packet */ +static u_char pbuf[65536]; /* 1 big packet */ void printpacket __P((ip_t *)); @@ -96,7 +97,7 @@ char *datain; if (fd < 0) exit(-1); - ip = (struct ip *)buf; + ip = (struct ip *)pbuf; eh = (ether_header_t *)malloc(sizeof(*eh)); bzero((char *)A_A eh->ether_shost, sizeof(eh->ether_shost)); @@ -106,7 +107,7 @@ char *datain; return -2; } - while ((i = (*r->r_readip)(buf, sizeof(buf), NULL, NULL)) > 0) + while ((i = (*r->r_readip)((char *)pbuf, sizeof(pbuf), NULL, NULL)) > 0) { if (!(opts & OPT_RAW)) { len = ntohs(ip->ip_len); @@ -128,7 +129,7 @@ char *datain; len += sizeof(*eh); printpacket(ip); } else { - eh = (ether_header_t *)buf; + eh = (ether_header_t *)pbuf; len = i; } diff --git a/usr.sbin/ipsend/ipsend/iplang_l.l b/usr.sbin/ipsend/ipsend/iplang_l.l index c4dcad9fe3e..bd51afb6f45 100644 --- a/usr.sbin/ipsend/ipsend/iplang_l.l +++ b/usr.sbin/ipsend/ipsend/iplang_l.l @@ -1,17 +1,14 @@ -%e 1500 -%p 4000 -%a 4000 -%o 6000 %{ -/* $OpenBSD: iplang_l.l,v 1.1 1998/01/26 04:17:01 dgregor Exp $ */ +/* $OpenBSD: iplang_l.l,v 1.2 2001/01/17 06:01:26 fgsch Exp $ */ + /* - * Copyright (C) 1997 by Darren Reed. + * Copyright (C) 1997-1998 by Darren Reed. * * Redistribution and use in source and binary forms are permitted * provided that this notice is preserved and due credit is given * to the original author and the contributors. * - * $Id: iplang_l.l,v 1.1 1998/01/26 04:17:01 dgregor Exp $ + * $IPFilter: iplang_l.l,v 2.2 2000/02/18 00:18:05 darrenr Exp $ */ #include <stdio.h> #include <string.h> @@ -23,7 +20,7 @@ #include <netinet/in_systm.h> #include <netinet/in.h> #include "y.tab.h" -#include "ip_fil_compat.h" +#include "ip_compat.h" #include "ipf.h" #ifndef __P @@ -36,7 +33,7 @@ extern int opts; -int lineNum = 0, proto = 0, oldproto = 0, next = -1, laststate = 0; +int lineNum = 0, ipproto = 0, oldipproto = 0, next = -1, laststate = 0; int *prstack = NULL, numpr = 0, state = 0, token = 0; void yyerror __P((char *)); @@ -47,134 +44,143 @@ int next_item __P((int)); int save_token __P((void)); void swallow __P((void)); int yylex __P((void)); -%} +struct wordtab { + char *word; + int state; + int next; +}; + +struct wordtab words[] = { + { "interface", IL_INTERFACE, -1 }, + { "iface", IL_INTERFACE, -1 }, + { "name", IL_IFNAME, IL_TOKEN }, + { "ifname", IL_IFNAME, IL_TOKEN }, + { "router", IL_DEFROUTER, IL_TOKEN }, + { "mtu", IL_MTU, IL_NUMBER }, + { "eaddr", IL_EADDR, IL_TOKEN }, + { "v4addr", IL_V4ADDR, IL_TOKEN }, + { "ipv4", IL_IPV4, -1 }, + { "v", IL_V4V, IL_TOKEN }, + { "proto", IL_V4PROTO, IL_TOKEN }, + { "hl", IL_V4HL, IL_TOKEN }, + { "id", IL_V4ID, IL_TOKEN }, + { "ttl", IL_V4TTL, IL_TOKEN }, + { "tos", IL_V4TOS, IL_TOKEN }, + { "src", IL_V4SRC, IL_TOKEN }, + { "dst", IL_V4DST, IL_TOKEN }, + { "opt", IL_OPT, -1 }, + { "len", IL_LEN, IL_TOKEN }, + { "off", IL_OFF, IL_TOKEN }, + { "sum", IL_SUM, IL_TOKEN }, + { "tcp", IL_TCP, -1 }, + { "sport", IL_SPORT, IL_TOKEN }, + { "dport", IL_DPORT, IL_TOKEN }, + { "seq", IL_TCPSEQ, IL_TOKEN }, + { "ack", IL_TCPACK, IL_TOKEN }, + { "flags", IL_TCPFL, IL_TOKEN }, + { "urp", IL_TCPURP, IL_TOKEN }, + { "win", IL_TCPWIN, IL_TOKEN }, + { "udp", IL_UDP, -1 }, + { "send", IL_SEND, -1 }, + { "via", IL_VIA, IL_TOKEN }, + { "arp", IL_ARP, -1 }, + { "data", IL_DATA, -1 }, + { "value", IL_DVALUE, IL_TOKEN }, + { "file", IL_DFILE, IL_TOKEN }, + { "nop", IL_IPO_NOP, -1 }, + { "eol", IL_IPO_EOL, -1 }, + { "rr", IL_IPO_RR, -1 }, + { "zsu", IL_IPO_ZSU, -1 }, + { "mtup", IL_IPO_MTUP, -1 }, + { "mtur", IL_IPO_MTUR, -1 }, + { "encode", IL_IPO_ENCODE, -1 }, + { "ts", IL_IPO_TS, -1 }, + { "tr", IL_IPO_TR, -1 }, + { "sec", IL_IPO_SEC, -1 }, + { "secclass", IL_IPO_SECCLASS, IL_TOKEN }, + { "lsrr", IL_IPO_LSRR, -1 }, + { "esec", IL_IPO_ESEC, -1 }, + { "cipso", IL_IPO_CIPSO, -1 }, + { "satid", IL_IPO_SATID, -1 }, + { "ssrr", IL_IPO_SSRR, -1 }, + { "addext", IL_IPO_ADDEXT, -1 }, + { "visa", IL_IPO_VISA, -1 }, + { "imitd", IL_IPO_IMITD, -1 }, + { "eip", IL_IPO_EIP, -1 }, + { "finn", IL_IPO_FINN, -1 }, + { "mss", IL_TCPO_MSS, IL_TOKEN }, + { "wscale", IL_TCPO_WSCALE, IL_TOKEN }, + { "reserv-4", IL_IPS_RESERV4, -1 }, + { "topsecret", IL_IPS_TOPSECRET, -1 }, + { "secret", IL_IPS_SECRET, -1 }, + { "reserv-3", IL_IPS_RESERV3, -1 }, + { "confid", IL_IPS_CONFID, -1 }, + { "unclass", IL_IPS_UNCLASS, -1 }, + { "reserv-2", IL_IPS_RESERV2, -1 }, + { "reserv-1", IL_IPS_RESERV1, -1 }, + { "icmp", IL_ICMP, -1 }, + { "type", IL_ICMPTYPE, -1 }, + { "code", IL_ICMPCODE, -1 }, + { "echorep", IL_ICMP_ECHOREPLY, -1 }, + { "unreach", IL_ICMP_UNREACH, -1 }, + { "squench", IL_ICMP_SOURCEQUENCH, -1 }, + { "redir", IL_ICMP_REDIRECT, -1 }, + { "echo", IL_ICMP_ECHO, -1 }, + { "routerad", IL_ICMP_ROUTERADVERT, -1 }, + { "routersol", IL_ICMP_ROUTERSOLICIT, -1 }, + { "timex", IL_ICMP_TIMXCEED, -1 }, + { "paramprob", IL_ICMP_PARAMPROB, -1 }, + { "timest", IL_ICMP_TSTAMP, -1 }, + { "timestrep", IL_ICMP_TSTAMPREPLY, -1 }, + { "inforeq", IL_ICMP_IREQ, -1 }, + { "inforep", IL_ICMP_IREQREPLY, -1 }, + { "maskreq", IL_ICMP_MASKREQ, -1 }, + { "maskrep", IL_ICMP_MASKREPLY, -1 }, + { "net-unr", IL_ICMP_UNREACH_NET, -1 }, + { "host-unr", IL_ICMP_UNREACH_HOST, -1 }, + { "proto-unr", IL_ICMP_UNREACH_PROTOCOL, -1 }, + { "port-unr", IL_ICMP_UNREACH_PORT, -1 }, + { "needfrag", IL_ICMP_UNREACH_NEEDFRAG, -1 }, + { "srcfail", IL_ICMP_UNREACH_SRCFAIL, -1 }, + { "net-unk", IL_ICMP_UNREACH_NET_UNKNOWN, -1 }, + { "host-unk", IL_ICMP_UNREACH_HOST_UNKNOWN, -1 }, + { "isolate", IL_ICMP_UNREACH_ISOLATED, -1 }, + { "net-prohib", IL_ICMP_UNREACH_NET_PROHIB, -1 }, + { "host-prohib", IL_ICMP_UNREACH_HOST_PROHIB, -1 }, + { "net-tos", IL_ICMP_UNREACH_TOSNET, -1 }, + { "host-tos", IL_ICMP_UNREACH_TOSHOST, -1 }, + { "filter-prohib", IL_ICMP_UNREACH_FILTER_PROHIB, -1 }, + { "host-preced", IL_ICMP_UNREACH_HOST_PRECEDENCE, -1 }, + { "cutoff-preced", IL_ICMP_UNREACH_PRECEDENCE_CUTOFF, -1 }, + { "net-redir", IL_ICMP_REDIRECT_NET, -1 }, + { "host-redir", IL_ICMP_REDIRECT_HOST, -1 }, + { "tos-net-redir", IL_ICMP_REDIRECT_TOSNET, -1 }, + { "tos-host-redir", IL_ICMP_REDIRECT_TOSHOST, -1 }, + { "intrans", IL_ICMP_TIMXCEED_INTRANS, -1 }, + { "reass", IL_ICMP_TIMXCEED_REASS, -1 }, + { "optabsent", IL_ICMP_PARAMPROB_OPTABSENT, -1 }, + { "otime", IL_ICMP_OTIME, -1 }, + { "rtime", IL_ICMP_RTIME, -1 }, + { "ttime", IL_ICMP_TTIME, -1 }, + { "icmpseq", IL_ICMP_SEQ, -1 }, + { "icmpid", IL_ICMP_SEQ, -1 }, + { ".", IL_DOT, -1 }, + { NULL, 0, 0 } +}; +%} +white [ \t\r]+ %% -[ \t\r] ; +{white} ; \n { lineNum++; swallow(); } -interface | -iface { return next_state(IL_INTERFACE, -1); } -name | -ifname { return next_state(IL_IFNAME, IL_TOKEN); } -router { return next_state(IL_DEFROUTER, IL_TOKEN); } -mtu { return next_state(IL_MTU, IL_NUMBER); } -eaddr { return next_state(IL_EADDR, IL_TOKEN); } -v4addr { return next_state(IL_V4ADDR, IL_TOKEN); } -ipv4 { return next_state(IL_IPV4, -1); } -v { return next_state(IL_V4V, IL_TOKEN); } -proto { return next_state(IL_V4PROTO, IL_TOKEN); } -hl { return next_state(IL_V4HL, IL_TOKEN); } -id { return next_state(IL_V4ID, IL_TOKEN); } -ttl { return next_state(IL_V4TTL, IL_TOKEN); } -tos { return next_state(IL_V4TOS, IL_TOKEN); } -src { return next_state(IL_V4SRC, IL_TOKEN); } -dst { return next_state(IL_V4DST, IL_TOKEN); } -opt { return next_state(IL_OPT, -1); } -len { return next_state(IL_LEN, IL_TOKEN); } -off { return next_state(IL_OFF, IL_TOKEN); } -sum { return next_state(IL_SUM, IL_TOKEN); } -tcp { return next_state(IL_TCP, -1); } -sport { return next_state(IL_SPORT, IL_TOKEN); } -dport { return next_state(IL_DPORT, IL_TOKEN); } -seq { return next_state(IL_TCPSEQ, IL_TOKEN); } -ack { return next_state(IL_TCPACK, IL_TOKEN); } -flags { return next_state(IL_TCPFL, IL_TOKEN); } -urp { return next_state(IL_TCPURP, IL_TOKEN); } -win { return next_state(IL_TCPWIN, IL_TOKEN); } -udp { return next_state(IL_UDP, -1); } -send { return next_state(IL_SEND, -1); } -via { return next_state(IL_VIA, IL_TOKEN); } -arp { return next_state(IL_ARP, -1); } -data { return next_state(IL_DATA, -1); } -value { return next_state(IL_DVALUE, IL_TOKEN); } -file { return next_state(IL_DFILE, IL_TOKEN); } -nop { return next_state(IL_IPO_NOP, -1); } -eol { return next_state(IL_IPO_EOL, -1); } -rr { return next_state(IL_IPO_RR, -1); } -zsu { return next_state(IL_IPO_ZSU, -1); } -mtup { return next_state(IL_IPO_MTUP, -1); } -mtur { return next_state(IL_IPO_MTUR, -1); } -encode { return next_state(IL_IPO_ENCODE, -1); } -ts { return next_state(IL_IPO_TS, -1); } -tr { return next_state(IL_IPO_TR, -1); } -sec { return next_state(IL_IPO_SEC, -1); } -secclass { return next_state(IL_IPO_SECCLASS, IL_TOKEN); } -lsrr { return next_state(IL_IPO_LSRR, -1); } -esec { return next_state(IL_IPO_ESEC, -1); } -cipso { return next_state(IL_IPO_CIPSO, -1); } -satid { return next_state(IL_IPO_SATID, -1); } -ssrr { return next_state(IL_IPO_SSRR, -1); } -addext { return next_state(IL_IPO_ADDEXT, -1); } -visa { return next_state(IL_IPO_VISA, -1); } -imitd { return next_state(IL_IPO_IMITD, -1); } -eip { return next_state(IL_IPO_EIP, -1); } -finn { return next_state(IL_IPO_FINN, -1); } -mss { return next_state(IL_TCPO_MSS, IL_TOKEN); } -wscale { return next_state(IL_TCPO_MSS, IL_TOKEN); } -reserv-4 { return next_state(IL_IPS_RESERV4, -1); } -topsecret { return next_state(IL_IPS_TOPSECRET, -1); } -secret { return next_state(IL_IPS_SECRET, -1); } -reserv-3 { return next_state(IL_IPS_RESERV3, -1); } -confid { return next_state(IL_IPS_CONFID, -1); } -unclass { return next_state(IL_IPS_UNCLASS, -1); } -reserv-2 { return next_state(IL_IPS_RESERV2, -1); } -reserv-1 { return next_state(IL_IPS_RESERV1, -1); } -icmp { return next_state(IL_ICMP, -1); } -type { return next_state(IL_ICMPTYPE, -1); } -code { return next_state(IL_ICMPCODE, -1); } -echorep { return next_state(IL_ICMP_ECHOREPLY, -1); } -unreach { return next_state(IL_ICMP_UNREACH, -1); } -squench { return next_state(IL_ICMP_SOURCEQUENCH, -1); } -redir { return next_state(IL_ICMP_REDIRECT, -1); } -echo { return next_state(IL_ICMP_ECHO, -1); } -routerad { return next_state(IL_ICMP_ROUTERADVERT, -1); } -routersol { return next_state(IL_ICMP_ROUTERSOLICIT, -1); } -timex { return next_state(IL_ICMP_TIMXCEED, -1); } -paramprob { return next_state(IL_ICMP_PARAMPROB, -1); } -timest { return next_state(IL_ICMP_TSTAMP, -1); } -timestrep { return next_state(IL_ICMP_TSTAMPREPLY, -1); } -inforeq { return next_state(IL_ICMP_IREQ, -1); } -inforep { return next_state(IL_ICMP_IREQREPLY, -1); } -maskreq { return next_state(IL_ICMP_MASKREQ, -1); } -maskrep { return next_state(IL_ICMP_MASKREPLY, -1); } -net-unr { return next_state(IL_ICMP_UNREACH_NET, -1); } -host-unr { return next_state(IL_ICMP_UNREACH_HOST, -1); } -proto-unr { return next_state(IL_ICMP_UNREACH_PROTOCOL, -1); } -port-unr { return next_state(IL_ICMP_UNREACH_PORT, -1); } -needfrag { return next_state(IL_ICMP_UNREACH_NEEDFRAG, -1); } -srcfail { return next_state(IL_ICMP_UNREACH_SRCFAIL, -1); } -net-unk { return next_state(IL_ICMP_UNREACH_NET_UNKNOWN, -1); } -host-unk { return next_state(IL_ICMP_UNREACH_HOST_UNKNOWN, -1); } -isolate { return next_state(IL_ICMP_UNREACH_ISOLATED, -1); } -net-prohib { return next_state(IL_ICMP_UNREACH_NET_PROHIB, -1); } -host-prohib { return next_state(IL_ICMP_UNREACH_HOST_PROHIB, -1); } -net-tos { return next_state(IL_ICMP_UNREACH_TOSNET, -1); } -host-tos { return next_state(IL_ICMP_UNREACH_TOSHOST, -1); } -filter-prohib { return next_state(IL_ICMP_UNREACH_FILTER_PROHIB, -1); } -host-preced { return next_state(IL_ICMP_UNREACH_HOST_PRECEDENCE, -1); } -cutoff-preced { return next_state(IL_ICMP_UNREACH_PRECEDENCE_CUTOFF, -1); } -net-redir { return next_state(IL_ICMP_REDIRECT_NET, -1); } -host-redir { return next_state(IL_ICMP_REDIRECT_HOST, -1); } -tos-net-redir { return next_state(IL_ICMP_REDIRECT_TOSNET, -1); } -tos-host-redir { return next_state(IL_ICMP_REDIRECT_TOSHOST, -1); } -intrans { return next_state(IL_ICMP_TIMXCEED_INTRANS, -1); } -reass { return next_state(IL_ICMP_TIMXCEED_REASS, -1); } -optabsent { return next_state(IL_ICMP_PARAMPROB_OPTABSENT, -1); } -otime { return next_state(IL_ICMP_OTIME, -1); } -rtime { return next_state(IL_ICMP_RTIME, -1); } -ttime { return next_state(IL_ICMP_TTIME, -1); } -icmpseq { return next_state(IL_ICMP_SEQ, -1); } -icmpid { return next_state(IL_ICMP_SEQ, -1); } -\377 { return 0; } /* EOF */ \{ { push_proto(); return next_item('{'); } \} { pop_proto(); return next_item('}'); } -\. { return next_item(IL_DOT); } ; { return next_item(';'); } [0-9]+ { return next_item(IL_NUMBER); } [0-9a-fA-F] { return next_item(IL_HEXDIGIT); } : { return next_item(IL_COLON); } #[^\n]* { return next_item(IL_COMMENT); } -[^ {}\n\t;]* { return next_item(IL_TOKEN); } +[^ \{\}\n\t;:{}]* { return next_item(IL_TOKEN); } \"[^\"]*\" { return next_item(IL_TOKEN); } %% void yyerror(msg) @@ -193,14 +199,14 @@ void push_proto() prstack = (int *)malloc(sizeof(int)); else prstack = (int *)realloc((char *)prstack, numpr * sizeof(int)); - prstack[numpr - 1] = oldproto; + prstack[numpr - 1] = oldipproto; } void pop_proto() { numpr--; - proto = prstack[numpr]; + ipproto = prstack[numpr]; if (!numpr) { free(prstack); prstack = NULL; @@ -221,10 +227,21 @@ int save_token() int next_item(nstate) int nstate; { + struct wordtab *wt; + + if (opts & OPT_DEBUG) + printf("text=[%s] id=%d next=%d\n", yytext, nstate, next); if (next == IL_TOKEN) { next = -1; return save_token(); } + token++; + + for (wt = words; wt->word; wt++) + if (!strcasecmp(wt->word, yytext)) + return next_state(wt->state, wt->next); + if (opts & OPT_DEBUG) + printf("unknown keyword=[%s]\n", yytext); next = -1; if (nstate == IL_NUMBER) yylval.num = atoi(yytext); @@ -236,13 +253,6 @@ int nstate; int next_state(nstate, fornext) int nstate, fornext; { - token++; - - if (next == IL_TOKEN) { - next = -1; - return save_token(); - } - next = fornext; switch (nstate) @@ -254,45 +264,45 @@ int nstate, fornext; case IL_DATA : case IL_INTERFACE : case IL_ARP : - oldproto = proto; - proto = nstate; + oldipproto = ipproto; + ipproto = nstate; break; case IL_SUM : - if (proto == IL_IPV4) + if (ipproto == IL_IPV4) nstate = IL_V4SUM; - else if (proto == IL_TCP) + else if (ipproto == IL_TCP) nstate = IL_TCPSUM; - else if (proto == IL_UDP) + else if (ipproto == IL_UDP) nstate = IL_UDPSUM; break; case IL_OPT : - if (proto == IL_IPV4) + if (ipproto == IL_IPV4) nstate = IL_V4OPT; - else if (proto == IL_TCP) + else if (ipproto == IL_TCP) nstate = IL_TCPOPT; break; case IL_IPO_NOP : - if (proto == IL_TCP) + if (ipproto == IL_TCP) nstate = IL_TCPO_NOP; break; case IL_IPO_EOL : - if (proto == IL_TCP) + if (ipproto == IL_TCP) nstate = IL_TCPO_EOL; break; case IL_IPO_TS : - if (proto == IL_TCP) + if (ipproto == IL_TCP) nstate = IL_TCPO_TS; break; case IL_OFF : - if (proto == IL_IPV4) + if (ipproto == IL_IPV4) nstate = IL_V4OFF; - else if (proto == IL_TCP) + else if (ipproto == IL_TCP) nstate = IL_TCPOFF; break; case IL_LEN : - if (proto == IL_IPV4) + if (ipproto == IL_IPV4) nstate = IL_V4LEN; - else if (proto == IL_UDP) + else if (ipproto == IL_UDP) nstate = IL_UDPLEN; break; } @@ -302,7 +312,9 @@ int nstate, fornext; void swallow() { - int c = input(); + int c; + + c = input(); if (c == '#') { while ((c != '\n') && (c != EOF)) diff --git a/usr.sbin/ipsend/ipsend/iplang_y.y b/usr.sbin/ipsend/ipsend/iplang_y.y index ace441a6366..e57c912b158 100644 --- a/usr.sbin/ipsend/ipsend/iplang_y.y +++ b/usr.sbin/ipsend/ipsend/iplang_y.y @@ -1,15 +1,16 @@ %{ -/* $OpenBSD: iplang_y.y,v 1.1 1998/01/26 04:17:02 dgregor Exp $ */ +/* $OpenBSD: iplang_y.y,v 1.2 2001/01/17 06:01:26 fgsch Exp $ */ + /* - * Copyright (C) 1997 by Darren Reed. + * Copyright (C) 1997-1998 by Darren Reed. * * Redistribution and use in source and binary forms are permitted * provided that this notice is preserved and due credit is given * to the original author and the contributors. * - * $Id: iplang_y.y,v 1.1 1998/01/26 04:17:02 dgregor Exp $ + * $IPFilter: iplang_y.y,v 2.2.2.1 2000/08/05 14:43:39 darrenr Exp $ */ - + #include <stdio.h> #include <string.h> #include <fcntl.h> @@ -45,11 +46,14 @@ #include <resolv.h> #include <ctype.h> #include "ipsend.h" -#include "ip_fil_compat.h" +#include "ip_compat.h" #include "ipf.h" #include "iplang.h" +#if !defined(__NetBSD__) && (!defined(__FreeBSD_version) && \ + __FreeBSD_version < 400020) extern struct ether_addr *ether_aton __P((char *)); +#endif extern int opts; extern struct ipopt_names ionames[]; @@ -163,6 +167,7 @@ void end_tcp __P((void)); void end_data __P((void)); void yyerror __P((char *)); void iplang __P((FILE *)); +int arp_getipv4 __P((char *, char *)); int yyparse __P((void)); %} %union { @@ -346,7 +351,7 @@ tcpopts: tcpopt: IL_TCPO_NOP ';' { set_tcpopt(IL_TCPO_NOP, NULL); } | IL_TCPO_EOL ';' { set_tcpopt(IL_TCPO_EOL, NULL); } | IL_TCPO_MSS optoken { set_tcpopt(IL_TCPO_MSS,&$2);} - | IL_TCPO_WSCALE optoken { set_tcpopt(IL_TCPO_MSS,&$2);} + | IL_TCPO_WSCALE optoken { set_tcpopt(IL_TCPO_WSCALE,&$2);} | IL_TCPO_TS optoken { set_tcpopt(IL_TCPO_TS, &$2);} ; @@ -780,6 +785,8 @@ char **arg; *t++ = (u_char)(val & 0xff); todo = 0; } + if (todo) + continue; } if (quote) { if (isdigit(c)) { @@ -808,8 +815,8 @@ char **arg; *t++ = '\t'; break; } - quote = 0; } + quote = 0; continue; } @@ -818,6 +825,8 @@ char **arg; else *t++ = c; } + if (todo) + *t++ = (u_char)(val & 0xff); if (quote) *t++ = '\\'; len = t - (u_char *)canip->ah_data; @@ -911,7 +920,7 @@ char **arg; void set_ipv4off(arg) char **arg; { - ip->ip_off = strtol(*arg, NULL, 0); + ip->ip_off = htons(strtol(*arg, NULL, 0)); free(*arg); *arg = NULL; } @@ -962,7 +971,7 @@ char **arg; void set_ipv4id(arg) char **arg; { - ip->ip_id = strtol(*arg, NULL, 0); + ip->ip_id = htons(strtol(*arg, NULL, 0)); free(*arg); *arg = NULL; } @@ -1000,7 +1009,7 @@ void new_tcpheader() ip->ip_p = IPPROTO_TCP; tcp = (tcphdr_t *)new_header(IPPROTO_TCP); - tcp->th_win = 4096; + tcp->th_win = htons(4096); tcp->th_off = sizeof(*tcp) >> 2; } @@ -1048,7 +1057,7 @@ char **arg; void set_tcpseq(arg) char **arg; { - tcp->th_seq = strtol(*arg, NULL, 0); + tcp->th_seq = htonl(strtol(*arg, NULL, 0)); free(*arg); *arg = NULL; } @@ -1057,7 +1066,7 @@ char **arg; void set_tcpack(arg) char **arg; { - tcp->th_ack = strtol(*arg, NULL, 0); + tcp->th_ack = htonl(strtol(*arg, NULL, 0)); free(*arg); *arg = NULL; } @@ -1079,7 +1088,7 @@ char **arg; void set_tcpurp(arg) char **arg; { - tcp->th_urp = strtol(*arg, NULL, 0); + tcp->th_urp = htons(strtol(*arg, NULL, 0)); free(*arg); *arg = NULL; } @@ -1088,7 +1097,7 @@ char **arg; void set_tcpwin(arg) char **arg; { - tcp->th_win = strtol(*arg, NULL, 0); + tcp->th_win = htons(strtol(*arg, NULL, 0)); free(*arg); *arg = NULL; } @@ -1299,7 +1308,8 @@ void packet_done() u_char *s = (u_char *)ipbuffer, *t = (u_char *)outline; if (opts & OPT_VERBOSE) { - for (i = ip->ip_len, j = 0; i; i--, j++, s++) { + ip->ip_len = htons(ip->ip_len); + for (i = ntohs(ip->ip_len), j = 0; i; i--, j++, s++) { if (j && !(j & 0xf)) { *t++ = '\n'; *t = '\0'; @@ -1339,6 +1349,7 @@ void packet_done() } fputs(outline, stdout); fflush(stdout); + ip->ip_len = ntohs(ip->ip_len); } prep_packet(); @@ -1424,6 +1435,21 @@ char **arg; } +int arp_getipv4(ip, addr) +char *ip; +char *addr; +{ + arp_t *a; + + for (a = arplist; a; a = a->arp_next) + if (!bcmp(ip, (char *)&a->arp_addr, 4)) { + bcopy((char *)&a->arp_eaddr, addr, 6); + return 0; + } + return -1; +} + + void reset_send() { sending.snd_if = iflist; @@ -1543,35 +1569,35 @@ char **type; void set_icmpid(arg) int arg; { - icmp->icmp_id = arg; + icmp->icmp_id = htons(arg); } void set_icmpseq(arg) int arg; { - icmp->icmp_seq = arg; + icmp->icmp_seq = htons(arg); } void set_icmpotime(arg) int arg; { - icmp->icmp_otime = arg; + icmp->icmp_otime = htonl(arg); } void set_icmprtime(arg) int arg; { - icmp->icmp_rtime = arg; + icmp->icmp_rtime = htonl(arg); } void set_icmpttime(arg) int arg; { - icmp->icmp_ttime = arg; + icmp->icmp_ttime = htonl(arg); } @@ -1579,7 +1605,7 @@ void set_icmpmtu(arg) int arg; { #if BSD >= 199306 - icmp->icmp_nextmtu = arg; + icmp->icmp_nextmtu = htons(arg); #endif } @@ -1731,7 +1757,9 @@ void end_ipv4() aniphdr_t *aip; ip->ip_sum = 0; + ip->ip_len = htons(ip->ip_len); ip->ip_sum = chksum((u_short *)ip, ip->ip_hl << 2); + ip->ip_len = ntohs(ip->ip_len); free_anipheader(); for (aip = aniphead, ip = NULL; aip; aip = aip->ah_next) if (aip->ah_p == IPPROTO_IP) @@ -1762,9 +1790,10 @@ void end_udp() iptmp.ip_p = ip->ip_p; iptmp.ip_src = ip->ip_src; iptmp.ip_dst = ip->ip_dst; - iptmp.ip_len = ip->ip_len - (ip->ip_hl << 2); + iptmp.ip_len = htons(ip->ip_len - (ip->ip_hl << 2)); sum = p_chksum((u_short *)&iptmp, (u_int)sizeof(iptmp)); - udp->uh_sum = c_chksum((u_short *)udp, (u_int)iptmp.ip_len, sum); + udp->uh_ulen = htons(udp->uh_ulen); + udp->uh_sum = c_chksum((u_short *)udp, (u_int)ntohs(iptmp.ip_len), sum); free_anipheader(); for (aip = aniphead, udp = NULL; aip; aip = aip->ah_next) if (aip->ah_p == IPPROTO_UDP) @@ -1782,10 +1811,10 @@ void end_tcp() iptmp.ip_p = ip->ip_p; iptmp.ip_src = ip->ip_src; iptmp.ip_dst = ip->ip_dst; - iptmp.ip_len = ip->ip_len - (ip->ip_hl << 2); + iptmp.ip_len = htons(ip->ip_len - (ip->ip_hl << 2)); sum = p_chksum((u_short *)&iptmp, (u_int)sizeof(iptmp)); tcp->th_sum = 0; - tcp->th_sum = c_chksum((u_short *)tcp, (u_int)iptmp.ip_len, sum); + tcp->th_sum = c_chksum((u_short *)tcp, (u_int)ntohs(iptmp.ip_len), sum); free_anipheader(); for (aip = aniphead, tcp = NULL; aip; aip = aip->ah_next) if (aip->ah_p == IPPROTO_TCP) diff --git a/usr.sbin/ipsend/ipsend/ipsend.c b/usr.sbin/ipsend/ipsend/ipsend.c index a026bb2863e..43eedf46dbe 100644 --- a/usr.sbin/ipsend/ipsend/ipsend.c +++ b/usr.sbin/ipsend/ipsend/ipsend.c @@ -1,6 +1,7 @@ -/* $OpenBSD: ipsend.c,v 1.6 1999/03/22 05:33:30 deraadt Exp $ */ +/* $OpenBSD: ipsend.c,v 1.7 2001/01/17 06:01:26 fgsch Exp $ */ + /* - * ipsend.c (C) 1995-1997 Darren Reed + * ipsend.c (C) 1995-1998 Darren Reed * * This was written to test what size TCP fragments would get through * various TCP/IP packet filters, as used in IP firewalls. In certain @@ -13,13 +14,14 @@ */ #if !defined(lint) static const char sccsid[] = "@(#)ipsend.c 1.5 12/10/95 (C)1995 Darren Reed"; -static const char rcsid[] = "@(#)$Id: ipsend.c,v 1.6 1999/03/22 05:33:30 deraadt Exp $"; +static const char rcsid[] = "@(#)$IPFilter: ipsend.c,v 2.2 1999/12/04 03:37:05 darrenr Exp $"; #endif #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <netdb.h> #include <string.h> +#include <sys/param.h> #include <sys/types.h> #include <sys/time.h> #include <sys/socket.h> @@ -33,7 +35,6 @@ static const char rcsid[] = "@(#)$Id: ipsend.c,v 1.6 1999/03/22 05:33:30 deraadt #ifndef linux #include <netinet/ip_var.h> #endif -#include "ip_fil_compat.h" #include "ipsend.h" #include "ipf.h" @@ -47,13 +48,13 @@ int opts; #ifdef linux char default_device[] = "eth0"; #else -# if defined(sun) || defined(__OpenBSD__) +# ifdef sun char default_device[] = "le0"; # else # ifdef ultrix char default_device[] = "ln0"; # else -# ifdef __bsdi__ +# ifdef __bsdi__ char default_device[] = "ef0"; # else # ifdef __sgi @@ -178,7 +179,8 @@ char **argv; struct in_addr gwip; tcphdr_t *tcp; ip_t *ip; - char *name = argv[0], host[64], *gateway = NULL, *dev = NULL; + char *name = argv[0], host[MAXHOSTNAMELEN + 1]; + char *gateway = NULL, *dev = NULL; char *src = NULL, *dst, *s; int mtu = 1500, olen = 0, c, nonl = 0; @@ -358,8 +360,8 @@ char **argv; tcp = (tcphdr_t *)((char *)(ip + 1) + olen); } - if (ip->ip_p == IPPROTO_TCP && optind < argc) - for (s = argv[optind]; (c = *s); s++) + if (ip->ip_p == IPPROTO_TCP) + for (s = argv[optind]; s && (c = *s); s++) switch(c) { case 'S' : case 's' : diff --git a/usr.sbin/ipsend/ipsend/ipsopt.c b/usr.sbin/ipsend/ipsend/ipsopt.c index 1d598f2757c..f24b5b00cc4 100644 --- a/usr.sbin/ipsend/ipsend/ipsopt.c +++ b/usr.sbin/ipsend/ipsend/ipsopt.c @@ -1,6 +1,7 @@ -/* $OpenBSD: ipsopt.c,v 1.2 1998/01/26 04:17:06 dgregor Exp $ */ +/* $OpenBSD: ipsopt.c,v 1.3 2001/01/17 06:01:27 fgsch Exp $ */ + /* - * Copyright (C) 1995-1997 by Darren Reed. + * Copyright (C) 1995-1998 by Darren Reed. * * Redistribution and use in source and binary forms are permitted * provided that this notice is preserved and due credit is given @@ -8,7 +9,7 @@ */ #if !defined(lint) static const char sccsid[] = "@(#)ipsopt.c 1.2 1/11/96 (C)1995 Darren Reed"; -static const char rcsid[] = "@(#)$Id: ipsopt.c,v 1.2 1998/01/26 04:17:06 dgregor Exp $"; +static const char rcsid[] = "@(#)$IPFilter: ipsopt.c,v 2.1 1999/08/04 17:31:07 darrenr Exp $"; #endif #include <stdio.h> #include <string.h> diff --git a/usr.sbin/ipsend/iptest/iptest.c b/usr.sbin/ipsend/iptest/iptest.c index c5ff22a15b9..43d420848a7 100644 --- a/usr.sbin/ipsend/iptest/iptest.c +++ b/usr.sbin/ipsend/iptest/iptest.c @@ -1,6 +1,8 @@ -/* $OpenBSD: iptest.c,v 1.4 1998/01/26 04:17:10 dgregor Exp $ */ + +/* $OpenBSD: iptest.c,v 1.5 2001/01/17 06:01:27 fgsch Exp $ */ + /* - * ipsend.c (C) 1995-1997 Darren Reed + * ipsend.c (C) 1995-1998 Darren Reed * * This was written to test what size TCP fragments would get through * various TCP/IP packet filters, as used in IP firewalls. In certain @@ -13,13 +15,14 @@ */ #if !defined(lint) static const char sccsid[] = "%W% %G% (C)1995 Darren Reed"; -static const char rcsid[] = "@(#)$Id: iptest.c,v 1.4 1998/01/26 04:17:10 dgregor Exp $"; +static const char rcsid[] = "@(#)$IPFilter: iptest.c,v 2.2 1999/12/04 03:37:05 darrenr Exp $"; #endif #include <stdio.h> #include <netdb.h> #include <unistd.h> #include <stdlib.h> #include <string.h> +#include <sys/param.h> #include <sys/types.h> #include <sys/time.h> #include <sys/socket.h> @@ -98,7 +101,8 @@ char **argv; struct tcpiphdr *ti; struct in_addr gwip; ip_t *ip; - char *name = argv[0], host[64], *gateway = NULL, *dev = NULL; + char *name = argv[0], host[MAXHOSTNAMELEN + 1]; + char *gateway = NULL, *dev = NULL; char *src = NULL, *dst; int mtu = 1500, tests = 0, pointtest = 0, c; @@ -154,6 +158,7 @@ char **argv; if (!src) { gethostname(host, sizeof(host)); + host[sizeof(host) - 1] = '\0'; src = host; } diff --git a/usr.sbin/ipsend/iptest/iptests.c b/usr.sbin/ipsend/iptest/iptests.c index f18e77b2e70..5148ca1a6c3 100644 --- a/usr.sbin/ipsend/iptest/iptests.c +++ b/usr.sbin/ipsend/iptest/iptests.c @@ -1,6 +1,7 @@ -/* $OpenBSD: iptests.c,v 1.2 1998/01/26 04:17:11 dgregor Exp $ */ +/* $OpenBSD: iptests.c,v 1.3 2001/01/17 06:01:27 fgsch Exp $ */ + /* - * Copyright (C) 1993-1997 by Darren Reed. + * Copyright (C) 1993-1998 by Darren Reed. * * Redistribution and use in source and binary forms are permitted * provided that this notice is preserved and due credit is given @@ -8,7 +9,7 @@ */ #if !defined(lint) static const char sccsid[] = "%W% %G% (C)1995 Darren Reed"; -static const char rcsid[] = "@(#)$Id: iptests.c,v 1.2 1998/01/26 04:17:11 dgregor Exp $"; +static const char rcsid[] = "@(#)$IPFilter: iptests.c,v 2.1 1999/08/04 17:31:09 darrenr Exp $"; #endif #include <stdio.h> #include <unistd.h> @@ -17,12 +18,18 @@ static const char rcsid[] = "@(#)$Id: iptests.c,v 1.2 1998/01/26 04:17:11 dgrego #include <sys/types.h> #include <sys/time.h> #include <sys/param.h> +#define _KERNEL +#define KERNEL #if !defined(solaris) && !defined(linux) && !defined(__sgi) -# define _KERNEL -# define KERNEL # include <sys/file.h> -# undef _KERNEL -# undef KERNEL +#else +# ifdef solaris +# include <sys/dditypes.h> +# endif +#endif +#undef _KERNEL +#undef KERNEL +#if !defined(solaris) && !defined(linux) && !defined(__sgi) # include <nlist.h> # include <sys/user.h> # include <sys/proc.h> @@ -99,24 +106,21 @@ int ptest; ip->ip_p = IPPROTO_UDP; ip->ip_sum = 0; u = (udphdr_t *)(ip + 1); - u->uh_sport = 1; - u->uh_dport = 9; + u->uh_sport = htons(1); + u->uh_dport = htons(9); u->uh_sum = 0; - u->uh_ulen = sizeof(*u) + 4; - ip->ip_len = sizeof(*ip) + u->uh_ulen; + u->uh_ulen = htons(sizeof(*u) + 4); + ip->ip_len = sizeof(*ip) + ntohs(u->uh_ulen); len = ip->ip_len; nfd = initdevice(dev, u->uh_sport, 1); - u->uh_sport = htons(u->uh_sport); - u->uh_dport = htons(u->uh_dport); - u->uh_ulen = htons(u->uh_ulen); if (!ptest || (ptest == 1)) { /* * Part1: hl < len */ ip->ip_id = 0; printf("1.1. sending packets with ip_hl < ip_len\n"); - for (i = 0; i < ((sizeof(*ip) + u->uh_ulen) >> 2); i++) { + for (i = 0; i < ((sizeof(*ip) + ntohs(u->uh_ulen)) >> 2); i++) { ip->ip_hl = i >> 2; (void) send_ip(nfd, 1500, ip, gwip, 1); printf("%d\r", i); @@ -132,7 +136,7 @@ int ptest; */ ip->ip_id = 0; printf("1.2. sending packets with ip_hl > ip_len\n"); - for (; i < ((sizeof(*ip) * 2 + u->uh_ulen) >> 2); i++) { + for (; i < ((sizeof(*ip) * 2 + ntohs(u->uh_ulen)) >> 2); i++) { ip->ip_hl = i >> 2; (void) send_ip(nfd, 1500, ip, gwip, 1); printf("%d\r", i); @@ -182,10 +186,8 @@ int ptest; ip->ip_id = 0; ip->ip_v = IPVERSION; i = ip->ip_len + 1; - ip->ip_len = htons(ip->ip_len); - ip->ip_off = htons(ip->ip_off); printf("1.5.0 ip_len < packet size (size++, long packets)\n"); - for (; i < (ntohs(ip->ip_len) * 2); i++) { + for (; i < (ip->ip_len * 2); i++) { ip->ip_id = htons(id++); ip->ip_sum = 0; ip->ip_sum = chksum((u_short *)ip, ip->ip_hl << 2); @@ -198,7 +200,7 @@ int ptest; printf("1.5.1 ip_len < packet size (ip_len-, short packets)\n"); for (i = len; i > 0; i--) { ip->ip_id = htons(id++); - ip->ip_len = htons(i); + ip->ip_len = i; ip->ip_sum = 0; ip->ip_sum = chksum((u_short *)ip, ip->ip_hl << 2); (void) send_ether(nfd, (char *)ip, len, gwip); @@ -217,7 +219,7 @@ int ptest; printf("1.6.0 ip_len > packet size (increase ip_len)\n"); for (i = len + 1; i < (len * 2); i++) { ip->ip_id = htons(id++); - ip->ip_len = htons(i); + ip->ip_len = i; ip->ip_sum = 0; ip->ip_sum = chksum((u_short *)ip, ip->ip_hl << 2); (void) send_ether(nfd, (char *)ip, len, gwip); @@ -226,7 +228,7 @@ int ptest; PAUSE(); } putchar('\n'); - ip->ip_len = htons(len); + ip->ip_len = len; printf("1.6.1 ip_len > packet size (size--, short packets)\n"); for (i = len; i > 0; i--) { ip->ip_id = htons(id++); @@ -289,7 +291,7 @@ int ptest; * about that here. */ ip->ip_p = IPPROTO_ICMP; - ip->ip_off = IP_MF; + ip->ip_off = htons(IP_MF); u->uh_dport = htons(9); ip->ip_id = htons(id++); printf("1.8.1 63k packet + 1k fragment at offset 0x1ffe\n"); @@ -300,14 +302,14 @@ int ptest; ip->ip_len = MIN(768 + 20, mtu - 68); i = 512; for (; i < (63 * 1024 + 768); i += 768) { - ip->ip_off = IP_MF | (i >> 3); + ip->ip_off = htons(IP_MF | (i >> 3)); (void) send_ip(nfd, mtu, ip, gwip, 1); printf("%d\r", i); fflush(stdout); PAUSE(); } ip->ip_len = 896 + 20; - ip->ip_off = (i >> 3); + ip->ip_off = htons(i >> 3); (void) send_ip(nfd, mtu, ip, gwip, 1); printf("%d\r", i); putchar('\n'); @@ -320,7 +322,7 @@ int ptest; * about that here. (Lossage here) */ ip->ip_p = IPPROTO_ICMP; - ip->ip_off = IP_MF; + ip->ip_off = htons(IP_MF); u->uh_dport = htons(9); ip->ip_id = htons(id++); printf("1.8.2 63k packet + 1k fragment at offset 0x1ffe\n"); @@ -334,7 +336,7 @@ int ptest; ip->ip_len = MIN(768 + 20, mtu - 68); i = 512; for (; i < (63 * 1024 + 768); i += 768) { - ip->ip_off = IP_MF | (i >> 3); + ip->ip_off = htons(IP_MF | (i >> 3)); if ((rand() & 0x1f) != 0) { (void) send_ip(nfd, mtu, ip, gwip, 1); printf("%d\r", i); @@ -344,7 +346,7 @@ int ptest; PAUSE(); } ip->ip_len = 896 + 20; - ip->ip_off = (i >> 3); + ip->ip_off = htons(i >> 3); if ((rand() & 0x1f) != 0) { (void) send_ip(nfd, mtu, ip, gwip, 1); printf("%d\r", i); @@ -360,7 +362,7 @@ int ptest; * about that here. */ ip->ip_p = IPPROTO_ICMP; - ip->ip_off = IP_MF; + ip->ip_off = htons(IP_MF); u->uh_dport = htons(9); ip->ip_id = htons(id++); printf("1.8.3 33k packet\n"); @@ -371,14 +373,14 @@ int ptest; ip->ip_len = MIN(768 + 20, mtu - 68); i = 512; for (; i < (32 * 1024 + 768); i += 768) { - ip->ip_off = IP_MF | (i >> 3); + ip->ip_off = htons(IP_MF | (i >> 3)); (void) send_ip(nfd, mtu, ip, gwip, 1); printf("%d\r", i); fflush(stdout); PAUSE(); } ip->ip_len = 896 + 20; - ip->ip_off = (i >> 3); + ip->ip_off = htons(i >> 3); (void) send_ip(nfd, mtu, ip, gwip, 1); printf("%d\r", i); putchar('\n'); @@ -392,7 +394,7 @@ int ptest; * Part9: off & 0x8000 == 0x8000 */ ip->ip_id = 0; - ip->ip_off = 0x8000; + ip->ip_off = htons(0x8000); printf("1.9. ip_off & 0x8000 == 0x8000\n"); (void) send_ip(nfd, mtu, ip, gwip, 1); fflush(stdout); @@ -441,7 +443,7 @@ int ptest; u_char *s; s = (u_char *)(ip + 1); - nfd = initdevice(dev, 1, 1); + nfd = initdevice(dev, htons(1), 1); ip->ip_hl = 6; ip->ip_len = ip->ip_hl << 2; @@ -540,7 +542,7 @@ int ptest; ip->ip_sum = 0; ip->ip_len = sizeof(*ip) + sizeof(*icp); icp = (struct icmp *)((char *)ip + (ip->ip_hl << 2)); - nfd = initdevice(dev, 1, 1); + nfd = initdevice(dev, htons(1), 1); if (!ptest || (ptest == 1)) { /* @@ -732,20 +734,20 @@ int ptest; ip->ip_p = IPPROTO_UDP; ip->ip_sum = 0; u = (udphdr_t *)((char *)ip + (ip->ip_hl << 2)); - u->uh_sport = 1; - u->uh_dport = 1; - u->uh_ulen = sizeof(*u) + 4; + u->uh_sport = htons(1); + u->uh_dport = htons(1); + u->uh_ulen = htons(sizeof(*u) + 4); nfd = initdevice(dev, u->uh_sport, 1); if (!ptest || (ptest == 1)) { /* * Test 1. ulen > packet */ - u->uh_ulen = sizeof(*u) + 4; - ip->ip_len = (ip->ip_hl << 2) + u->uh_ulen; + u->uh_ulen = htons(sizeof(*u) + 4); + ip->ip_len = (ip->ip_hl << 2) + ntohs(u->uh_ulen); printf("4.1 UDP uh_ulen > packet size - short packets\n"); - for (i = u->uh_ulen * 2; i > sizeof(*u) + 4; i--) { - u->uh_ulen = i; + for (i = ntohs(u->uh_ulen) * 2; i > sizeof(*u) + 4; i--) { + u->uh_ulen = htons(i); (void) send_udp(nfd, 1500, ip, gwip); printf("%d\r", i); fflush(stdout); @@ -758,10 +760,10 @@ int ptest; /* * Test 2. ulen < packet */ - u->uh_ulen = sizeof(*u) + 4; - ip->ip_len = (ip->ip_hl << 2) + u->uh_ulen; + u->uh_ulen = htons(sizeof(*u) + 4); + ip->ip_len = (ip->ip_hl << 2) + ntohs(u->uh_ulen); printf("4.2 UDP uh_ulen < packet size - short packets\n"); - for (i = u->uh_ulen * 2; i > sizeof(*u) + 4; i--) { + for (i = ntohs(u->uh_ulen) * 2; i > sizeof(*u) + 4; i--) { ip->ip_len = i; (void) send_udp(nfd, 1500, ip, gwip); printf("%d\r", i); @@ -777,7 +779,7 @@ int ptest; * sport = 32768, sport = 65535 */ u->uh_ulen = sizeof(*u) + 4; - ip->ip_len = (ip->ip_hl << 2) + u->uh_ulen; + ip->ip_len = (ip->ip_hl << 2) + ntohs(u->uh_ulen); printf("4.3.1 UDP sport = 0\n"); u->uh_sport = 0; (void) send_udp(nfd, 1500, ip, gwip); @@ -785,26 +787,26 @@ int ptest; fflush(stdout); PAUSE(); printf("4.3.2 UDP sport = 1\n"); - u->uh_sport = 1; + u->uh_sport = htons(1); (void) send_udp(nfd, 1500, ip, gwip); printf("1\n"); fflush(stdout); PAUSE(); printf("4.3.3 UDP sport = 32767\n"); - u->uh_sport = 32767; + u->uh_sport = htons(32767); (void) send_udp(nfd, 1500, ip, gwip); printf("32767\n"); fflush(stdout); PAUSE(); printf("4.3.4 UDP sport = 32768\n"); - u->uh_sport = 32768; + u->uh_sport = htons(32768); (void) send_udp(nfd, 1500, ip, gwip); printf("32768\n"); putchar('\n'); fflush(stdout); PAUSE(); printf("4.3.5 UDP sport = 65535\n"); - u->uh_sport = 65535; + u->uh_sport = htons(65535); (void) send_udp(nfd, 1500, ip, gwip); printf("65535\n"); fflush(stdout); @@ -816,9 +818,9 @@ int ptest; * Test 4: dport = 0, dport = 1, dport = 32767 * dport = 32768, dport = 65535 */ - u->uh_ulen = sizeof(*u) + 4; - u->uh_sport = 1; - ip->ip_len = (ip->ip_hl << 2) + u->uh_ulen; + u->uh_ulen = ntohs(sizeof(*u) + 4); + u->uh_sport = htons(1); + ip->ip_len = (ip->ip_hl << 2) + ntohs(u->uh_ulen); printf("4.4.1 UDP dport = 0\n"); u->uh_dport = 0; (void) send_udp(nfd, 1500, ip, gwip); @@ -826,25 +828,25 @@ int ptest; fflush(stdout); PAUSE(); printf("4.4.2 UDP dport = 1\n"); - u->uh_dport = 1; + u->uh_dport = htons(1); (void) send_udp(nfd, 1500, ip, gwip); printf("1\n"); fflush(stdout); PAUSE(); printf("4.4.3 UDP dport = 32767\n"); - u->uh_dport = 32767; + u->uh_dport = htons(32767); (void) send_udp(nfd, 1500, ip, gwip); printf("32767\n"); fflush(stdout); PAUSE(); printf("4.4.4 UDP dport = 32768\n"); - u->uh_dport = 32768; + u->uh_dport = htons(32768); (void) send_udp(nfd, 1500, ip, gwip); printf("32768\n"); fflush(stdout); PAUSE(); printf("4.4.5 UDP dport = 65535\n"); - u->uh_dport = 65535; + u->uh_dport = htons(65535); (void) send_udp(nfd, 1500, ip, gwip); printf("65535\n"); fflush(stdout); @@ -857,7 +859,7 @@ int ptest; * sizeof(ip_t) */ printf("4.5 UDP 20 <= MTU <= 32\n"); - for (i = sizeof(*ip); i <= u->uh_ulen; i++) { + for (i = sizeof(*ip); i <= ntohs(u->uh_ulen); i++) { (void) send_udp(nfd, i, ip, gwip); printf("%d\r", i); fflush(stdout); @@ -886,12 +888,12 @@ int ptest; t->th_x2 = 0; #endif t->th_off = 0; - t->th_sport = 1; - t->th_dport = 1; - t->th_win = 4096; + t->th_sport = htons(1); + t->th_dport = htons(1); + t->th_win = htons(4096); t->th_urp = 0; t->th_sum = 0; - t->th_seq = 1; + t->th_seq = htonl(1); t->th_ack = 0; ip->ip_len = sizeof(ip_t) + sizeof(tcphdr_t); nfd = initdevice(dev, t->th_sport, 1); @@ -920,37 +922,37 @@ int ptest; * seq = 0xa000000, seq = 0xffffffff */ printf("5.2.1 TCP seq = 0\n"); - t->th_seq = 0; + t->th_seq = htonl(0); (void) send_tcp(nfd, mtu, ip, gwip); fflush(stdout); PAUSE(); printf("5.2.2 TCP seq = 1\n"); - t->th_seq = 1; + t->th_seq = htonl(1); (void) send_tcp(nfd, mtu, ip, gwip); fflush(stdout); PAUSE(); printf("5.2.3 TCP seq = 0x7fffffff\n"); - t->th_seq = 0x7fffffff; + t->th_seq = htonl(0x7fffffff); (void) send_tcp(nfd, mtu, ip, gwip); fflush(stdout); PAUSE(); printf("5.2.4 TCP seq = 0x80000000\n"); - t->th_seq = 0x80000000; + t->th_seq = htonl(0x80000000); (void) send_tcp(nfd, mtu, ip, gwip); fflush(stdout); PAUSE(); printf("5.2.5 TCP seq = 0xc0000000\n"); - t->th_seq = 0xc0000000; + t->th_seq = htonl(0xc0000000); (void) send_tcp(nfd, mtu, ip, gwip); fflush(stdout); PAUSE(); printf("5.2.6 TCP seq = 0xffffffff\n"); - t->th_seq = 0xffffffff; + t->th_seq = htonl(0xffffffff); (void) send_tcp(nfd, mtu, ip, gwip); fflush(stdout); PAUSE(); @@ -969,31 +971,31 @@ int ptest; PAUSE(); printf("5.3.2 TCP ack = 1\n"); - t->th_ack = 1; + t->th_ack = htonl(1); (void) send_tcp(nfd, mtu, ip, gwip); fflush(stdout); PAUSE(); printf("5.3.3 TCP ack = 0x7fffffff\n"); - t->th_ack = 0x7fffffff; + t->th_ack = htonl(0x7fffffff); (void) send_tcp(nfd, mtu, ip, gwip); fflush(stdout); PAUSE(); printf("5.3.4 TCP ack = 0x80000000\n"); - t->th_ack = 0x80000000; + t->th_ack = htonl(0x80000000); (void) send_tcp(nfd, mtu, ip, gwip); fflush(stdout); PAUSE(); printf("5.3.5 TCP ack = 0xc0000000\n"); - t->th_ack = 0xc0000000; + t->th_ack = htonl(0xc0000000); (void) send_tcp(nfd, mtu, ip, gwip); fflush(stdout); PAUSE(); printf("5.3.6 TCP ack = 0xffffffff\n"); - t->th_ack = 0xffffffff; + t->th_ack = htonl(0xffffffff); (void) send_tcp(nfd, mtu, ip, gwip); fflush(stdout); PAUSE(); @@ -1005,19 +1007,19 @@ int ptest; * Test 4: win = 0, win = 32768, win = 65535 */ printf("5.4.1 TCP win = 0\n"); - t->th_seq = 0; + t->th_seq = htonl(0); (void) send_tcp(nfd, mtu, ip, gwip); fflush(stdout); PAUSE(); printf("5.4.2 TCP win = 32768\n"); - t->th_seq = 0x7fff; + t->th_seq = htonl(0x7fff); (void) send_tcp(nfd, mtu, ip, gwip); fflush(stdout); PAUSE(); printf("5.4.3 TCP win = 65535\n"); - t->th_win = 0xffff; + t->th_win = htons(0xffff); (void) send_tcp(nfd, mtu, ip, gwip); fflush(stdout); PAUSE(); @@ -1062,7 +1064,7 @@ int ptest; } KMCPY(&tcb, tcbp, sizeof(tcb)); ti.ti_win = tcb.rcv_adv; - ti.ti_seq = tcb.snd_nxt - 1; + ti.ti_seq = htonl(tcb.snd_nxt - 1); ti.ti_ack = tcb.rcv_nxt; if (!ptest || (ptest == 5)) { @@ -1076,7 +1078,7 @@ int ptest; (void) send_tcp(nfd, mtu, ip, gwip); PAUSE(); - t->th_seq = tcb.snd_nxt; + t->th_seq = htonl(tcb.snd_nxt); ip->ip_len = sizeof(ip_t) + sizeof(tcphdr_t) + 1; t->th_urp = htons(0x7fff); (void) send_tcp(nfd, mtu, ip, gwip); @@ -1087,7 +1089,7 @@ int ptest; t->th_urp = htons(0xffff); (void) send_tcp(nfd, mtu, ip, gwip); PAUSE(); - t->th_urp = htons(0); + t->th_urp = 0; t->th_flags &= ~TH_URG; ip->ip_len = sizeof(ip_t) + sizeof(tcphdr_t); } @@ -1113,8 +1115,8 @@ int ptest; } skip_five_and_six: #endif - t->th_seq = 1; - t->th_ack = 1; + t->th_seq = htonl(1); + t->th_ack = htonl(1); t->th_off = 0; if (!ptest || (ptest == 7)) { @@ -1130,32 +1132,32 @@ skip_five_and_six: PAUSE(); printf("5.7.2 TCP sport = 1\n"); - t->th_sport = 1; + t->th_sport = htons(1); (void) send_tcp(nfd, mtu, ip, gwip); fflush(stdout); PAUSE(); printf("5.7.3 TCP sport = 32767\n"); - t->th_sport = 32767; + t->th_sport = htons(32767); (void) send_tcp(nfd, mtu, ip, gwip); fflush(stdout); PAUSE(); printf("5.7.4 TCP sport = 32768\n"); - t->th_sport = 32768; + t->th_sport = htons(32768); (void) send_tcp(nfd, mtu, ip, gwip); fflush(stdout); PAUSE(); printf("5.7.5 TCP sport = 65535\n"); - t->th_sport = 65535; + t->th_sport = htons(65535); (void) send_tcp(nfd, mtu, ip, gwip); fflush(stdout); PAUSE(); } if (!ptest || (ptest == 8)) { - t->th_sport = 1; + t->th_sport = htons(1); t->th_flags = TH_SYN; /* * Test 8: dport = 0, dport = 1, dport = 32767 @@ -1168,25 +1170,25 @@ skip_five_and_six: PAUSE(); printf("5.8.2 TCP dport = 1\n"); - t->th_dport = 1; + t->th_dport = htons(1); (void) send_tcp(nfd, mtu, ip, gwip); fflush(stdout); PAUSE(); printf("5.8.3 TCP dport = 32767\n"); - t->th_dport = 32767; + t->th_dport = htons(32767); (void) send_tcp(nfd, mtu, ip, gwip); fflush(stdout); PAUSE(); printf("5.8.4 TCP dport = 32768\n"); - t->th_dport = 32768; + t->th_dport = htons(32768); (void) send_tcp(nfd, mtu, ip, gwip); fflush(stdout); PAUSE(); printf("5.8.5 TCP dport = 65535\n"); - t->th_dport = 65535; + t->th_dport = htons(65535); (void) send_tcp(nfd, mtu, ip, gwip); fflush(stdout); PAUSE(); @@ -1230,14 +1232,12 @@ int ptest; ip->ip_p = IPPROTO_UDP; ip->ip_sum = 0; u = (udphdr_t *)(ip + 1); - u->uh_sport = 1; - u->uh_dport = 9; + u->uh_sport = htons(1); + u->uh_dport = htons(9); u->uh_sum = 0; nfd = initdevice(dev, u->uh_sport, 1); - u->uh_sport = htons(u->uh_sport); - u->uh_dport = htons(u->uh_dport); - u->uh_ulen = 7168; + u->uh_ulen = htons(7168); printf("6. Exhaustive mbuf test.\n"); printf(" Send 7k packet in 768 & 128 byte fragments, 128 times.\n"); @@ -1248,7 +1248,7 @@ int ptest; */ ip->ip_len = sizeof(*ip) + 768 + sizeof(*u); ip->ip_hl = sizeof(*ip) >> 2; - ip->ip_off = IP_MF; + ip->ip_off = htons(IP_MF); (void) send_ip(nfd, 1500, ip, gwip, 1); printf("%d %d\r", i, 0); fflush(stdout); @@ -1257,7 +1257,7 @@ int ptest; * And again using 128 byte chunks. */ ip->ip_len = sizeof(*ip) + 128 + sizeof(*u); - ip->ip_off = IP_MF; + ip->ip_off = htons(IP_MF); (void) send_ip(nfd, 1500, ip, gwip, 1); printf("%d %d\r", i, 0); fflush(stdout); @@ -1265,7 +1265,7 @@ int ptest; for (j = 768; j < 3584; j += 768) { ip->ip_len = sizeof(*ip) + 768; - ip->ip_off = IP_MF|(j>>3); + ip->ip_off = htons(IP_MF|(j>>3)); (void) send_ip(nfd, 1500, ip, gwip, 1); printf("%d %d\r", i, j); fflush(stdout); @@ -1273,7 +1273,7 @@ int ptest; ip->ip_len = sizeof(*ip) + 128; for (k = j - 768; k < j; k += 128) { - ip->ip_off = IP_MF|(k>>3); + ip->ip_off = htons(IP_MF|(k>>3)); (void) send_ip(nfd, 1500, ip, gwip, 1); printf("%d %d\r", i, k); fflush(stdout); @@ -1327,7 +1327,7 @@ int ptest; for (s = (u_char *)pip, j = 0; j < sizeof(tbuf); j++, s++) *s = (rand() >> 13) & 0xff; pip->ip_v = IPVERSION; - pip->ip_off &= 0xc000; + pip->ip_off &= htons(0xc000); bcopy((char *)&ip->ip_dst, (char *)&pip->ip_dst, sizeof(struct in_addr)); pip->ip_sum = 0; |