xref: /netbsd-src/external/bsd/ipf/dist/ipmon.h (revision 2f6d4dae9633a7e1c58ba98f387f3e4b2a14ec56)
1*2f6d4daeSchristos /*	$NetBSD: ipmon.h,v 1.3 2012/10/21 22:57:48 christos Exp $	*/
2bc4097aaSchristos 
3bc4097aaSchristos /*
4c9d5dc6cSdarrenr  * Copyright (C) 2012 by Darren Reed.
5bc4097aaSchristos  *
6bc4097aaSchristos  * See the IPFILTER.LICENCE file for details on licencing.
7bc4097aaSchristos  *
8bc4097aaSchristos  * @(#)ip_fil.h	1.35 6/5/96
913885a66Sdarrenr  * Id: ipmon.h,v 1.1.1.2 2012/07/22 13:44:25 darrenr Exp $
10bc4097aaSchristos  */
11bc4097aaSchristos 
12bc4097aaSchristos typedef struct ipmon_msg_s {
13bc4097aaSchristos 	int	imm_msglen;
14bc4097aaSchristos 	char	*imm_msg;
15bc4097aaSchristos 	int	imm_dsize;
16bc4097aaSchristos 	void	*imm_data;
17bc4097aaSchristos 	time_t	imm_when;
18bc4097aaSchristos 	int	imm_loglevel;
19bc4097aaSchristos } ipmon_msg_t;
20bc4097aaSchristos 
21c9d5dc6cSdarrenr typedef	void	(*ims_destroy_func_t)(void *);
22c9d5dc6cSdarrenr typedef	void	*(*ims_dup_func_t)(void *);
23c9d5dc6cSdarrenr typedef	int	(*ims_match_func_t)(void *, void *);
24c9d5dc6cSdarrenr typedef	void	*(*ims_parse_func_t)(char **);
25c9d5dc6cSdarrenr typedef	void	(*ims_print_func_t)(void *);
26c9d5dc6cSdarrenr typedef	int	(*ims_store_func_t)(void *, ipmon_msg_t *);
27c9d5dc6cSdarrenr 
28bc4097aaSchristos typedef struct ipmon_saver_s {
29bc4097aaSchristos 	char			*ims_name;
30c9d5dc6cSdarrenr 	ims_destroy_func_t	ims_destroy;
31c9d5dc6cSdarrenr 	ims_dup_func_t		ims_dup;
32c9d5dc6cSdarrenr 	ims_match_func_t	ims_match;
33c9d5dc6cSdarrenr 	ims_parse_func_t	ims_parse;
34c9d5dc6cSdarrenr 	ims_print_func_t	ims_print;
35c9d5dc6cSdarrenr 	ims_store_func_t	ims_store;
36bc4097aaSchristos } ipmon_saver_t;
37bc4097aaSchristos 
38bc4097aaSchristos typedef struct	ipmon_saver_int_s {
39bc4097aaSchristos 	struct ipmon_saver_int_s	*imsi_next;
40bc4097aaSchristos 	ipmon_saver_t			*imsi_stor;
41bc4097aaSchristos 	void				*imsi_handle;
42bc4097aaSchristos } ipmon_saver_int_t;
43bc4097aaSchristos 
44bc4097aaSchristos typedef	struct	ipmon_doing_s {
45bc4097aaSchristos 	struct ipmon_doing_s	*ipmd_next;
46bc4097aaSchristos 	void			*ipmd_token;
47bc4097aaSchristos 	ipmon_saver_t		*ipmd_saver;
48bc4097aaSchristos 	/*
49bc4097aaSchristos 	 * ipmd_store is "cached" in this structure to avoid a double
50bc4097aaSchristos 	 * deref when doing saves....
51bc4097aaSchristos 	 */
52bc4097aaSchristos 	int			(*ipmd_store)(void *, ipmon_msg_t *);
53bc4097aaSchristos } ipmon_doing_t;
54bc4097aaSchristos 
55bc4097aaSchristos 
56bc4097aaSchristos typedef	struct	ipmon_action {
57bc4097aaSchristos 	struct	ipmon_action	*ac_next;
58bc4097aaSchristos 	int	ac_mflag;	/* collection of things to compare */
59bc4097aaSchristos 	int	ac_dflag;	/* flags to compliment the doing fields */
60bc4097aaSchristos 	int	ac_logpri;
61bc4097aaSchristos 	int	ac_direction;
62bc4097aaSchristos 	char	ac_group[FR_GROUPLEN];
63bc4097aaSchristos 	char	ac_nattag[16];
64bc4097aaSchristos 	u_32_t	ac_logtag;
65bc4097aaSchristos 	int	ac_type;	/* nat/state/ipf */
66bc4097aaSchristos 	int	ac_proto;
67bc4097aaSchristos 	int	ac_rule;
68bc4097aaSchristos 	int	ac_packet;
69bc4097aaSchristos 	int	ac_second;
70bc4097aaSchristos 	int	ac_result;
71bc4097aaSchristos 	u_32_t	ac_sip;
72bc4097aaSchristos 	u_32_t	ac_smsk;
73bc4097aaSchristos 	u_32_t	ac_dip;
74bc4097aaSchristos 	u_32_t	ac_dmsk;
75bc4097aaSchristos 	u_short	ac_sport;
76bc4097aaSchristos 	u_short	ac_dport;
77bc4097aaSchristos 	char	*ac_iface;
78bc4097aaSchristos 	/*
79bc4097aaSchristos 	 * used with ac_packet/ac_second
80bc4097aaSchristos 	 */
81bc4097aaSchristos 	struct	timeval	ac_last;
82bc4097aaSchristos 	int	ac_pktcnt;
83bc4097aaSchristos 	/*
84bc4097aaSchristos 	 * What to do with matches
85bc4097aaSchristos 	 */
86bc4097aaSchristos 	ipmon_doing_t	*ac_doing;
87bc4097aaSchristos } ipmon_action_t;
88bc4097aaSchristos 
89bc4097aaSchristos #define	ac_lastsec	ac_last.tv_sec
90bc4097aaSchristos #define	ac_lastusec	ac_last.tv_usec
91bc4097aaSchristos 
92bc4097aaSchristos /*
93bc4097aaSchristos  * Flags indicating what fields to do matching upon (ac_mflag).
94bc4097aaSchristos  */
95bc4097aaSchristos #define	IPMAC_DIRECTION	0x0001
96bc4097aaSchristos #define	IPMAC_DSTIP	0x0002
97bc4097aaSchristos #define	IPMAC_DSTPORT	0x0004
98bc4097aaSchristos #define	IPMAC_EVERY	0x0008
99bc4097aaSchristos #define	IPMAC_GROUP	0x0010
100bc4097aaSchristos #define	IPMAC_INTERFACE	0x0020
101bc4097aaSchristos #define	IPMAC_LOGTAG	0x0040
102bc4097aaSchristos #define	IPMAC_NATTAG	0x0080
103bc4097aaSchristos #define	IPMAC_PROTOCOL	0x0100
104bc4097aaSchristos #define	IPMAC_RESULT	0x0200
105bc4097aaSchristos #define	IPMAC_RULE	0x0400
106bc4097aaSchristos #define	IPMAC_SRCIP	0x0800
107bc4097aaSchristos #define	IPMAC_SRCPORT	0x1000
108bc4097aaSchristos #define	IPMAC_TYPE	0x2000
109bc4097aaSchristos #define	IPMAC_WITH	0x4000
110bc4097aaSchristos 
111bc4097aaSchristos #define	IPMR_BLOCK	1
112bc4097aaSchristos #define	IPMR_PASS	2
113bc4097aaSchristos #define	IPMR_NOMATCH	3
114bc4097aaSchristos #define	IPMR_LOG	4
115bc4097aaSchristos 
116bc4097aaSchristos #define	IPMON_SYSLOG	0x001
117bc4097aaSchristos #define	IPMON_RESOLVE	0x002
118bc4097aaSchristos #define	IPMON_HEXBODY	0x004
119bc4097aaSchristos #define	IPMON_HEXHDR	0x010
120bc4097aaSchristos #define	IPMON_TAIL	0x020
121bc4097aaSchristos #define	IPMON_VERBOSE	0x040
122bc4097aaSchristos #define	IPMON_NAT	0x080
123bc4097aaSchristos #define	IPMON_STATE	0x100
124bc4097aaSchristos #define	IPMON_FILTER	0x200
125bc4097aaSchristos #define	IPMON_PORTNUM	0x400
126bc4097aaSchristos #define	IPMON_LOGALL	(IPMON_NAT|IPMON_STATE|IPMON_FILTER)
127bc4097aaSchristos #define	IPMON_LOGBODY	0x800
128bc4097aaSchristos 
129bc4097aaSchristos #define	HOSTNAME_V4(a,b)	hostname((a), 4, (u_32_t *)&(b))
130bc4097aaSchristos 
131bc4097aaSchristos #ifndef	LOGFAC
132bc4097aaSchristos #define	LOGFAC	LOG_LOCAL0
133bc4097aaSchristos #endif
134bc4097aaSchristos 
135bc4097aaSchristos extern	void	dump_config __P((void));
136bc4097aaSchristos extern	int	load_config __P((char *));
137bc4097aaSchristos extern	void	unload_config __P((void));
138*2f6d4daeSchristos extern	void	dumphex __P((FILE *, int, const void *, size_t));
139*2f6d4daeSchristos extern	int	check_action __P((const char *, const char *, int, int));
140bc4097aaSchristos extern	char	*getword __P((int));
141bc4097aaSchristos extern	void	*add_doing __P((ipmon_saver_t *));
142bc4097aaSchristos 
143