1*a3a66860Sdlg /* $OpenBSD: ip_ether.h,v 1.30 2019/10/04 05:00:49 dlg Exp $ */
20b581c19Sangelos /*
30b581c19Sangelos * The author of this code is Angelos D. Keromytis (angelos@adk.gr)
40b581c19Sangelos *
50b581c19Sangelos * This code was written by Angelos D. Keromytis in October 1999.
60b581c19Sangelos *
70775ebe4Sangelos * Copyright (C) 1999-2001 Angelos D. Keromytis.
80b581c19Sangelos *
90775ebe4Sangelos * Permission to use, copy, and modify this software with or without fee
100b581c19Sangelos * is hereby granted, provided that this entire notice is included in
110b581c19Sangelos * all copies of any software which is or includes a copy or
120b581c19Sangelos * modification of this software.
130b581c19Sangelos * You may use this code under the GNU public license if you so wish. Please
140b581c19Sangelos * contribute changes back to the authors under this freer than GPL license
150b581c19Sangelos * so that we may further the use of strong encryption without limitations to
160b581c19Sangelos * all.
170b581c19Sangelos *
180b581c19Sangelos * THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR
190b581c19Sangelos * IMPLIED WARRANTY. IN PARTICULAR, NONE OF THE AUTHORS MAKES ANY
200b581c19Sangelos * REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE
210b581c19Sangelos * MERCHANTABILITY OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR
220b581c19Sangelos * PURPOSE.
230b581c19Sangelos */
240b581c19Sangelos
25d1eb37ffSangelos #ifndef _NETINET_IP_ETHER_H_
26d1eb37ffSangelos #define _NETINET_IP_ETHER_H_
27d1eb37ffSangelos
280b581c19Sangelos /*
290b581c19Sangelos * Ethernet-inside-IP processing.
300b581c19Sangelos */
310b581c19Sangelos
3271a5d0e3Sjason struct etheripstat {
33a1fe7271Sjca u_int64_t etherips_hdrops; /* packet shorter than header shows */
34a1fe7271Sjca u_int64_t etherips_qfull; /* bridge queue full, packet dropped */
35a1fe7271Sjca u_int64_t etherips_noifdrops; /* no interface/bridge information */
36a1fe7271Sjca u_int64_t etherips_pdrops; /* packet dropped due to policy */
37a1fe7271Sjca u_int64_t etherips_adrops; /* all other drops */
38a1fe7271Sjca u_int64_t etherips_ipackets; /* total input packets */
39a1fe7271Sjca u_int64_t etherips_opackets; /* total output packets */
40a1fe7271Sjca u_int64_t etherips_ibytes; /* input bytes */
41a1fe7271Sjca u_int64_t etherips_obytes; /* output bytes */
420b581c19Sangelos };
430b581c19Sangelos
4465b14adfSjason struct etherip_header {
4572a0bcbaSderaadt #if BYTE_ORDER == LITTLE_ENDIAN
461611710dSderaadt u_int eip_res:4; /* reserved */
4772a0bcbaSderaadt u_int eip_ver:4; /* version */
4872a0bcbaSderaadt #endif
4972a0bcbaSderaadt #if BYTE_ORDER == BIG_ENDIAN
5072a0bcbaSderaadt u_int eip_ver:4; /* version */
511611710dSderaadt u_int eip_res:4; /* reserved */
5272a0bcbaSderaadt #endif
53b8b0b912Sjason u_int8_t eip_pad; /* required padding byte */
5472a0bcbaSderaadt } __packed;
5565b14adfSjason
56b8b0b912Sjason #define ETHERIP_VERSION 0x03
570efd8267Sangelos
580b581c19Sangelos /*
594bd06df3Sangelos * Names for Ether-IP sysctl objects
600b581c19Sangelos */
610b581c19Sangelos #define ETHERIPCTL_ALLOW 1 /* accept incoming EtherIP packets */
62ab46c28dSderaadt #define ETHERIPCTL_STATS 2 /* etherip stats */
63ab46c28dSderaadt #define ETHERIPCTL_MAXID 3
640b581c19Sangelos
650b581c19Sangelos #define ETHERIPCTL_NAMES { \
660b581c19Sangelos { 0, 0 }, \
670b581c19Sangelos { "allow", CTLTYPE_INT }, \
68ab46c28dSderaadt { "stats", CTLTYPE_STRUCT }, \
690b581c19Sangelos }
700b581c19Sangelos
710b581c19Sangelos #ifdef _KERNEL
72dd4faa4aSvisa
73dd4faa4aSvisa #include <sys/percpu.h>
74dd4faa4aSvisa
75dd4faa4aSvisa enum etheripstat_counters {
76dd4faa4aSvisa etherips_hdrops, /* packet shorter than header shows */
77dd4faa4aSvisa etherips_qfull, /* bridge queue full, packet dropped */
78dd4faa4aSvisa etherips_noifdrops, /* no interface/bridge information */
79dd4faa4aSvisa etherips_pdrops, /* packet dropped due to policy */
80dd4faa4aSvisa etherips_adrops, /* all other drops */
81dd4faa4aSvisa etherips_ipackets, /* total input packets */
82dd4faa4aSvisa etherips_opackets, /* total output packets */
83dd4faa4aSvisa etherips_ibytes, /* input bytes */
84dd4faa4aSvisa etherips_obytes, /* output bytes */
85dd4faa4aSvisa
86dd4faa4aSvisa etherips_ncounters
87dd4faa4aSvisa };
88dd4faa4aSvisa
89dd4faa4aSvisa extern struct cpumem *etheripcounters;
90dd4faa4aSvisa
91dd4faa4aSvisa static inline void
etheripstat_inc(enum etheripstat_counters c)92dd4faa4aSvisa etheripstat_inc(enum etheripstat_counters c)
93dd4faa4aSvisa {
94dd4faa4aSvisa counters_inc(etheripcounters, c);
95dd4faa4aSvisa }
96dd4faa4aSvisa
97dd4faa4aSvisa static inline void
etheripstat_add(enum etheripstat_counters c,uint64_t v)98dd4faa4aSvisa etheripstat_add(enum etheripstat_counters c, uint64_t v)
99dd4faa4aSvisa {
100dd4faa4aSvisa counters_add(etheripcounters, c, v);
101dd4faa4aSvisa }
102dd4faa4aSvisa
103dd4faa4aSvisa static inline void
etheripstat_pkt(enum etheripstat_counters pcounter,enum etheripstat_counters bcounter,uint64_t v)104dd4faa4aSvisa etheripstat_pkt(enum etheripstat_counters pcounter,
105dd4faa4aSvisa enum etheripstat_counters bcounter, uint64_t v)
106dd4faa4aSvisa {
107dd4faa4aSvisa counters_pkt(etheripcounters, pcounter, bcounter, v);
108dd4faa4aSvisa }
109dd4faa4aSvisa
110d1eb37ffSangelos #endif /* _KERNEL */
111d1eb37ffSangelos #endif /* _NETINET_IP_ETHER_H_ */
112