xref: /openbsd/sys/netinet/ip_ether.h (revision 4cfece93)
1 /*	$OpenBSD: ip_ether.h,v 1.30 2019/10/04 05:00:49 dlg Exp $ */
2 /*
3  * The author of this code is Angelos D. Keromytis (angelos@adk.gr)
4  *
5  * This code was written by Angelos D. Keromytis in October 1999.
6  *
7  * Copyright (C) 1999-2001 Angelos D. Keromytis.
8  *
9  * Permission to use, copy, and modify this software with or without fee
10  * is hereby granted, provided that this entire notice is included in
11  * all copies of any software which is or includes a copy or
12  * modification of this software.
13  * You may use this code under the GNU public license if you so wish. Please
14  * contribute changes back to the authors under this freer than GPL license
15  * so that we may further the use of strong encryption without limitations to
16  * all.
17  *
18  * THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR
19  * IMPLIED WARRANTY. IN PARTICULAR, NONE OF THE AUTHORS MAKES ANY
20  * REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE
21  * MERCHANTABILITY OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR
22  * PURPOSE.
23  */
24 
25 #ifndef _NETINET_IP_ETHER_H_
26 #define _NETINET_IP_ETHER_H_
27 
28 /*
29  * Ethernet-inside-IP processing.
30  */
31 
32 struct etheripstat {
33 	u_int64_t	etherips_hdrops;	/* packet shorter than header shows */
34 	u_int64_t	etherips_qfull;		/* bridge queue full, packet dropped */
35 	u_int64_t	etherips_noifdrops;	/* no interface/bridge information */
36 	u_int64_t	etherips_pdrops;	/* packet dropped due to policy */
37 	u_int64_t	etherips_adrops;	/* all other drops */
38 	u_int64_t	etherips_ipackets;	/* total input packets */
39 	u_int64_t	etherips_opackets;	/* total output packets */
40 	u_int64_t	etherips_ibytes;	/* input bytes */
41 	u_int64_t	etherips_obytes;	/* output bytes */
42 };
43 
44 struct etherip_header {
45 #if BYTE_ORDER == LITTLE_ENDIAN
46 	u_int		eip_res:4;	/* reserved */
47 	u_int		eip_ver:4;	/* version */
48 #endif
49 #if BYTE_ORDER == BIG_ENDIAN
50 	u_int		eip_ver:4;	/* version */
51 	u_int		eip_res:4;	/* reserved */
52 #endif
53 	u_int8_t	eip_pad;	/* required padding byte */
54 } __packed;
55 
56 #define ETHERIP_VERSION		0x03
57 
58 /*
59  * Names for Ether-IP sysctl objects
60  */
61 #define	ETHERIPCTL_ALLOW	1	/* accept incoming EtherIP packets */
62 #define	ETHERIPCTL_STATS	2	/* etherip stats */
63 #define	ETHERIPCTL_MAXID	3
64 
65 #define ETHERIPCTL_NAMES { \
66 	{ 0, 0 }, \
67 	{ "allow", CTLTYPE_INT }, \
68 	{ "stats", CTLTYPE_STRUCT }, \
69 }
70 
71 #ifdef _KERNEL
72 
73 #include <sys/percpu.h>
74 
75 enum etheripstat_counters {
76 	etherips_hdrops,		/* packet shorter than header shows */
77 	etherips_qfull,			/* bridge queue full, packet dropped */
78 	etherips_noifdrops,		/* no interface/bridge information */
79 	etherips_pdrops,		/* packet dropped due to policy */
80 	etherips_adrops,		/* all other drops */
81 	etherips_ipackets,		/* total input packets */
82 	etherips_opackets,		/* total output packets */
83 	etherips_ibytes,		/* input bytes */
84 	etherips_obytes,		/* output bytes */
85 
86 	etherips_ncounters
87 };
88 
89 extern struct cpumem *etheripcounters;
90 
91 static inline void
92 etheripstat_inc(enum etheripstat_counters c)
93 {
94 	counters_inc(etheripcounters, c);
95 }
96 
97 static inline void
98 etheripstat_add(enum etheripstat_counters c, uint64_t v)
99 {
100 	counters_add(etheripcounters, c, v);
101 }
102 
103 static inline void
104 etheripstat_pkt(enum etheripstat_counters pcounter,
105     enum etheripstat_counters bcounter, uint64_t v)
106 {
107 	counters_pkt(etheripcounters, pcounter, bcounter, v);
108 }
109 
110 #endif /* _KERNEL */
111 #endif /* _NETINET_IP_ETHER_H_ */
112