@@ -149,15 +149,23 @@ impl WireguardInterfaceApi for WireguardApiUserspace {
149
149
/// Assign IP address to network interface.
150
150
fn assign_address ( & self , address : & IpAddrMask ) -> Result < ( ) , WireguardInterfaceError > {
151
151
debug ! ( "Assigning address {address} to interface {}" , self . ifname) ;
152
+ let address_string = address. ip . to_string ( ) ;
153
+
152
154
let output = if cfg ! ( target_os = "macos" ) {
153
- // On macOS, interface is point-to-point and requires a pair of addresses
154
- let address_string = address. ip . to_string ( ) ;
155
- Command :: new ( "ifconfig" )
156
- . args ( [ & self . ifname , & address_string, & address_string] )
157
- . output ( ) ?
155
+ match address. ip {
156
+ IpAddr :: V4 ( _) => {
157
+ Command :: new ( "ifconfig" )
158
+ // On macOS ipv4, interface is point-to-point and requires a pair of addresses
159
+ . args ( [ & self . ifname , "inet" , & address_string, & address_string] )
160
+ . output ( ) ?
161
+ }
162
+ IpAddr :: V6 ( _) => Command :: new ( "ifconfig" )
163
+ . args ( [ & self . ifname , "inet6" , & address_string] )
164
+ . output ( ) ?,
165
+ }
158
166
} else {
159
167
Command :: new ( "ifconfig" )
160
- . args ( [ & self . ifname , & address . to_string ( ) ] )
168
+ . args ( [ & self . ifname , & address_string ] )
161
169
. output ( ) ?
162
170
} ;
163
171
check_command_output_status ( output) ?;
@@ -187,35 +195,35 @@ impl WireguardInterfaceApi for WireguardApiUserspace {
187
195
/// Add peer addresses to network routing table.
188
196
///
189
197
/// # Linux:
190
- /// On a Linux system, the `sysctl` command is required to work if using `0.0.0.0/0` or `::/0`.
191
- /// For every allowed IP, it runs:
192
- /// `ip <ip_version> route add <allowed_ip> dev <ifname>`
193
- /// `<ifname>` - interface name while creating api
194
- /// `<ip_version>` - `-4` or `-6` based on allowed ip type
198
+ /// On a Linux system, the `sysctl` command is required to work if using `0.0.0.0/0` or `::/0`.
199
+ /// For every allowed IP, it runs:
200
+ /// `ip <ip_version> route add <allowed_ip> dev <ifname>`
201
+ /// `<ifname>` - interface name while creating api
202
+ /// `<ip_version>` - `-4` or `-6` based on allowed ip type
195
203
/// `<allowed_ip>`- one of [Peer](crate::Peer) allowed ip
196
204
///
197
205
/// For `0.0.0.0/0` or `::/0` allowed IP, it runs belowed additional commands in order:
198
- /// - `ip <ip_version> route add 0.0.0.0/0 dev <ifname> table <fwmark>`
199
- /// `<fwmark>` - fwmark attribute of [Host](crate::Host) or 51820 default if value is `None`.
200
- /// `<ifname>` - Interface name.
201
- /// - `ip <ip_version> rule add not fwmark <fwmark> table <fwmark>`.
202
- /// - `ip <ip_version> rule add table main suppress_prefixlength 0`.
203
- /// - `sysctl -q net.ipv4.conf.all.src_valid_mark=1` - runs only for `0.0.0.0/0`.
204
- /// - `iptables-restore -n`. For `0.0.0.0/0` only.
205
- /// - `iptables6-restore -n`. For `::/0` only.
206
+ /// - `ip <ip_version> route add 0.0.0.0/0 dev <ifname> table <fwmark>`
207
+ /// `<fwmark>` - fwmark attribute of [Host](crate::Host) or 51820 default if value is `None`.
208
+ /// `<ifname>` - Interface name.
209
+ /// - `ip <ip_version> rule add not fwmark <fwmark> table <fwmark>`.
210
+ /// - `ip <ip_version> rule add table main suppress_prefixlength 0`.
211
+ /// - `sysctl -q net.ipv4.conf.all.src_valid_mark=1` - runs only for `0.0.0.0/0`.
212
+ /// - `iptables-restore -n`. For `0.0.0.0/0` only.
213
+ /// - `iptables6-restore -n`. For `::/0` only.
206
214
/// Based on IP type `<ip_version>` will be equal to `-4` or `-6`.
207
215
///
208
216
///
209
217
/// # macOS, FreeBSD:
210
- /// For every allowed IP, it runs:
211
- /// - `route -q -n add <inet> allowed_ip -interface if_name`
212
- /// `ifname` - interface name while creating api
218
+ /// For every allowed IP, it runs:
219
+ /// - `route -q -n add <inet> allowed_ip -interface if_name`
220
+ /// `ifname` - interface name while creating api
213
221
/// `allowed_ip`- one of [Peer](crate::Peer) allowed ip
214
222
/// For `0.0.0.0/0` or `::/0` allowed IP, it adds default routing and skips other routings.
215
- /// - `route -q -n add <inet> 0.0.0.0/1 -interface if_name`.
216
- /// - `route -q -n add <inet> 128.0.0.0/1 -interface if_name`.
217
- /// - `route -q -n add <inet> <endpoint> -gateway <gateway>`
218
- /// `<endpoint>` - Add routing for every unique Peer endpoint.
223
+ /// - `route -q -n add <inet> 0.0.0.0/1 -interface if_name`.
224
+ /// - `route -q -n add <inet> 128.0.0.0/1 -interface if_name`.
225
+ /// - `route -q -n add <inet> <endpoint> -gateway <gateway>`
226
+ /// `<endpoint>` - Add routing for every unique Peer endpoint.
219
227
/// `<gateway>`- Gateway extracted using `netstat -nr -f <inet>`.
220
228
fn configure_peer_routing ( & self , peers : & [ Peer ] ) -> Result < ( ) , WireguardInterfaceError > {
221
229
add_peer_routing ( peers, & self . ifname )
0 commit comments