Skip to content

Commit

Permalink
mroute: adapt to new protocol handling and hashing improvements
Browse files Browse the repository at this point in the history
Repurposing an unused field and renaming it to 'proto'
instead of introducing a new field. The hashing now
begins at the 'proto' field rather than the 'type'
field. Additionally, the changes ensure that the
correct protocol is consistently used with virtual
addresses ensuring alignment.

Change-Id: Ic66eccb5058fe9c0fae64d8e2ca88728068a92ab
Signed-off-by: Gianmarco De Gregori <[email protected]>
Acked-by: Gert Doering <[email protected]>
Message-Id: <[email protected]>
URL: https://www.mail-archive.com/[email protected]/msg30579.html
Signed-off-by: Gert Doering <[email protected]>
  • Loading branch information
itsGiaan authored and cron2 committed Jan 24, 2025
1 parent 8a0f297 commit dda93f3
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/openvpn/mroute.c
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,7 @@ mroute_addr_print_ex(const struct mroute_addr *ma,
buf_printf(&out, "UNKNOWN");
break;
}
buf_printf(&out, "|%d", maddr.proto);
return BSTR(&out);
}
else
Expand Down
19 changes: 16 additions & 3 deletions src/openvpn/mroute.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@

struct mroute_addr {
uint8_t len; /* length of address */
uint8_t unused;
uint8_t proto;
uint8_t type; /* MR_ADDR/MR_WITH flags */
uint8_t netbits; /* number of bits in network part of address,
* valid if MR_WITH_NETBITS is set */
Expand Down Expand Up @@ -183,6 +183,15 @@ mroute_extract_addr_from_packet(struct mroute_addr *src,
{
unsigned int ret = 0;
verify_align_4(buf);

/*
* Since we don't really need the protocol on vaddresses for internal VPN
* payload packets, make sure we have the same value to avoid hashing insert
* and search issues.
*/
src->proto = 0;
dest->proto = src->proto;

if (tunnel_type == DEV_TYPE_TUN)
{
ret = mroute_extract_addr_ip(src, dest, buf);
Expand All @@ -201,6 +210,10 @@ mroute_addr_equal(const struct mroute_addr *a1, const struct mroute_addr *a2)
{
return false;
}
if (a1->proto != a2->proto)
{
return false;
}
if (a1->netbits != a2->netbits)
{
return false;
Expand All @@ -216,13 +229,13 @@ static inline const uint8_t *
mroute_addr_hash_ptr(const struct mroute_addr *a)
{
/* NOTE: depends on ordering of struct mroute_addr */
return (uint8_t *) &a->type;
return (uint8_t *) &a->proto;
}

static inline uint32_t
mroute_addr_hash_len(const struct mroute_addr *a)
{
return (uint32_t) a->len + 2;
return (uint32_t) a->len + 3;
}

static inline void
Expand Down
1 change: 1 addition & 0 deletions src/openvpn/mtcp.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ multi_create_instance_tcp(struct multi_context *m, struct link_socket *ls)
mi = multi_create_instance(m, NULL, ls);
if (mi)
{
mi->real.proto = ls->info.proto;
struct hash_element *he;
const uint32_t hv = hash_value(hash, &mi->real);
struct hash_bucket *bucket = hash_bucket(hash, hv);
Expand Down
1 change: 1 addition & 0 deletions src/openvpn/mudp.c
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ multi_get_create_instance_udp(struct multi_context *m, bool *floated,
struct mroute_addr real = {0};
struct multi_instance *mi = NULL;
struct hash *hash = m->hash;
real.proto = ls->info.proto;

if (mroute_extract_openvpn_sockaddr(&real, &m->top.c2.from.dest, true)
&& m->top.c2.buf.len > 0)
Expand Down
3 changes: 2 additions & 1 deletion src/openvpn/multi.c
Original file line number Diff line number Diff line change
Expand Up @@ -794,6 +794,7 @@ multi_create_instance(struct multi_context *m, const struct mroute_addr *real,
{
goto err;
}
mi->real.proto = ls->info.proto;
generate_prefix(mi);
}

Expand Down Expand Up @@ -1243,6 +1244,7 @@ multi_learn_in_addr_t(struct multi_context *m,
CLEAR(remote_si);
remote_si.addr.in4.sin_family = AF_INET;
remote_si.addr.in4.sin_addr.s_addr = htonl(a);
addr.proto = 0;
ASSERT(mroute_extract_openvpn_sockaddr(&addr, &remote_si, false));

if (netbits >= 0)
Expand Down Expand Up @@ -3548,7 +3550,6 @@ multi_process_incoming_tun(struct multi_context *m, const unsigned int mpp_flags
const int dev_type = TUNNEL_TYPE(m->top.c1.tuntap);
int16_t vid = 0;


#ifdef MULTI_DEBUG_EVENT_LOOP
printf("TUN -> TCP/UDP [%d]\n", BLEN(&m->top.c2.buf));
#endif
Expand Down

0 comments on commit dda93f3

Please sign in to comment.