From: Nick Porter Date: Thu, 29 May 2025 13:16:59 +0000 (+0100) Subject: Add Interface to Net tlv X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=da40d152c0b9e938bf960ed1a2d408ab16ee92ef;p=thirdparty%2Ffreeradius-server.git Add Interface to Net tlv Allows policy decisions based on the interface a packet was received on. Especially useful for multi-interface DHCPv4 servers handling broadcast packets where src IP is always 0.0.0.0 and dest IP is always 255.255.255.255. --- diff --git a/share/dictionary/freeradius/dictionary.freeradius.internal b/share/dictionary/freeradius/dictionary.freeradius.internal index 8cb90c2794a..08808626c64 100644 --- a/share/dictionary/freeradius/dictionary.freeradius.internal +++ b/share/dictionary/freeradius/dictionary.freeradius.internal @@ -83,6 +83,7 @@ ATTRIBUTE IP .1.1 combo-ip ATTRIBUTE Port .1.2 uint16 ATTRIBUTE Dst .2 tlv clone=.Src ATTRIBUTE Timestamp .3 date +ATTRIBUTE Interface .4 string # # diff --git a/src/lib/server/packet.c b/src/lib/server/packet.c index 5a66a58568a..c9a77b6d8e4 100644 --- a/src/lib/server/packet.c +++ b/src/lib/server/packet.c @@ -44,6 +44,7 @@ static fr_dict_attr_t const *attr_net_dst; static fr_dict_attr_t const *attr_net_dst_ip; static fr_dict_attr_t const *attr_net_dst_port; static fr_dict_attr_t const *attr_net_timestamp; +static fr_dict_attr_t const *attr_net_interface; extern fr_dict_attr_autoload_t util_packet_dict_attr[]; fr_dict_attr_autoload_t util_packet_dict_attr[] = { @@ -55,6 +56,7 @@ fr_dict_attr_autoload_t util_packet_dict_attr[] = { { .out = &attr_net_dst_ip, .name = "Net.Dst.IP", .type = FR_TYPE_COMBO_IP_ADDR, .dict = &dict_freeradius }, { .out = &attr_net_dst_port, .name = "Net.Dst.Port", .type = FR_TYPE_UINT16, .dict = &dict_freeradius }, { .out = &attr_net_timestamp, .name = "Net.Timestamp", .type = FR_TYPE_DATE, .dict = &dict_freeradius }, + { .out = &attr_net_interface, .name = "Net.Interface", .type = FR_TYPE_STRING, .dict = &dict_freeradius }, { NULL } }; @@ -89,6 +91,9 @@ static int inet2pairs(TALLOC_CTX *ctx, fr_pair_list_t *list, int fr_packet_pairs_from_packet(TALLOC_CTX *ctx, fr_pair_list_t *list, fr_packet_t const *packet) { fr_pair_t *vp, *net, *tlv; +#ifdef WITH_IFINDEX_NAME_RESOLUTION + char if_name[IFNAMSIZ]; +#endif /* * Net @@ -116,6 +121,16 @@ int fr_packet_pairs_from_packet(TALLOC_CTX *ctx, fr_pair_list_t *list, fr_packet vp->vp_date = fr_time_to_unix_time(packet->timestamp); fr_pair_set_immutable(vp); +#ifdef WITH_IFINDEX_NAME_RESOLUTION + /* + * Interface + */ + if (!packet->socket.inet.ifindex) return 0; + if (fr_pair_find_or_append_by_da(net, &vp, &net->vp_group, attr_net_interface) < 0) return -1; + fr_ifname_from_ifindex(if_name, packet->socket.inet.ifindex); + fr_value_box_strdup(vp, &vp->data, NULL, if_name, false); +#endif + return 0; }