Skip to content

Commit 5a89bba

Browse files
committed
Add s7comm prefs
1 parent 6a95f44 commit 5a89bba

File tree

3 files changed

+48
-0
lines changed

3 files changed

+48
-0
lines changed

include/Prefs.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ class Prefs {
7575
#ifdef NTOPNG_PRO
7676
ndpi_bitmap* modbus_allowed_function_codes;
7777
u_int modbus_too_many_exceptions;
78+
ndpi_bitmap* s7comm_allowed_function_codes;
79+
u_int s7comm_too_many_errors;
7880
bool data_archive_before_ttl_delete, asset_inventory_enabled, snmp_trap_enabled;
7981
#endif
8082
ServiceAcceptance behaviour_analysis_learning_status_during_learning,
@@ -740,6 +742,9 @@ class Prefs {
740742
inline ndpi_bitmap* getModbusAllowedFunctionCodes() { return (modbus_allowed_function_codes); };
741743
inline void setModbusTooManyExceptionsThreshold(u_int v) { modbus_too_many_exceptions = v; }
742744
inline u_int getModbusTooManyExceptionsThreshold() { return(modbus_too_many_exceptions); }
745+
inline ndpi_bitmap* getS7CommAllowedFunctionCodes() { return (s7comm_allowed_function_codes); };
746+
inline void setS7CommTooManyErrorsThreshold(u_int v) { s7comm_too_many_errors = v; }
747+
inline u_int getS7CommTooManyErrorsThreshold() { return(s7comm_too_many_errors); }
743748
#endif
744749
inline u_int32_t devicesLearingPeriod() { return (devices_learning_period); };
745750
inline u_int32_t macAddressCacheDuration() { return (mac_address_cache_duration); };
@@ -763,6 +768,7 @@ class Prefs {
763768
};
764769
#ifdef NTOPNG_PRO
765770
void setModbusAllowedFunctionCodes(const char *function_codes);
771+
void setS7CommAllowedFunctionCodes(const char *function_codes);
766772
#endif
767773
void setIEC104AllowedTypeIDs(const char* type_ids);
768774
void validate();

scripts/lua/modules/http_lint.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2384,6 +2384,7 @@ local known_parameters = {
23842384
["behaviour_analysis_learning_status_post_learning"] = validateNumber,
23852385
["iec60870_learning_period"] = validateNumber,
23862386
["modbus_learning_period"] = validateNumber,
2387+
["s7comm_learning_period"] = validateNumber,
23872388
["devices_learning_period"] = validateNumber,
23882389
["host_port_learning_period"] = validateNumber,
23892390
["toggle_src_and_dst_using_ports"] = validateBool,

src/Prefs.cpp

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,8 @@ Prefs::Prefs(Ntop *_ntop) {
262262
#ifdef NTOPNG_PRO
263263
modbus_allowed_function_codes = NULL; /* All allowed */
264264
modbus_too_many_exceptions = 5;
265+
s7comm_allowed_function_codes = NULL; /* All allowed */
266+
s7comm_too_many_errors = 5;
265267
#endif
266268
}
267269

@@ -345,6 +347,8 @@ Prefs::~Prefs() {
345347
#ifdef NTOPNG_PRO
346348
if(modbus_allowed_function_codes)
347349
ndpi_bitmap_free(modbus_allowed_function_codes);
350+
if(s7comm_allowed_function_codes)
351+
ndpi_bitmap_free(s7comm_allowed_function_codes);
348352
#endif
349353

350354
if(gateway) delete gateway;
@@ -3318,6 +3322,43 @@ void Prefs::setModbusAllowedFunctionCodes(const char *function_codes) {
33183322
}
33193323
}
33203324

3325+
/* *************************************** */
3326+
3327+
void Prefs::setS7CommAllowedFunctionCodes(const char *function_codes) {
3328+
char *p, *buf, *tmp;
3329+
3330+
if(!function_codes) return;
3331+
3332+
if((strcmp(function_codes, "-1") == 0)) {
3333+
if(s7comm_allowed_function_codes != NULL) {
3334+
ndpi_bitmap_free(s7comm_allowed_function_codes);
3335+
s7comm_allowed_function_codes = NULL;
3336+
}
3337+
} else if((buf = strdup(function_codes))) {
3338+
if(s7comm_allowed_function_codes == NULL) {
3339+
if((s7comm_allowed_function_codes = ndpi_bitmap_alloc()) == NULL)
3340+
ntop->getTrace()->traceEvent(TRACE_WARNING, "Unable to allocate bitmap memory");
3341+
}
3342+
3343+
if(s7comm_allowed_function_codes) {
3344+
ndpi_bitmap_free(s7comm_allowed_function_codes);
3345+
3346+
if((s7comm_allowed_function_codes = ndpi_bitmap_alloc()) != NULL) {
3347+
p = strtok_r(buf, ",", &tmp);
3348+
while(p != NULL) {
3349+
int f_code = atoi(p);
3350+
3351+
ndpi_bitmap_set(s7comm_allowed_function_codes, f_code);
3352+
3353+
p = strtok_r(NULL, ",", &tmp);
3354+
}
3355+
}
3356+
}
3357+
3358+
free(buf);
3359+
}
3360+
}
3361+
33213362
#endif
33223363

33233364
/* *************************************** */

0 commit comments

Comments
 (0)