@@ -8,7 +8,7 @@ use byteorder::{ByteOrder, NativeEndian};
8
8
use netlink_packet_utils:: {
9
9
nla:: { DefaultNla , Nla , NlaBuffer } ,
10
10
parsers:: { parse_u16, parse_u32, parse_u8} ,
11
- traits:: Parseable ,
11
+ traits:: { Parseable , ParseableParametrized } ,
12
12
DecodeError ,
13
13
} ;
14
14
@@ -146,8 +146,13 @@ impl Nla for InfoIpTunnel {
146
146
}
147
147
}
148
148
149
- impl < ' a , T : AsRef < [ u8 ] > + ?Sized > Parseable < NlaBuffer < & ' a T > > for InfoIpTunnel {
150
- fn parse ( buf : & NlaBuffer < & ' a T > ) -> Result < Self , DecodeError > {
149
+ impl < ' a , T : AsRef < [ u8 ] > + ?Sized >
150
+ ParseableParametrized < NlaBuffer < & ' a T > , super :: InfoKind > for InfoIpTunnel
151
+ {
152
+ fn parse_with_param (
153
+ buf : & NlaBuffer < & ' a T > ,
154
+ kind : super :: InfoKind ,
155
+ ) -> Result < Self , DecodeError > {
151
156
use self :: InfoIpTunnel :: * ;
152
157
let payload = buf. value ( ) ;
153
158
Ok ( match buf. kind ( ) {
@@ -202,13 +207,26 @@ impl<'a, T: AsRef<[u8]> + ?Sized> Parseable<NlaBuffer<&'a T>> for InfoIpTunnel {
202
207
parse_u32 ( payload)
203
208
. context ( "invalid IFLA_IPTUN_FLOWINFO value" ) ?,
204
209
) ,
205
- IFLA_IPTUN_FLAGS => Flags ( TunnelFlags :: from_bits_retain (
206
- parse_u32 ( payload) . context ( "invalid IFLA_IPTUN_FLAGS value" ) ?,
207
- ) ) ,
208
- IFLA_IPTUN_PROTO => Protocol ( IpProtocol :: from (
209
- parse_u8 ( payload) . context ( "invalid IFLA_IPTUN_PROTO value" ) ?
210
- as i32 ,
211
- ) ) ,
210
+ IFLA_IPTUN_FLAGS => match kind {
211
+ super :: InfoKind :: SitTun => {
212
+ // Parse as u16 for SIT tunnels
213
+ Flags ( TunnelFlags :: from_bits_retain ( u32:: from (
214
+ parse_u16 ( payload) . context (
215
+ "invalid IFLA_IPTUN_FLAGS value for SIT" ,
216
+ ) ?,
217
+ ) ) )
218
+ }
219
+ _ => {
220
+ // Default: parse as u32 for other tunnel types
221
+ Flags ( TunnelFlags :: from_bits_retain (
222
+ parse_u32 ( payload)
223
+ . context ( "invalid IFLA_IPTUN_FLAGS value" ) ?,
224
+ ) )
225
+ }
226
+ } ,
227
+ IFLA_IPTUN_PROTO => Protocol ( IpProtocol :: from ( i32:: from (
228
+ parse_u8 ( payload) . context ( "invalid IFLA_IPTUN_PROTO value" ) ?,
229
+ ) ) ) ,
212
230
IFLA_IPTUN_PMTUDISC => PMtuDisc (
213
231
parse_u8 ( payload)
214
232
. context ( "invalid IFLA_IPTUN_PMTUDISC value" ) ?
0 commit comments