siftr.c (3b8f08459569bf0faa21473e5cec2491e95c9349) siftr.c (0e1152fcc2fe48dea2583ac89d30ba77b4ab78cc)
1/*-
2 * Copyright (c) 2007-2009
3 * Swinburne University of Technology, Melbourne, Australia.
4 * Copyright (c) 2009-2010, The FreeBSD Foundation
5 * All rights reserved.
6 *
7 * Portions of this software were developed at the Centre for Advanced
8 * Internet Architectures, Swinburne University of Technology, Melbourne,

--- 254 unchanged lines hidden (view full) ---

263static DPCPU_DEFINE(struct siftr_stats, ss);
264
265static volatile unsigned int siftr_exit_pkt_manager_thread = 0;
266static unsigned int siftr_enabled = 0;
267static unsigned int siftr_pkts_per_log = 1;
268static unsigned int siftr_generate_hashes = 0;
269/* static unsigned int siftr_binary_log = 0; */
270static char siftr_logfile[PATH_MAX] = "/var/log/siftr.log";
1/*-
2 * Copyright (c) 2007-2009
3 * Swinburne University of Technology, Melbourne, Australia.
4 * Copyright (c) 2009-2010, The FreeBSD Foundation
5 * All rights reserved.
6 *
7 * Portions of this software were developed at the Centre for Advanced
8 * Internet Architectures, Swinburne University of Technology, Melbourne,

--- 254 unchanged lines hidden (view full) ---

263static DPCPU_DEFINE(struct siftr_stats, ss);
264
265static volatile unsigned int siftr_exit_pkt_manager_thread = 0;
266static unsigned int siftr_enabled = 0;
267static unsigned int siftr_pkts_per_log = 1;
268static unsigned int siftr_generate_hashes = 0;
269/* static unsigned int siftr_binary_log = 0; */
270static char siftr_logfile[PATH_MAX] = "/var/log/siftr.log";
271static char siftr_logfile_shadow[PATH_MAX] = "/var/log/siftr.log";
271static u_long siftr_hashmask;
272STAILQ_HEAD(pkthead, pkt_node) pkt_queue = STAILQ_HEAD_INITIALIZER(pkt_queue);
273LIST_HEAD(listhead, flow_hash_node) *counter_hash;
274static int wait_for_pkt;
275static struct alq *siftr_alq = NULL;
276static struct mtx siftr_pkt_queue_mtx;
277static struct mtx siftr_pkt_mgr_mtx;
278static struct thread *siftr_pkt_manager_thr = NULL;

--- 15 unchanged lines hidden (view full) ---

