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