def find_reply_from(reply_from: Optional[IPv6Address], interface_name: str,
interface_addresses: Iterable[IPv6Address]) -> IPv6Address:
"""
Find the appropriate reply-from address
:param reply_from: The reply-from address specified in the configuration, if any
:param interface_name: The name of the interface for logging purposes
:param interface_addresses: The list of addresses on the interface
:return: The reply-from address to use
"""
if reply_from:
# Check if this address exists
if reply_from not in interface_addresses:
raise ValueError("Reply-from address {addr} does not exist on {intf}".format(
addr=reply_from,
intf=interface_name
))
return reply_from
else:
# Pick the first link-local address
ll_addresses = [address for address in interface_addresses if address.is_link_local]
if not ll_addresses:
raise ValueError("No link-local address found on {intf}".format(
intf=interface_name
))
return ll_addresses[0]
评论列表
文章目录