aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/nat/nat44-ed
diff options
context:
space:
mode:
authorHuawei LI <lihuawei_zzu@163.com>2022-10-29 21:20:07 +0800
committerOle Tr�an <otroan@employees.org>2022-11-07 07:58:55 +0000
commit9ff833d8f4ccccc475f9a302b8f70eed49963472 (patch)
tree549bd4356c271427f60857f08dbdffa7bc3d4c7f /src/plugins/nat/nat44-ed
parentce1ff6a9b1ab2c4ab74165b26c92c2d551f53cf8 (diff)
nat: fix byte order error.
fix byte order error about the struct snat_address_t's member net. for example configurations: set interface ip table loop1 1 set interface ip addr loop1 10.10.10.2/24 nat44 add address 10.10.10.2 tenant-vrf 1 the snat address's net should be "as_u8 = {0xa, 0xa, 0xa, 0x0}", but now it's "as_u8 = {0x0, 0xa, 0xa, 0x2}" because of missing transition of byte order about the member net of snat_address_t. (gdb) p/x *snat_main->addresses $3 = {addr = {data = {0xa, 0xa, 0xa, 0x2}, data_u32 = 0x20a0a0a, as_u8 = {0xa, 0xa, 0xa, 0x2}, as_u16 = {0xa0a, 0x20a}, as_u32 = 0x20a0a0a}, net = {data = {0x0, 0xa, 0xa, 0x2}, data_u32 = 0x20a0a00, as_u8 = {0x0, 0xa, 0xa, 0x2}, as_u16 = {0xa00, 0x20a}, as_u32 = 0x20a0a00}, sw_if_index = 0x3, fib_index = 0x1,addr_len = 0x18} (gdb) Type: fix Signed-off-by: Huawei LI <lihuawei_zzu@163.com> Change-Id: I4f25f0639ae90a7f2e8715b44f825571283d994d
Diffstat (limited to 'src/plugins/nat/nat44-ed')
-rw-r--r--src/plugins/nat/nat44-ed/nat44_ed.c10
1 files changed, 4 insertions, 6 deletions
diff --git a/src/plugins/nat/nat44-ed/nat44_ed.c b/src/plugins/nat/nat44-ed/nat44_ed.c
index 2e4c791ef80..ed93f6cc55f 100644
--- a/src/plugins/nat/nat44-ed/nat44_ed.c
+++ b/src/plugins/nat/nat44-ed/nat44_ed.c
@@ -286,8 +286,7 @@ nat44_ed_resolve_nat_addr_len (snat_address_t *ap,
{
ap->addr_len = ia->address_length;
ap->sw_if_index = i->sw_if_index;
- ap->net.as_u32 = (ap->addr.as_u32 >> (32 - ap->addr_len))
- << (32 - ap->addr_len);
+ ap->net.as_u32 = ap->addr.as_u32 & ip4_main.fib_masks[ap->addr_len];
nat_log_debug ("pool addr %U binds to -> sw_if_idx: %u net: %U/%u",
format_ip4_address, &ap->addr, ap->sw_if_index,
@@ -334,8 +333,7 @@ nat44_ed_bind_if_addr_to_nat_addr (u32 sw_if_index)
{
ap->addr_len = ia->address_length;
ap->sw_if_index = sw_if_index;
- ap->net.as_u32 = (ap->addr.as_u32 >> (32 - ap->addr_len))
- << (32 - ap->addr_len);
+ ap->net.as_u32 = ap->addr.as_u32 & ip4_main.fib_masks[ap->addr_len];
nat_log_debug ("pool addr %U binds to -> sw_if_idx: %u net: %U/%u",
format_ip4_address, &ap->addr, ap->sw_if_index,
@@ -3434,8 +3432,8 @@ nat44_ed_add_del_interface_address_cb (ip4_main_t *im, uword opaque,
{
ap->addr_len = address_length;
ap->sw_if_index = sw_if_index;
- ap->net.as_u32 = (ap->addr.as_u32 >> (32 - ap->addr_len))
- << (32 - ap->addr_len);
+ ap->net.as_u32 =
+ ap->addr.as_u32 & ip4_main.fib_masks[ap->addr_len];
nat_log_debug (
"pool addr %U binds to -> sw_if_idx: %u net: %U/%u",