diff options
| author | Peter Wemm <peter@FreeBSD.org> | 1997-11-16 04:52:19 +0000 |
|---|---|---|
| committer | Peter Wemm <peter@FreeBSD.org> | 1997-11-16 04:52:19 +0000 |
| commit | af5dd3181a44c8c60d82fe2f4f8ff9ff81d98e26 (patch) | |
| tree | 1abde20e1d717a2bf3509de2189cbe7fa3c9f91e /contrib/ipfilter/opt.c | |
| parent | acdb2ce24a62f8b955af761b992ae020cc2303ef (diff) | |
Notes
Diffstat (limited to 'contrib/ipfilter/opt.c')
| -rw-r--r-- | contrib/ipfilter/opt.c | 107 |
1 files changed, 75 insertions, 32 deletions
diff --git a/contrib/ipfilter/opt.c b/contrib/ipfilter/opt.c index e52f7bc3674d7..4ed646b983100 100644 --- a/contrib/ipfilter/opt.c +++ b/contrib/ipfilter/opt.c @@ -1,5 +1,5 @@ /* - * (C)opyright 1993,1994,1995 by Darren Reed. + * Copyright (C) 1993-1997 by Darren Reed. * * Redistribution and use in source and binary forms are permitted * provided that this notice is preserved and due credit is given @@ -7,22 +7,27 @@ */ #include <stdio.h> #include <string.h> +#include <stdlib.h> #include <sys/types.h> #include <sys/time.h> #include <sys/socket.h> #include <netinet/in.h> #include <netinet/in_systm.h> #include <netinet/ip.h> +#ifndef linux #include <netinet/ip_var.h> +#endif #include <netinet/tcp.h> -#include <netinet/tcpip.h> #include <net/if.h> +#include <arpa/inet.h> #include "ip_compat.h" +#include <netinet/tcpip.h> +#include "ip_fil.h" #include "ipf.h" -#if !defined(lint) && defined(LIBC_SCCS) -static char sccsid[] = "@(#)opt.c 1.8 4/10/96 (C) 1993-1995 Darren Reed"; -static char rcsid[] = "$Id: opt.c,v 2.0.2.3 1997/03/10 08:10:40 darrenr Exp $"; +#if !defined(lint) +static const char sccsid[] = "@(#)opt.c 1.8 4/10/96 (C) 1993-1995 Darren Reed"; +static const char rcsid[] = "@(#)$Id: opt.c,v 2.0.2.9.2.1 1997/11/12 10:58:44 darrenr Exp $"; #endif extern int opts; @@ -63,7 +68,9 @@ struct ipopt_names secclass[] = { { 0, 0, 0, NULL } /* must be last */ }; + static u_char seclevel __P((char *)); +int addipopt __P((char *, struct ipopt_names *, int, char *)); static u_char seclevel(slevel) char *slevel; @@ -82,14 +89,70 @@ char *slevel; } -u_long buildopts(cp, op) +int addipopt(op, io, len, class) +char *op; +struct ipopt_names *io; +int len; +char *class; +{ + int olen = len; + struct in_addr ipadr; + u_short val; + u_char lvl; + char *s; + + if ((len + io->on_siz) > 48) { + fprintf(stderr, "options too long\n"); + return 0; + } + len += io->on_siz; + *op++ = io->on_value; + if (io->on_siz > 1) { + s = op; + *op++ = io->on_siz; + *op++ = IPOPT_MINOFF; + + if (class) { + switch (io->on_value) + { + case IPOPT_SECURITY : + lvl = seclevel(class); + *(op - 1) = lvl; + break; + case IPOPT_LSRR : + case IPOPT_SSRR : + ipadr.s_addr = inet_addr(class); + s[IPOPT_OLEN] = IPOPT_MINOFF - 1 + 4; + bcopy((char *)&ipadr, op, sizeof(ipadr)); + break; + case IPOPT_SATID : + val = atoi(class); + bcopy((char *)&val, op, 2); + break; + } + } + + op += io->on_siz - 3; + if (len & 3) { + *op++ = IPOPT_NOP; + len++; + } + } + if (opts & OPT_DEBUG) + fprintf(stderr, "bo: %s %d %#x: %d\n", + io->on_name, io->on_value, io->on_bit, len); + return len - olen; +} + + +u_32_t buildopts(cp, op, len) char *cp, *op; +int len; { struct ipopt_names *io; - u_char lvl; - u_long msk = 0; + u_32_t msk = 0; char *s, *t; - int len = 0; + int inc; for (s = strtok(cp, ","); s; s = strtok(NULL, ",")) { if ((t = strchr(s, '='))) @@ -97,30 +160,10 @@ char *cp, *op; for (io = ionames; io->on_name; io++) { if (strcasecmp(s, io->on_name) || (msk & io->on_bit)) continue; - if ((len + io->on_siz) > 48) { - fprintf(stderr, "options too long\n"); - return 0; - } - len += io->on_siz; - *op++ = io->on_value; - if (io->on_siz > 1) { - *op++ = io->on_siz; - *op++ = IPOPT_MINOFF; - - if (t && !strcasecmp(s, "sec-class")) { - lvl = seclevel(t); - *(op - 1) = lvl; - } - op += io->on_siz - 3; - if (len & 3) { - *op++ = IPOPT_NOP; - len++; - } + if ((inc = addipopt(op, io, len, t))) { + op += inc; + len += inc; } - if (opts & OPT_DEBUG) - fprintf(stderr, "bo: %s %d %#x: %d\n", - io->on_name, io->on_value, - io->on_bit, len); msk |= io->on_bit; break; } |
