- if (loglen < msgsize)
- dptr[loglen-1] = 0;
- else
- dptr[msgsize-1] = 0;
-
- pri = LOG_PRI(level);
-
- /* remove "ipfw:" prefix if logging to ipfw log */
- if ( !(strncmp( ipfwstring, msgBuf, ipfwstringlen))){
- dptr = msgBuf+ipfwstringlen;
- }
-
- ev_msg.dv[0].data_ptr = &pri;
- ev_msg.dv[0].data_length = 1;
- ev_msg.dv[1].data_ptr = dptr;
- ev_msg.dv[1].data_length = 100; /* bug in kern_post_msg, it can't handle size > 256-msghdr */
- ev_msg.dv[2].data_length = 0;
-
- kev_post_msg(&ev_msg);
+ if (loglen < msgsize) {
+ dptr[loglen - 1] = 0;
+ } else {
+ dptr[msgsize - 1] = 0;
+ }
+
+ pri = LOG_PRI(level);
+
+ /* remove "ipfw:" prefix if logging to ipfw log */
+ if (!(strncmp( ipfwstring, msgBuf, ipfwstringlen))) {
+ dptr = msgBuf + ipfwstringlen;
+ }
+
+ ev_msg.dv[0].data_ptr = &pri;
+ ev_msg.dv[0].data_length = 1;
+ ev_msg.dv[1].data_ptr = dptr;
+ ev_msg.dv[1].data_length = 100; /* bug in kern_post_msg, it can't handle size > 256-msghdr */
+ ev_msg.dv[2].data_length = 0;
+
+ kev_post_msg(&ev_msg);
+}
+
+static inline void
+ipfw_stealth_stats_incr(uint32_t type)
+{
+ if (type >= IPFW_STEALTH_STATS_MAX) {
+ return;
+ }
+
+ ipfw_stealth_stats[type]++;
+
+ if (!ipfw_stealth_stats_needs_flush) {
+ ipfw_stealth_stats_needs_flush = TRUE;
+ }
+}
+
+void
+ipfw_stealth_stats_incr_udp(void)
+{
+ ipfw_stealth_stats_incr(IPFW_STEALTH_STATS_UDP);
+}
+
+void
+ipfw_stealth_stats_incr_tcp(void)
+{
+ ipfw_stealth_stats_incr(IPFW_STEALTH_STATS_TCP);
+}
+
+void
+ipfw_stealth_stats_incr_udpv6(void)
+{
+ ipfw_stealth_stats_incr(IPFW_STEALTH_STATS_UDPv6);
+}
+
+void
+ipfw_stealth_stats_incr_tcpv6(void)
+{
+ ipfw_stealth_stats_incr(IPFW_STEALTH_STATS_TCPv6);
+}
+
+static void
+ipfw_stealth_flush_stats(void)
+{
+ int i;
+
+ for (i = 0; i < IPFW_STEALTH_STATS_MAX; i++) {
+ if (ipfw_stealth_stats[i]) {
+ ipfwsyslog(LOG_INFO, "Stealth Mode connection attempt to %s %d times",
+ ipfw_stealth_stats_str[i], ipfw_stealth_stats[i]);
+ ipfw_stealth_stats[i] = 0;
+ }
+ }
+ ipfw_stealth_stats_needs_flush = FALSE;