Parcourir la source

added blacklist to stats export

tags/v1.1.0
root il y a 5 ans
Parent
révision
d114fc8b3f
6 fichiers modifiés avec 44 ajouts et 20 suppressions
  1. 4
    0
      src/dp_blacklist.c
  2. 1
    0
      src/dp_blacklist.h
  3. 4
    3
      src/dp_dhcpv4.c
  4. 23
    17
      src/dp_events.c
  5. 11
    0
      src/dp_helpers.c
  6. 1
    0
      src/dp_helpers.h

+ 4
- 0
src/dp_blacklist.c Voir le fichier

@@ -24,6 +24,10 @@
static dp_blacklist *blacklists = NULL;
static time_t dp_cleanuptime = 0;

dp_blacklist *dp_blacklist_get(void) {
return blacklists;
}

void dp_blacklist_add(dp_conf *conf, unsigned char *remoteid, int len) {
dp_blacklist *bl;


+ 1
- 0
src/dp_blacklist.h Voir le fichier

@@ -30,6 +30,7 @@ typedef struct dp_blacklist {
UT_hash_handle hh;
} dp_blacklist;

dp_blacklist *dp_blacklist_get(void);
void dp_blacklist_add (dp_conf*, unsigned char *, int);
int dp_blacklist_check (dp_conf*, unsigned char *, int);
void dp_blacklist_cleanup (dp_conf*);

+ 4
- 3
src/dp_dhcpv4.c Voir le fichier

@@ -48,7 +48,7 @@ void dp_dhcpv4_check(dp_conf *conf, unsigned char *pkt, int pktlen, int offset,


// parse TLV options
while(offset<pktlen && remoteidlen==0) {
while(offset<pktlen) {
uint8_t type = pkt[offset];
uint8_t len;

@@ -75,8 +75,9 @@ void dp_dhcpv4_check(dp_conf *conf, unsigned char *pkt, int pktlen, int offset,
break;

// option 53 message type
if ( type == 53 && len == 1 )
dp_dhcpv4_cnt(*(uint8_t*)(pkt+offset+1));
if ( type == 53 && len == 1 ) {
dp_dhcpv4_cnt((uint8_t)pkt[offset]);
}

// option 82 parser
if ( type == 82 ) {

+ 23
- 17
src/dp_events.c Voir le fichier

@@ -62,8 +62,10 @@ void dp_events_stats(dp_conf *conf) {
char tmpfile[PATH_MAX+4];
dp_dhcpv4_stats *stats4;
dp_dhcpv6_stats *stats6;
dp_blacklist *blacklists, *bl, *tmp;
FILE *fh;
int i;
int first = 1;

snprintf(tmpfile, sizeof(tmpfile), "%s.tmp", conf->stats_file);

@@ -75,43 +77,47 @@ void dp_events_stats(dp_conf *conf) {
fprintf(fh,"{ \"dhcpv4\": { ");

for(i=0; i<DP_DHCPV4_CODE_LEN; i++) {
if ( stats4->relcnt[i]>0 ) {
if ( stats4->relcnt[i]>0 || stats4->abscnt[i]>0 ) {
if ( !first ) fprintf(fh, ", ");
fprintf(fh, "\"%s\": { ", dp_dhcpv4_code[i]);
fprintf(fh, "\"rel\": %llu, \"abs\": %llu }", stats4->relcnt[i], stats4->abscnt[i]);
first=0;
}
else if ( stats4->abscnt[i]>0 ) {
fprintf(fh, "\"%s\": { ", dp_dhcpv4_code[i]);
fprintf(fh, "\"abs\": %llu }", stats4->abscnt[i]);
}

if ( ( stats4->relcnt[i]>0 || stats4->abscnt[i]>0 ) && i+1 != DP_DHCPV4_CODE_LEN )
fprintf(fh, ", ");

stats4->relcnt[i]=0;
}

first=1;

stats6 = dp_dhcpv6_cnt(0);

fprintf(fh, "}, \"dhcpv6\" : { ");

for(i=0; i<DP_DHCPV6_CODE_LEN; i++) {
if ( stats6->relcnt[i]>0 ) {
if ( stats6->relcnt[i]>0 || stats6->abscnt[i]>0 ) {
if ( !first ) fprintf(fh, ", ");
fprintf(fh, "\"%s\": { ", dp_dhcpv6_code[i]);
fprintf(fh, "\"rel\": %llu, \"abs\": %llu }", stats6->relcnt[i], stats6->abscnt[i]);
}
else if ( stats6->abscnt[i]>0 ) {
fprintf(fh, "\"%s\": { ", dp_dhcpv6_code[i]);
fprintf(fh, "\"abs\": %llu }", stats6->abscnt[i]);
first=0;
}

if ( ( stats6->relcnt[i]>0 || stats6->abscnt[i]>0 ) && i+1 != DP_DHCPV6_CODE_LEN )
fprintf(fh, ", ");

stats6->relcnt[i]=0;
}


fprintf(fh, "} }");
fprintf(fh, "}, \"blacklist\": [");

blacklists = dp_blacklist_get();

first=1;
HASH_ITER(hh, blacklists, bl, tmp) {
if ( bl->expire > time(NULL) ) {
if ( !first ) fprintf(fh, ", ");
fprintf(fh, "{ \"id\": \"%s\", \"expire\": %i }", dp_printid(bl->remoteid, bl->len), (int)(bl->expire - time(NULL)));
}
}

fprintf(fh, "] }\n");

fclose(fh);


+ 11
- 0
src/dp_helpers.c Voir le fichier

@@ -155,3 +155,14 @@ dp_conf *dp_load_config(dp_conf *conf, char *file) {

return conf;
}

char *dp_printid(unsigned char *str, int len) {
static char hex[1024];
int i;

memset(hex, 0, sizeof(hex));
for(i=0; i<len && i<512; i++) {
sprintf(hex+(i*2),"%02x", str[i]);
}
return hex;
}

+ 1
- 0
src/dp_helpers.h Voir le fichier

@@ -34,5 +34,6 @@ typedef struct dp_conf {
void dp_usage (char*);
dp_conf *dp_load_config (dp_conf*, char*);
void dp_log (unsigned char *, int, char *, ...);
char *dp_printid(unsigned char*, int);

#endif // __DP_MACRO

Chargement…
Annuler
Enregistrer