Changeset 1482
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/Makefile.am
r1480 r1482 62 62 tcpprep_LDADD = ./common/libcommon.a \ 63 63 $(LIBSTRL) @LNETLIB@ @LPCAPLIB@ $(LIBOPTS_LDADD) 64 tcpprep_SOURCES = tcpprep_opts.c tcpprep.c tree.c 64 tcpprep_SOURCES = tcpprep_opts.c tcpprep.c tree.c mac.c 65 65 tcpprep_OBJECTS: tcpprep_opts.h 66 66 tcpprep_opts.h: tcpprep_opts.c -
trunk/src/mac.c
r1462 r1482 1 /* $Id :$ */1 /* $Id$ */ 2 2 /* Copyright 2004-2005 Aaron Turner 3 3 * All rights reserved. … … 108 108 } 109 109 110 /* 111 * Figures out if a MAC is listed in a comma delimited 112 * string of MAC addresses. 113 * returns CACHE_PRIMARY if listed 114 * returns CACHE_SECONDARY if not listed 115 */ 116 int 117 macinstring(const char *macstring, const u_char *mac) 118 { 119 char *tok, *tempstr, *ourstring; 120 u_char *tempmac; 121 int len = 6, ret = CACHE_SECONDARY; 122 123 ourstring = safe_strdup(macstring); 124 125 tempstr = strtok_r(ourstring, ",", &tok); 126 if (strlen(tempstr)) { 127 mac2hex(tempstr, tempmac, len); 128 if (memcmp(mac, tempmac, len) == 0) { 129 ret = CACHE_PRIMARY; 130 goto EXIT_MACINSTRING; 131 } 132 } else { 133 goto EXIT_MACINSTRING; 134 } 135 136 while ((tempstr = strtok_r(NULL, ",", &tok)) != NULL) { 137 mac2hex(tempstr, tempmac, len); 138 if (memcmp(mac, tempmac, len) == 0) { 139 ret = CACHE_PRIMARY; 140 goto EXIT_MACINSTRING; 141 } 142 } 143 144 EXIT_MACINSTRING: 145 free(ourstring); 146 return ret; 147 } 110 148 111 149 /* -
trunk/src/mac.h
r1462 r1482 1 /* $Id :$ */1 /* $Id$ */ 2 2 /* Copyright 2004 Aaron Turner 3 3 * All rights reserved. … … 35 35 void mac2hex(const char *mac, u_char *dst, int len); 36 36 int dualmac2hex(const char *dualmac, u_char *first, u_char *second, int len); 37 int macinstring(const char *macstring, const u_char *mac); 37 38 38 39 #endif /* __MAC_H__ */ -
trunk/src/tcpprep.c
r1481 r1482 62 62 #include "lib/sll.h" 63 63 #include "lib/strlcpy.h" 64 #include "mac.h" 64 65 65 66 /* … … 121 122 errx(1, "Error opening file: %s", errbuf); 122 123 123 switch((int)options.pcap) { 124 /* make sure we support the DLT type */ 125 switch(pcap_datalink(options.pcap)) { 124 126 case DLT_EN10MB: 125 127 case DLT_LINUX_SLL: … … 129 131 default: 130 132 errx(1, "Unsupported pcap DLT type: 0x%x", pcap_datalink(options.pcap)); 133 } 134 135 /* Can only split based on MAC address for ethernet */ 136 if ((pcap_datalink(options.pcap) != DLT_EN10MB) && 137 (options.mode == MAC_MODE)) { 138 err(1, "MAC mode splitting is only supported by DLT_EN10MB packet captures."); 131 139 } 132 140 … … 285 293 { 286 294 ip_hdr_t *ip_hdr = NULL; 295 eth_hdr_t *eth_hdr = NULL; 287 296 struct pcap_pkthdr pkthdr; 288 297 const u_char *pktdata = NULL; … … 316 325 } 317 326 } 327 328 eth_hdr = (eth_hdr_t *)pktdata; 318 329 319 330 /* get the IP header (if any) */ … … 354 365 cache_result = add_cache(&options.cachedata, SEND, 355 366 check_ip_cidr(options.cidrdata, ip_hdr->ip_src.s_addr)); 367 break; 368 case MAC_MODE: 369 dbg(2, "processing mac mode..."); 370 cache_result = add_cache(&options.cachedata, SEND, 371 macinstring(options.maclist, (u_char *)eth_hdr->ether_shost)); 356 372 break; 357 373 case AUTO_MODE: -
trunk/src/tcpprep.h
r1462 r1482 52 52 tcpr_cache_t *cachedata; 53 53 tcpr_cidr_t *cidrdata; 54 54 char *maclist; 55 55 tcpr_xX_t xX; 56 56 tcpr_bpf_t bpf; -
trunk/src/tcpprep_opts.def
r1481 r1482 76 76 flags-cant = port; 77 77 flags-cant = regex; 78 flags-cant = mac; 78 79 flag-code = <<- EOAuto 79 80 … … 137 138 flags-cant = port; 138 139 flags-cant = regex; 140 flags-cant = mac; 139 141 flag-code = <<- EOCidr 140 142 … … 162 164 flags-cant = port; 163 165 flags-cant = cidr; 166 flags-cant = mac; 164 167 flag-code = <<- EORegex 165 168 … … 185 188 value = p; 186 189 descrip = "Port-split mode"; 190 max = 1; 187 191 flags-cant = auto; 188 192 flags-cant = regex; 189 193 flags-cant = cidr; 194 flags-cant = mac; 190 195 flag-code = <<- EOPort 191 196 … … 197 202 or server based upon the destination port of the header. 198 203 EOText; 204 }; 205 206 flag = { 207 name = mac; 208 value = e; 209 arg-type = string; 210 max = 1; 211 descrip = "Source MAC split mode"; 212 flags-cant = auto; 213 flags-cant = regex; 214 flags-cant = cidr; 215 flags-cant = port; 216 flag-code = <<- EOMac 217 218 options.mode = MAC_MODE; 219 options.maclist = safe_strdup(OPT_ARG(MAC)); 220 221 222 EOMac; 223 doc = <<- EOText 224 Specify a list of MAC addresses to match against the source MAC 225 of each packet. Packets matching one of the values are classified 226 as servers. 227 EOText; 228 199 229 }; 200 230
