1 /* $Id$ */
2 /****************************************************************************
3  *
4  * Copyright (C) 2014-2021 Cisco and/or its affiliates. All rights reserved.
5  * Copyright (C) 2004-2013 Sourcefire, Inc.
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License Version 2 as
9  * published by the Free Software Foundation.  You may not use, modify or
10  * distribute this program under any other version of the GNU General
11  * Public License.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21  *
22  ****************************************************************************/
23 
24 /**************************************************************************
25  *
26  * stream5_ha.h
27  *
28  * Authors: Michael Altizer <maltizer@sourcefire.com>, Russ Combs <rcombs@sourcefire.com>
29  *
30  * Description:
31  *
32  * Stream high availability exported functionality.
33  *
34  **************************************************************************/
35 
36 #ifndef __STREAM_HA_H__
37 #define __STREAM_HA_H__
38 
39 #ifdef ENABLE_HA
40 
41 #include "sf_types.h"
42 #include "session_common.h"
43 #include "snort_session.h"
44 
45 typedef enum
46 {
47     HA_EVENT_UPDATE,
48     HA_EVENT_DELETE,
49     HA_EVENT_MAX
50 } HA_Event;
51 
52 typedef SessionControlBlock *(*f_ha_create_session) (const SessionKey *);
53 typedef int (*f_ha_delete_session) (const SessionKey *);
54 typedef SessionControlBlock *(*f_ha_get_lws) (const SessionKey *);
55 typedef void (*f_ha_deactivate_session) (SessionControlBlock *);
56 
57 typedef struct
58 {
59     f_ha_get_lws get_lws;
60     f_ha_create_session create_session;
61     f_ha_deactivate_session deactivate_session;
62     f_ha_delete_session delete_session;
63 } HA_Api;
64 
65 extern int ha_set_api(unsigned proto, const HA_Api *);
66 
67 // Used with StreamLWSession.ha_flags:
68 #define HA_FLAG_STANDBY         0x01    // session is not active
69 #define HA_FLAG_NEW             0x02    // flow has never been synchronized
70 #define HA_FLAG_MODIFIED        0x04    // session HA state information has been modified
71 #define HA_FLAG_MAJOR_CHANGE    0x08    // session HA state information has been modified in a major fashion
72 #define HA_FLAG_CRITICAL_CHANGE 0x10    // session HA state information has been modified in a critical fashion
73 #define HA_FLAG_DELETED         0x20    // flow deletion message has been sent
74 
ha_track_modify(SessionControlBlock * lws)75 static inline void ha_track_modify(SessionControlBlock *lws)
76 {
77     lws->ha_flags |= HA_FLAG_MODIFIED;
78 }
79 
80 int RegisterSessionHAFuncs(uint32_t preproc_id, uint8_t subcode, uint8_t size,
81                             StreamHAProducerFunc produce, StreamHAConsumerFunc consume);
82 void UnregisterSessionHAFuncs(uint32_t preproc_id, uint8_t subcode);
83 void SessionSetHAPendingBit(void *ssnptr, int bit);
84 
85 void SessionHAInit(struct _SnortConfig *sc, char *args);
86 void SessionHAReload(struct _SnortConfig *sc, char *args, void **new_config);
87 int SessionVerifyHAConfig(struct _SnortConfig *sc, void *swap_config);
88 void *SessionHASwapReload( struct _SnortConfig *sc, void *data );
89 void SessionHAConfigFree( void *data );
90 
91 void SessionHAPostConfigInit(struct _SnortConfig *sc, int unused, void *arg);
92 void SessionCleanHA(void);
93 void SessionPrintHAStats(void);
94 void SessionResetHAStats(void);
95 void SessionProcessHA(void *ssnptr, const DAQ_PktHdr_t *pkthdr);
96 void SessionHANotifyDeletion(SessionControlBlock *scb);
97 #ifdef HAVE_DAQ_QUERYFLOW
98 #ifdef REG_TEST
99 int SessionHAQueryDAQState( DAQ_PktHdr_t *pkthdr);
100 #else
101 int SessionHAQueryDAQState(const  DAQ_PktHdr_t *pkthdr);
102 #endif
103 #endif
104 
105 #endif /* ENABLE_HA */
106 
107 #endif /* __STREAM_HA_H__ */
108