@@ -3,7 +3,9 @@ use std::{
3
3
os:: fd:: AsRawFd ,
4
4
} ;
5
5
6
- use libc:: { c_char, kld_load, IFF_UP , IF_NAMESIZE } ;
6
+ #[ cfg( target_os = "freebsd" ) ]
7
+ use libc:: { c_char, kld_load} ;
8
+ use libc:: { IFF_UP , IF_NAMESIZE } ;
7
9
use nix:: { ioctl_readwrite, ioctl_write_ptr, sys:: socket:: AddressFamily } ;
8
10
9
11
use super :: {
@@ -20,11 +22,17 @@ ioctl_write_ptr!(destroy_clone_if, b'i', 121, IfReq);
20
22
// SIOCIFCREATE2
21
23
ioctl_readwrite ! ( create_clone_if, b'i' , 124 , IfReq ) ;
22
24
// SIOCAIFADDR
25
+ #[ cfg( target_os = "freebsd" ) ]
23
26
ioctl_write_ptr ! ( add_addr_if, b'i' , 43 , InAliasReq ) ;
27
+ #[ cfg( target_os = "macos" ) ]
28
+ ioctl_write_ptr ! ( add_addr_if, b'i' , 26 , InAliasReq ) ;
24
29
// SIOCDIFADDR
25
30
ioctl_write_ptr ! ( del_addr_if, b'i' , 25 , IfReq ) ;
26
31
// SIOCAIFADDR_IN6
32
+ #[ cfg( target_os = "freebsd" ) ]
27
33
ioctl_write_ptr ! ( add_addr_if_in6, b'i' , 27 , In6AliasReq ) ;
34
+ #[ cfg( target_os = "macos" ) ]
35
+ ioctl_write_ptr ! ( add_addr_if_in6, b'i' , 26 , In6AliasReq ) ;
28
36
// SIOCDIFADDR_IN6
29
37
ioctl_write_ptr ! ( del_addr_if_in6, b'i' , 25 , IfReq6 ) ;
30
38
// SIOCSIFFLAGS
@@ -51,14 +59,17 @@ impl IfReq {
51
59
52
60
// First, try to load a kernel module for this type of network interface.
53
61
// Omit digits at the end of interface name, e.g. "wg0" -> "if_wg".
54
- let index = if_name
55
- . find ( |c : char | c. is_ascii_digit ( ) )
56
- . unwrap_or ( if_name. len ( ) ) ;
57
- let mod_name = format ! ( "if_{}" , & if_name[ 0 ..index] ) ;
58
- unsafe {
59
- // Ignore the return value for the time being.
60
- // Do the cast because `c_char` differs across platforms.
61
- kld_load ( mod_name. as_ptr ( ) as * const c_char ) ;
62
+ #[ cfg( target_os = "freebsd" ) ]
63
+ {
64
+ let index = if_name
65
+ . find ( |c : char | c. is_ascii_digit ( ) )
66
+ . unwrap_or ( if_name. len ( ) ) ;
67
+ let mod_name = format ! ( "if_{}" , & if_name[ 0 ..index] ) ;
68
+ unsafe {
69
+ // Ignore the return value for the time being.
70
+ // Do the cast because `c_char` differs across platforms.
71
+ kld_load ( mod_name. as_ptr ( ) as * const c_char ) ;
72
+ }
62
73
}
63
74
64
75
Self {
@@ -87,7 +98,7 @@ impl IfReq {
87
98
Ok ( ( ) )
88
99
}
89
100
90
- pub ( super ) fn delete_address ( & mut self , addr : & Ipv4Addr ) -> Result < ( ) , IoError > {
101
+ pub ( super ) fn delete_address ( & mut self , addr : Ipv4Addr ) -> Result < ( ) , IoError > {
91
102
self . ifr_ifru = addr. into ( ) ;
92
103
93
104
let socket = create_socket ( AddressFamily :: Inet ) . map_err ( IoError :: WriteIo ) ?;
@@ -104,6 +115,7 @@ impl IfReq {
104
115
pub struct IfReq6 {
105
116
ifr_name : [ u8 ; IF_NAMESIZE ] ,
106
117
ifr_ifru : SockAddrIn6 ,
118
+ _padding : [ u8 ; 244 ] ,
107
119
}
108
120
109
121
impl IfReq6 {
@@ -119,10 +131,11 @@ impl IfReq6 {
119
131
Self {
120
132
ifr_name,
121
133
ifr_ifru : SockAddrIn6 :: default ( ) ,
134
+ _padding : [ 0u8 ; 244 ] ,
122
135
}
123
136
}
124
137
125
- pub ( super ) fn delete_address ( & mut self , addr : & Ipv6Addr ) -> Result < ( ) , IoError > {
138
+ pub ( super ) fn delete_address ( & mut self , addr : Ipv6Addr ) -> Result < ( ) , IoError > {
126
139
self . ifr_ifru = addr. into ( ) ;
127
140
128
141
let socket = create_socket ( AddressFamily :: Inet6 ) . map_err ( IoError :: WriteIo ) ?;
@@ -141,16 +154,17 @@ pub struct InAliasReq {
141
154
ifra_addr : SockAddrIn ,
142
155
ifra_broadaddr : SockAddrIn ,
143
156
ifra_mask : SockAddrIn ,
157
+ #[ cfg( target_os = "freebsd" ) ]
144
158
ifra_vhid : u32 ,
145
159
}
146
160
147
161
impl InAliasReq {
148
162
#[ must_use]
149
163
pub ( super ) fn new (
150
164
if_name : & str ,
151
- addr : & Ipv4Addr ,
152
- broadcast : & Ipv4Addr ,
153
- mask : & Ipv4Addr ,
165
+ address : Ipv4Addr ,
166
+ broadcast : Ipv4Addr ,
167
+ mask : Ipv4Addr ,
154
168
) -> Self {
155
169
let mut ifr_name = [ 0u8 ; IF_NAMESIZE ] ;
156
170
if_name
@@ -161,9 +175,10 @@ impl InAliasReq {
161
175
162
176
Self {
163
177
ifr_name,
164
- ifra_addr : addr . into ( ) ,
178
+ ifra_addr : address . into ( ) ,
165
179
ifra_broadaddr : broadcast. into ( ) ,
166
180
ifra_mask : mask. into ( ) ,
181
+ #[ cfg( target_os = "freebsd" ) ]
167
182
ifra_vhid : 0 ,
168
183
}
169
184
}
@@ -192,16 +207,17 @@ pub struct In6AliasReq {
192
207
ia6t_preferred : u64 ,
193
208
ia6t_vltime : u32 ,
194
209
ia6t_pltime : u32 ,
210
+ #[ cfg( target_os = "freebsd" ) ]
195
211
ifra_vhid : u32 ,
196
212
}
197
213
198
214
impl In6AliasReq {
199
215
#[ must_use]
200
216
pub ( super ) fn new (
201
217
if_name : & str ,
202
- address : & Ipv6Addr ,
203
- dstaddr : & Ipv6Addr ,
204
- prefixmask : & Ipv6Addr ,
218
+ address : Ipv6Addr ,
219
+ // FIXME: currenlty unused: dstaddr: Ipv6Addr,
220
+ prefixmask : Ipv6Addr ,
205
221
) -> Self {
206
222
let mut ifr_name = [ 0u8 ; IF_NAMESIZE ] ;
207
223
if_name
@@ -213,13 +229,14 @@ impl In6AliasReq {
213
229
Self {
214
230
ifr_name,
215
231
ifra_addr : address. into ( ) ,
216
- ifra_dstaddr : dstaddr . into ( ) ,
232
+ ifra_dstaddr : SockAddrIn6 :: zeroed ( ) ,
217
233
ifra_prefixmask : prefixmask. into ( ) ,
218
234
ifra_flags : 0 ,
219
235
ia6t_expire : 0 ,
220
236
ia6t_preferred : 0 ,
221
237
ia6t_vltime : ND6_INFINITE_LIFETIME ,
222
238
ia6t_pltime : ND6_INFINITE_LIFETIME ,
239
+ #[ cfg( target_os = "freebsd" ) ]
223
240
ifra_vhid : 0 ,
224
241
}
225
242
}
0 commit comments