294SYSCTL_NODE(_net_inet, OID_AUTO, siftr, CTLFLAG_RW, NULL,
295 "siftr related settings");
296
297SYSCTL_PROC(_net_inet_siftr, OID_AUTO, enabled, CTLTYPE_UINT|CTLFLAG_RW,
298 &siftr_enabled, 0, &siftr_sysctl_enabled_handler, "IU",
299 "switch siftr module operations on/off");
300
301SYSCTL_PROC(_net_inet_siftr, OID_AUTO, logfile, CTLTYPE_STRING|CTLFLAG_RW,
272static u_long siftr_hashmask;
273STAILQ_HEAD(pkthead, pkt_node) pkt_queue = STAILQ_HEAD_INITIALIZER(pkt_queue);
274LIST_HEAD(listhead, flow_hash_node) *counter_hash;
275static int wait_for_pkt;
276static struct alq *siftr_alq = NULL;
277static struct mtx siftr_pkt_queue_mtx;
278static struct mtx siftr_pkt_mgr_mtx;
279static struct thread *siftr_pkt_manager_thr = NULL;

--- 15 unchanged lines hidden (view full) ---

295SYSCTL_NODE(_net_inet, OID_AUTO, siftr, CTLFLAG_RW, NULL,
296 "siftr related settings");
297
298SYSCTL_PROC(_net_inet_siftr, OID_AUTO, enabled, CTLTYPE_UINT|CTLFLAG_RW,
299 &siftr_enabled, 0, &siftr_sysctl_enabled_handler, "IU",
300 "switch siftr module operations on/off");
301
302SYSCTL_PROC(_net_inet_siftr, OID_AUTO, logfile, CTLTYPE_STRING|CTLFLAG_RW,
302 &siftr_logfile, sizeof(siftr_logfile), &siftr_sysctl_logfile_name_handler,
303 &siftr_logfile_shadow, sizeof(siftr_logfile_shadow), &siftr_sysctl_logfile_name_handler,
303 "A", "file to save siftr log messages to");
304
305SYSCTL_UINT(_net_inet_siftr, OID_AUTO, ppl, CTLFLAG_RW,
306 &siftr_pkts_per_log, 1,
307 "number of packets between generating a log message");
308
309SYSCTL_UINT(_net_inet_siftr, OID_AUTO, genhashes, CTLFLAG_RW,
310 &siftr_generate_hashes, 0,

--- 829 unchanged lines hidden (view full) ---

1140
1141
1142static int
1143siftr_sysctl_logfile_name_handler(SYSCTL_HANDLER_ARGS)
1144{
1145 struct alq *new_alq;
1146 int error;
1147
304 "A", "file to save siftr log messages to");
305
306SYSCTL_UINT(_net_inet_siftr, OID_AUTO, ppl, CTLFLAG_RW,
307 &siftr_pkts_per_log, 1,
308 "number of packets between generating a log message");
309
310SYSCTL_UINT(_net_inet_siftr, OID_AUTO, genhashes, CTLFLAG_RW,
311 &siftr_generate_hashes, 0,

--- 829 unchanged lines hidden (view full) ---

1141
1142
1143static int
1144siftr_sysctl_logfile_name_handler(SYSCTL_HANDLER_ARGS)
1145{
1146 struct alq *new_alq;
1147 int error;
1148
1148 if (req->newptr == NULL)
1149 goto skip;
1149 error = sysctl_handle_string(oidp, arg1, arg2, req);
1150
1150
1151 /* If old filename and new filename are different. */
1152 if (strncmp(siftr_logfile, (char *)req->newptr, PATH_MAX)) {
1151 /* Check for error or same filename */
1152 if (error != 0 || req->newptr == NULL ||
1153 strncmp(siftr_logfile, arg1, arg2) == 0)
1154 goto done;
1153
1155
1154 error = alq_open(&new_alq, req->newptr, curthread->td_ucred,
1155 SIFTR_LOG_FILE_MODE, SIFTR_ALQ_BUFLEN, 0);
1156 /* Filname changed */
1157 error = alq_open(&new_alq, arg1, curthread->td_ucred,
1158 SIFTR_LOG_FILE_MODE, SIFTR_ALQ_BUFLEN, 0);
1159 if (error != 0)
1160 goto done;
1156
1161
1157 /* Bail if unable to create new alq. */
1158 if (error)
1159 return (1);
1160
1161 /*
1162 * If disabled, siftr_alq == NULL so we simply close
1163 * the alq as we've proved it can be opened.
1164 * If enabled, close the existing alq and switch the old
1165 * for the new.
1166 */
1167 if (siftr_alq == NULL)
1168 alq_close(new_alq);
1169 else {
1170 alq_close(siftr_alq);
1171 siftr_alq = new_alq;
1172 }
1162 /*
1163 * If disabled, siftr_alq == NULL so we simply close
1164 * the alq as we've proved it can be opened.
1165 * If enabled, close the existing alq and switch the old
1166 * for the new.
1167 */
1168 if (siftr_alq == NULL) {
1169 alq_close(new_alq);
1170 } else {
1171 alq_close(siftr_alq);
1172 siftr_alq = new_alq;
1173 }
1174
1173 }
1174
1175skip:
1176 return (sysctl_handle_string(oidp, arg1, arg2, req));
1175 /* Update filename upon success */
1176 strlcpy(siftr_logfile, arg1, arg2);
1177done:
1178 return (error);
1177}
1178
1179}
1180
1179
1180static int
1181siftr_manage_ops(uint8_t action)
1182{
1183 struct siftr_stats totalss;
1184 struct timeval tval;
1185 struct flow_hash_node *counter, *tmp_counter;
1186 struct sbuf *s;
1187 int i, key_index, ret, error;

--- 364 unchanged lines hidden ---
1181static int
1182siftr_manage_ops(uint8_t action)
1183{
1184 struct siftr_stats totalss;
1185 struct timeval tval;
1186 struct flow_hash_node *counter, *tmp_counter;
1187 struct sbuf *s;
1188 int i, key_index, ret, error;

--- 364 unchanged lines hidden ---