Skip to content

add option to anonymize sflowtool output for both ipv4 and ipv6. /24 … #43

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion src/sflowtool.c
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,8 @@ typedef struct _SFConfig {
/* general options */
int keepGoing;
int allowDNS;
/* Anonymize */
int anonymize;

} SFConfig;

Expand Down Expand Up @@ -1776,8 +1778,14 @@ static void decodeIPV4(SFSample *sample)
memcpy(&ip, ptr, sizeof(ip));
/* Value copy all ip elements into sample */
sample->s.ipsrc.type = SFLADDRESSTYPE_IP_V4;
if (sfConfig.anonymize == YES) {
ip.saddr=ip.saddr&0xffffff;
}
sample->s.ipsrc.address.ip_v4.addr = ip.saddr;
sample->s.ipdst.type = SFLADDRESSTYPE_IP_V4;
if (sfConfig.anonymize == YES) {
ip.daddr=ip.daddr&0xffffff;
}
sample->s.ipdst.address.ip_v4.addr = ip.daddr;
sample->s.dcd_ipProtocol = ip.protocol;
sample->s.dcd_ipTos = ip.tos;
Expand Down Expand Up @@ -1858,10 +1866,20 @@ static void decodeIPV6(SFSample *sample)
{/* src and dst address */
SFStr buf;
sample->s.ipsrc.type = SFLADDRESSTYPE_IP_V6;
if (sfConfig.anonymize == YES) {
bzero(&sample->s.ipsrc.address, 16);
memcpy(&sample->s.ipsrc.address, ptr, 6);
}
else
memcpy(&sample->s.ipsrc.address, ptr, 16);
ptr +=16;
sf_logf(sample, "srcIP6", printAddress(&sample->s.ipsrc, &buf));
sample->s.ipdst.type = SFLADDRESSTYPE_IP_V6;
if (sfConfig.anonymize == YES) {
bzero(&sample->s.ipdst.address, 16);
memcpy(&sample->s.ipdst.address, ptr, 6);
}
else
memcpy(&sample->s.ipdst.address, ptr, 16);
ptr +=16;
sf_logf(sample, "dstIP6", printAddress(&sample->s.ipdst, &buf));
Expand Down Expand Up @@ -6453,14 +6471,15 @@ static void process_command_line(int argc, char *argv[])

in = getopt_long(argc,
argv,
"ljJgtTHxesSD46Akh?zL:p:r:R:P:c:d:N:f:v:V:",
"ljJgtTHxesSD46aAkh?zL:p:r:R:P:c:d:N:f:v:V:",
long_options,
&option_index);

if(in == -1)
break;

switch(in) {
case 'a': sfConfig.anonymize = YES; break;
case 'p': sfConfig.sFlowInputPort = atoi(optarg); break;
case 't': sfConfig.outputFormat = SFLFMT_PCAP; break;
case 'T': sfConfig.outputFormat = SFLFMT_PCAP_DISCARD; break;
Expand Down