@@ -4,7 +4,7 @@ use netlink_packet_core::{
44 NetlinkHeader , NetlinkMessage , NetlinkPayload , NLM_F_DUMP , NLM_F_REQUEST ,
55} ;
66use netlink_packet_route:: {
7- link:: { InfoKind , LinkAttribute , LinkExtentMask , LinkInfo , LinkMessage } ,
7+ link:: { InfoData , InfoKind , InfoVxlan , LinkAttribute , LinkExtentMask , LinkInfo , LinkMessage } ,
88 route:: { RouteAddress , RouteAttribute , RouteMessage , RouteType } ,
99 RouteNetlinkMessage ,
1010} ;
@@ -15,6 +15,7 @@ use std::{cmp::Reverse, collections::HashMap, net::IpAddr};
1515pub struct Interfaces {
1616 pub id2name : HashMap < u32 , String > ,
1717 pub wireguard_ids : Vec < u32 > ,
18+ pub vxlan_ports : HashMap < u16 , u32 > ,
1819}
1920
2021pub fn interface_names ( socket : & Socket ) -> Result < Interfaces > {
@@ -32,6 +33,7 @@ pub fn interface_names(socket: &Socket) -> Result<Interfaces> {
3233
3334 let mut map = HashMap :: new ( ) ;
3435 let mut wg_ids = Vec :: new ( ) ;
36+ let mut vxlan_ports = HashMap :: new ( ) ;
3537 drive_req ( packet, socket, |inner| {
3638 if let RouteNetlinkMessage :: NewLink ( nl) = inner {
3739 for nla in nl. attributes {
@@ -41,8 +43,18 @@ pub fn interface_names(socket: &Socket) -> Result<Interfaces> {
4143 }
4244 LinkAttribute :: LinkInfo ( infos) => {
4345 for info in infos {
44- if info == LinkInfo :: Kind ( InfoKind :: Wireguard ) {
45- wg_ids. push ( nl. header . index ) ;
46+ match info {
47+ LinkInfo :: Kind ( InfoKind :: Wireguard ) => {
48+ wg_ids. push ( nl. header . index ) ;
49+ }
50+ LinkInfo :: Data ( InfoData :: Vxlan ( data) ) => {
51+ for datum in data {
52+ if let InfoVxlan :: Port ( port) = datum {
53+ vxlan_ports. insert ( port, nl. header . index ) ;
54+ }
55+ }
56+ }
57+ _ => ( ) ,
4658 }
4759 }
4860 }
@@ -56,6 +68,7 @@ pub fn interface_names(socket: &Socket) -> Result<Interfaces> {
5668 Ok ( Interfaces {
5769 id2name : map,
5870 wireguard_ids : wg_ids,
71+ vxlan_ports,
5972 } )
6073}
6174
@@ -170,7 +183,6 @@ pub fn local_routes(socket: &Socket) -> Result<Rtbl> {
170183 _ => None ,
171184 } ) ;
172185 if let ( Some ( & iface) , Some ( dst) ) = ( iface, dst) {
173- // TODO: more anyhow, less expect/unreachable
174186 let dst = match * dst {
175187 RouteAddress :: Inet ( a) => IpAddr :: from ( a) ,
176188 RouteAddress :: Inet6 ( a) => IpAddr :: from ( a) ,
0 commit comments