Skip to content

Commit

Permalink
appneta#199 support for multiple IP CIDR
Browse files Browse the repository at this point in the history
  • Loading branch information
fklassen committed Dec 15, 2015
1 parent 8cb14ca commit d8d253e
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/common/cidr.c
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@ ip_in_cidr(const tcpr_cidr_t * mycidr, const unsigned long ip)

#ifdef DEBUG
/* copy this for debug purposes, since it's not re-entrant */
strlcpy(netstr, get_addr2name4(htonl(mycidr->u.network), RESOLVE), 20);
strlcpy(netstr, get_addr2name4(mycidr->u.network, RESOLVE), 20);
#endif

/* if they're the same, then ip is in network */
Expand Down
42 changes: 28 additions & 14 deletions src/tcpedit/edit_packet.c
Original file line number Diff line number Diff line change
Expand Up @@ -554,23 +554,30 @@ rewrite_ipv4l3(tcpedit_t *tcpedit, ipv4_hdr_t *ip_hdr, tcpr_dir_t direction)
{
tcpr_cidrmap_t *cidrmap1 = NULL, *cidrmap2 = NULL;
int didsrc = 0, diddst = 0, loop = 1;
tcpr_cidrmap_t *ipmap;

assert(tcpedit);
assert(ip_hdr);

/* first check the src/dst IP maps */
if (tcpedit->srcipmap != NULL) {
if (ip_in_cidr(tcpedit->srcipmap->from, ip_hdr->ip_src.s_addr)) {
ip_hdr->ip_src.s_addr = remap_ipv4(tcpedit, tcpedit->srcipmap->to, ip_hdr->ip_src.s_addr);
ipmap = tcpedit->srcipmap;
while (ipmap != NULL) {
if (ip_in_cidr(ipmap->from, ip_hdr->ip_src.s_addr)) {
ip_hdr->ip_src.s_addr = remap_ipv4(tcpedit, ipmap->to, ip_hdr->ip_src.s_addr);
dbgx(2, "Remapped src addr to: %s", get_addr2name4(ip_hdr->ip_src.s_addr, RESOLVE));
break;
}
ipmap = ipmap->next;
}

if (tcpedit->dstipmap != NULL) {
if (ip_in_cidr(tcpedit->dstipmap->from, ip_hdr->ip_dst.s_addr)) {
ip_hdr->ip_dst.s_addr = remap_ipv4(tcpedit, tcpedit->dstipmap->to, ip_hdr->ip_dst.s_addr);
dbgx(2, "Remapped src addr to: %s", get_addr2name4(ip_hdr->ip_dst.s_addr, RESOLVE));
ipmap = tcpedit->dstipmap;
while (ipmap != NULL) {
if (ip_in_cidr(ipmap->from, ip_hdr->ip_dst.s_addr)) {
ip_hdr->ip_dst.s_addr = remap_ipv4(tcpedit, ipmap->to, ip_hdr->ip_dst.s_addr);
dbgx(2, "Remapped dst addr to: %s", get_addr2name4(ip_hdr->ip_dst.s_addr, RESOLVE));
break;
}
ipmap = ipmap->next;
}

/* anything else to rewrite? */
Expand Down Expand Up @@ -634,23 +641,30 @@ rewrite_ipv6l3(tcpedit_t *tcpedit, ipv6_hdr_t *ip6_hdr, tcpr_dir_t direction)
{
tcpr_cidrmap_t *cidrmap1 = NULL, *cidrmap2 = NULL;
int didsrc = 0, diddst = 0, loop = 1;
tcpr_cidrmap_t *ipmap;

assert(tcpedit);
assert(ip6_hdr);

/* first check the src/dst IP maps */
if (tcpedit->srcipmap != NULL) {
if (ip6_in_cidr(tcpedit->srcipmap->from, &ip6_hdr->ip_src)) {
remap_ipv6(tcpedit, tcpedit->srcipmap->to, &ip6_hdr->ip_src);
ipmap = tcpedit->srcipmap;
while (ipmap != NULL) {
if (ip6_in_cidr(ipmap->from, &ip6_hdr->ip_src)) {
remap_ipv6(tcpedit, ipmap->to, &ip6_hdr->ip_src);
dbgx(2, "Remapped src addr to: %s", get_addr2name6(&ip6_hdr->ip_src, RESOLVE));
break;
}
ipmap = ipmap->next;
}

if (tcpedit->dstipmap != NULL) {
if (ip6_in_cidr(tcpedit->dstipmap->from, &ip6_hdr->ip_dst)) {
remap_ipv6(tcpedit, tcpedit->dstipmap->to, &ip6_hdr->ip_dst);
dbgx(2, "Remapped src addr to: %s", get_addr2name6(&ip6_hdr->ip_dst, RESOLVE));
ipmap = tcpedit->dstipmap;
while (ipmap != NULL) {
if (ip6_in_cidr(ipmap->from, &ip6_hdr->ip_dst)) {
remap_ipv6(tcpedit, ipmap->to, &ip6_hdr->ip_dst);
dbgx(2, "Remapped dst addr to: %s", get_addr2name6(&ip6_hdr->ip_dst, RESOLVE));
break;
}
ipmap = ipmap->next;
}

/* anything else to rewrite? */
Expand Down

0 comments on commit d8d253e

Please sign in to comment.