Skip to content

Commit 7713739

Browse files
committed
Use control:Packet-SRC-IP-Address when proxying needs a given source
For the case when using Packet-DST-IP-Address to direct proxying. This needs to align with the src_ipaddr defined for the home server.
1 parent 2b9e8ad commit 7713739

File tree

1 file changed

+25
-2
lines changed

1 file changed

+25
-2
lines changed

src/main/process.c

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3322,7 +3322,7 @@ static int request_will_proxy(REQUEST *request)
33223322
} else if (((vp = fr_pair_find_by_num(request->config, PW_PACKET_DST_IP_ADDRESS, 0, TAG_ANY)) != NULL) ||
33233323
((vp = fr_pair_find_by_num(request->config, PW_PACKET_DST_IPV6_ADDRESS, 0, TAG_ANY)) != NULL)) {
33243324
uint16_t dst_port;
3325-
fr_ipaddr_t dst_ipaddr;
3325+
fr_ipaddr_t dst_ipaddr, src_ipaddr;
33263326

33273327
memset(&dst_ipaddr, 0, sizeof(dst_ipaddr));
33283328

@@ -3359,20 +3359,43 @@ static int request_will_proxy(REQUEST *request)
33593359
dst_port = vp->vp_integer;
33603360
}
33613361

3362+
if (((vp = fr_pair_find_by_num(request->config, PW_PACKET_SRC_IP_ADDRESS, 0, TAG_ANY)) != NULL) ||
3363+
((vp = fr_pair_find_by_num(request->config, PW_PACKET_SRC_IPV6_ADDRESS, 0, TAG_ANY)) != NULL)) {
3364+
if (((dst_ipaddr.af == AF_INET) && (vp->da->attr != PW_PACKET_SRC_IP_ADDRESS)) ||
3365+
((dst_ipaddr.af == AF_INET6) && (vp->da->attr != PW_PACKET_SRC_IPV6_ADDRESS))) {
3366+
REDEBUG("Cannot mix IPv4 and IPv6 source and destination addresses");
3367+
return 0;
3368+
}
3369+
if (vp->da->attr == PW_PACKET_SRC_IP_ADDRESS) {
3370+
src_ipaddr.af = AF_INET;
3371+
src_ipaddr.ipaddr.ip4addr.s_addr = vp->vp_ipaddr;
3372+
src_ipaddr.prefix = 32;
3373+
} else {
3374+
src_ipaddr.af = AF_INET6;
3375+
memcpy(&src_ipaddr.ipaddr.ip6addr, &vp->vp_ipv6addr, sizeof(vp->vp_ipv6addr));
3376+
src_ipaddr.prefix = 128;
3377+
}
3378+
home = home_server_find_bysrc(&dst_ipaddr, dst_port, IPPROTO_UDP, &src_ipaddr);
3379+
if (!home) home_server_find_bysrc(&dst_ipaddr, dst_port, IPPROTO_TCP, &src_ipaddr);
3380+
if (!home) goto no_home;
3381+
goto found_home;
3382+
}
3383+
33623384
/*
33633385
* Find the home server.
33643386
*/
33653387
home = home_server_find(&dst_ipaddr, dst_port, IPPROTO_UDP);
33663388
if (!home) home = home_server_find(&dst_ipaddr, dst_port, IPPROTO_TCP);
33673389
if (!home) {
33683390
char buffer[256];
3369-
3391+
no_home:
33703392
RWDEBUG("No such home server %s port %u",
33713393
inet_ntop(dst_ipaddr.af, &dst_ipaddr.ipaddr, buffer, sizeof(buffer)),
33723394
(unsigned int) dst_port);
33733395
return 0;
33743396
}
33753397

3398+
found_home:
33763399
/*
33773400
* The home server is alive (or may be alive).
33783401
* Send the packet to the IP.

0 commit comments

Comments
 (0)