Skip to content

remove IPAddrPrefixDefault addrlen, use netip.Prefix and options to know/set the ip family #3081

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

nplanelcisco
Copy link
Contributor

and handle multicast correctly

@nplanelcisco nplanelcisco force-pushed the nplanel/netip-remove-ipprefixaddrlen branch 7 times, most recently from a97c298 to 5160d6b Compare August 7, 2025 16:19
@fujita
Copy link
Member

fujita commented Aug 9, 2025

I had planned to remove addrlen when consolidating the separate structs for v4 and v6, but since you’ve started working on it, let's discuss the DecodeFromBytes and Serialize functions interface first.

With this change, since MarshallingOption becomes required to parse IPv6 addresses correctly, is the functional options pattern still appropriate? Better to use a normal argument?

I think thatFamily type is better than ipv6 bool type. Then we don't need to do the following stuff every time serializing a prefix.

	f := RF_IPv4_VPN
	isMulticast := l.Prefix.Addr().IsMulticast()
	isIPv6 := l.Prefix.Addr().Is6()
	switch {
	case !isMulticast && !isIPv6:
		f = RF_IPv4_VPN
	case isMulticast && !isIPv6:
		f = RF_IPv4_VPN_MC
	case !isMulticast && isIPv6:
		f = RF_IPv6_VPN
	case isMulticast && isIPv6:
		f = RF_IPv6_VPN_MC
	}

@fujita
Copy link
Member

fujita commented Aug 9, 2025

Furthermore, checking the AddPath map every time during serialization is not efficient.
When serializing an MP_REACH message containing multiple prefixes, it will only include a single family, so the map can be checked once at the beginning and the result reused for each prefix serialization.

@nplanelcisco
Copy link
Contributor Author

I had planned to remove addrlen when consolidating the separate structs for v4 and v6, but since you’ve started working on it, let's discuss the DecodeFromBytes and Serialize functions interface first.

With this change, since MarshallingOption becomes required to parse IPv6 addresses correctly, is the functional options pattern still appropriate? Better to use a normal argument?

I think thatFamily type is better than ipv6 bool type. Then we don't need to do the following stuff every time serializing a prefix.

	f := RF_IPv4_VPN
	isMulticast := l.Prefix.Addr().IsMulticast()
	isIPv6 := l.Prefix.Addr().Is6()
	switch {
	case !isMulticast && !isIPv6:
		f = RF_IPv4_VPN
	case isMulticast && !isIPv6:
		f = RF_IPv4_VPN_MC
	case !isMulticast && isIPv6:
		f = RF_IPv6_VPN
	case isMulticast && isIPv6:
		f = RF_IPv6_VPN_MC
	}

Sure,

Marshaling option is only used in the DecodeFromBytes path and will be passed along the way from labeled vpn prefix to IPAddrPrefix, so keeping the isv6 in the MarshalingOption would make sense here. we can put the switch case in an helper GetFamily(prefix netip.Prefix) Family.
I don't think changing the DecodeFromBytes API to add family parameter could be justified here as it's like optional, so MarshallingOption make sense in this way

On the Serialize side l.Prefix already contain all the family needed info and avoid us to store twice the same info in the IPAddrPrefix (if we add Family)

@nplanelcisco
Copy link
Contributor Author

Furthermore, checking the AddPath map every time during serialization is not efficient. When serializing an MP_REACH message containing multiple prefixes, it will only include a single family, so the map can be checked once at the beginning and the result reused for each prefix serialization.

Agreed, I tried to have minimal impact here on changes, and think it would be another PR as the marshaling option, should be accessed other way, like O(1) by merging MarshalingOptions in a single object, so no need to iterate on the options list afterwards

@nplanelcisco
Copy link
Contributor Author

the problem I don't like with the isAddPath lookup (in DecodeFromBytes) is the prefix is not aware on what to expect
in case of multicast ipv6 (or v4) I would need to lookup twice unicast and multicast family, but this is based only to the fact that both unicast and multicast families entries are always in sync as the check is basically a logical or

@nplanelcisco
Copy link
Contributor Author

overall I think we need to talk on our next sync, via sharing some code, the conversation/ideas would probably be more effective

@nplanelcisco nplanelcisco force-pushed the nplanel/netip-remove-ipprefixaddrlen branch from 5160d6b to e65e2df Compare August 14, 2025 14:28
@nplanelcisco nplanelcisco force-pushed the nplanel/netip-remove-ipprefixaddrlen branch from e65e2df to b7ca3a9 Compare August 14, 2025 14:29
@fujita
Copy link
Member

fujita commented Aug 15, 2025

overall I think we need to talk on our next sync, via sharing some code, the conversation/ideas would probably be more effective

Ok, I try to implement some ideas.

btw, the second commit to use Addr to see if multicast or not doesn't work for EOR path object. The fundamental problem is that EOR path should not have nlri. We should not use uninitialized nlri in any place but put uninitialized nlri to EOR path to get family when we convert the path to gRPC path. I'll fix Path.GetFamily() not to use nlri.AFI/SAFI(). Then we don't need AFI() and SAFI() in AddrPrefixInterface in the first place.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants