xref: /openbsd/sys/netinet/ip_ipip.h (revision 7af0f08f)
1 /*	$OpenBSD: ip_ipip.h,v 1.14 2024/08/22 10:58:31 mvs Exp $ */
2 /*
3  * The authors of this code are John Ioannidis (ji@tla.org),
4  * Angelos D. Keromytis (kermit@csd.uch.gr) and
5  * Niels Provos (provos@physnet.uni-hamburg.de).
6  *
7  * The original version of this code was written by John Ioannidis
8  * for BSD/OS in Athens, Greece, in November 1995.
9  *
10  * Ported to OpenBSD and NetBSD, with additional transforms, in December 1996,
11  * by Angelos D. Keromytis.
12  *
13  * Additional transforms and features in 1997 and 1998 by Angelos D. Keromytis
14  * and Niels Provos.
15  *
16  * Additional features in 1999 by Angelos D. Keromytis.
17  *
18  * Copyright (C) 1995, 1996, 1997, 1998, 1999 by John Ioannidis,
19  * Angelos D. Keromytis and Niels Provos.
20  * Copyright (c) 2001, Angelos D. Keromytis.
21  *
22  * Permission to use, copy, and modify this software with or without fee
23  * is hereby granted, provided that this entire notice is included in
24  * all copies of any software which is or includes a copy or
25  * modification of this software.
26  * You may use this code under the GNU public license if you so wish. Please
27  * contribute changes back to the authors under this freer than GPL license
28  * so that we may further the use of strong encryption without limitations to
29  * all.
30  *
31  * THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR
32  * IMPLIED WARRANTY. IN PARTICULAR, NONE OF THE AUTHORS MAKES ANY
33  * REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE
34  * MERCHANTABILITY OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR
35  * PURPOSE.
36  */
37 
38 #ifndef _NETINET_IPIP_H_
39 #define _NETINET_IPIP_H_
40 
41 /*
42  * IP-inside-IP processing.
43  * Not quite all the functionality of RFC-1853, but the main idea is there.
44  */
45 
46 struct ipipstat {
47     u_int64_t	ipips_ipackets;		/* total input packets */
48     u_int64_t	ipips_opackets;		/* total output packets */
49     u_int64_t	ipips_hdrops;		/* packet shorter than header shows */
50     u_int64_t	ipips_qfull;
51     u_int64_t	ipips_ibytes;
52     u_int64_t	ipips_obytes;
53     u_int64_t	ipips_pdrops;		/* packet dropped due to policy */
54     u_int64_t	ipips_spoof;		/* IP spoofing attempts */
55     u_int64_t	ipips_family;		/* Protocol family mismatch */
56     u_int64_t	ipips_unspec;            /* Missing tunnel endpoint address */
57 };
58 
59 #define IP4_DEFAULT_TTL    0
60 #define IP4_SAME_TTL	  -1
61 
62 /*
63  * Names for IPIP sysctl objects
64  */
65 #define	IPIPCTL_ALLOW	1		/* accept incoming IP4 packets */
66 #define	IPIPCTL_STATS	2		/* IPIP stats */
67 #define	IPIPCTL_MAXID	3
68 
69 #define IPIPCTL_NAMES { \
70 	{ 0, 0 }, \
71 	{ "allow", CTLTYPE_INT }, \
72 	{ "stats", CTLTYPE_STRUCT }, \
73 }
74 
75 #ifdef _KERNEL
76 
77 #include <sys/percpu.h>
78 
79 enum ipipstat_counters {
80 	ipips_ipackets,
81 	ipips_opackets,
82 	ipips_hdrops,
83 	ipips_qfull,
84 	ipips_ibytes,
85 	ipips_obytes,
86 	ipips_pdrops,
87 	ipips_spoof,
88 	ipips_family,
89 	ipips_unspec,
90 	ipips_ncounters
91 };
92 
93 extern struct cpumem *ipipcounters;
94 
95 static inline void
ipipstat_inc(enum ipipstat_counters c)96 ipipstat_inc(enum ipipstat_counters c)
97 {
98 	counters_inc(ipipcounters, c);
99 }
100 
101 static inline void
ipipstat_add(enum ipipstat_counters c,uint64_t v)102 ipipstat_add(enum ipipstat_counters c, uint64_t v)
103 {
104 	counters_add(ipipcounters, c, v);
105 }
106 
107 static inline void
ipipstat_pkt(enum ipipstat_counters p,enum ipipstat_counters b,uint64_t v)108 ipipstat_pkt(enum ipipstat_counters p, enum ipipstat_counters b, uint64_t v)
109 {
110 	counters_pkt(ipipcounters, p, b, v);
111 }
112 
113 struct tdb;
114 
115 void	ipip_init(void);
116 int	ipip_input(struct mbuf **, int *, int, int);
117 int	ipip_input_if(struct mbuf **, int *, int, int, int, struct ifnet *);
118 int	ipip_output(struct mbuf **, struct tdb *);
119 int	ipip_sysctl(int *, u_int, void *, size_t *, void *, size_t);
120 
121 extern int ipip_allow;
122 #endif /* _KERNEL */
123 #endif /* _NETINET_IPIP_H_ */
124