@@ -10,8 +10,12 @@ use wire::{ArpPacket, ArpRepr, ArpOperation};
10
10
use wire:: { Ipv4Packet , Ipv4Repr } ;
11
11
use wire:: { Icmpv4Packet , Icmpv4Repr , Icmpv4DstUnreachable } ;
12
12
use wire:: { IpAddress , IpProtocol , IpRepr } ;
13
- use wire:: { UdpPacket , UdpRepr , TcpPacket , TcpRepr , TcpControl } ;
14
- use socket:: { Socket , SocketSet , RawSocket , TcpSocket , UdpSocket , AsSocket } ;
13
+ #[ cfg( feature = "socket-udp" ) ] use wire:: { UdpPacket , UdpRepr } ;
14
+ #[ cfg( feature = "socket-tcp" ) ] use wire:: { TcpPacket , TcpRepr , TcpControl } ;
15
+ use socket:: { Socket , SocketSet , AsSocket } ;
16
+ #[ cfg( feature = "socket-raw" ) ] use socket:: RawSocket ;
17
+ #[ cfg( feature = "socket-udp" ) ] use socket:: UdpSocket ;
18
+ #[ cfg( feature = "socket-tcp" ) ] use socket:: TcpSocket ;
15
19
use super :: ArpCache ;
16
20
17
21
/// An Ethernet network interface.
@@ -30,8 +34,11 @@ enum Packet<'a> {
30
34
None ,
31
35
Arp ( ArpRepr ) ,
32
36
Icmpv4 ( Ipv4Repr , Icmpv4Repr < ' a > ) ,
37
+ #[ cfg( feature = "socket-raw" ) ]
33
38
Raw ( ( IpRepr , & ' a [ u8 ] ) ) ,
39
+ #[ cfg( feature = "socket-udp" ) ]
34
40
Udp ( ( IpRepr , UdpRepr < ' a > ) ) ,
41
+ #[ cfg( feature = "socket-tcp" ) ]
35
42
Tcp ( ( IpRepr , TcpRepr < ' a > ) )
36
43
}
37
44
@@ -169,22 +176,25 @@ impl<'a, 'b, 'c, DeviceT: Device + 'a> Interface<'a, 'b, 'c, DeviceT> {
169
176
let mut device_result = Ok ( ( ) ) ;
170
177
let socket_result =
171
178
match socket {
179
+ #[ cfg( feature = "socket-raw" ) ]
172
180
& mut Socket :: Raw ( ref mut socket) =>
173
181
socket. dispatch ( |response| {
174
182
device_result = self . dispatch ( timestamp, Packet :: Raw ( response) ) ;
175
183
device_result
176
184
} ) ,
185
+ #[ cfg( feature = "socket-udp" ) ]
177
186
& mut Socket :: Udp ( ref mut socket) =>
178
187
socket. dispatch ( |response| {
179
188
device_result = self . dispatch ( timestamp, Packet :: Udp ( response) ) ;
180
189
device_result
181
190
} ) ,
191
+ #[ cfg( feature = "socket-tcp" ) ]
182
192
& mut Socket :: Tcp ( ref mut socket) =>
183
193
socket. dispatch ( timestamp, & limits, |response| {
184
194
device_result = self . dispatch ( timestamp, Packet :: Tcp ( response) ) ;
185
195
device_result
186
196
} ) ,
187
- & mut Socket :: __Nonexhaustive => unreachable ! ( )
197
+ & mut Socket :: __Nonexhaustive( _ ) => unreachable ! ( )
188
198
} ;
189
199
match ( device_result, socket_result) {
190
200
( Err ( Error :: Unaddressable ) , _) => break , // no one to transmit to
@@ -285,8 +295,11 @@ impl<'a, 'b, 'c, DeviceT: Device + 'a> Interface<'a, 'b, 'c, DeviceT> {
285
295
let ip_repr = IpRepr :: Ipv4 ( ipv4_repr) ;
286
296
let ip_payload = ipv4_packet. payload ( ) ;
287
297
288
- // Pass every IP packet to all raw sockets we have registered.
298
+ # [ cfg ( feature = "socket- raw" ) ]
289
299
let mut handled_by_raw_socket = false ;
300
+
301
+ // Pass every IP packet to all raw sockets we have registered.
302
+ #[ cfg( feature = "socket-raw" ) ]
290
303
for raw_socket in sockets. iter_mut ( ) . filter_map (
291
304
<Socket as AsSocket < RawSocket > >:: try_as_socket) {
292
305
if !raw_socket. accepts ( & ip_repr) { continue }
@@ -309,12 +322,19 @@ impl<'a, 'b, 'c, DeviceT: Device + 'a> Interface<'a, 'b, 'c, DeviceT> {
309
322
match ipv4_repr. protocol {
310
323
IpProtocol :: Icmp =>
311
324
Self :: process_icmpv4 ( ipv4_repr, ip_payload) ,
325
+
326
+ #[ cfg( feature = "socket-udp" ) ]
312
327
IpProtocol :: Udp =>
313
328
Self :: process_udp ( sockets, ip_repr, ip_payload) ,
329
+
330
+ #[ cfg( feature = "socket-tcp" ) ]
314
331
IpProtocol :: Tcp =>
315
332
Self :: process_tcp ( sockets, timestamp, ip_repr, ip_payload) ,
333
+
334
+ #[ cfg( feature = "socket-raw" ) ]
316
335
_ if handled_by_raw_socket =>
317
336
Ok ( Packet :: None ) ,
337
+
318
338
_ => {
319
339
let icmp_reply_repr = Icmpv4Repr :: DstUnreachable {
320
340
reason : Icmpv4DstUnreachable :: ProtoUnreachable ,
@@ -362,6 +382,7 @@ impl<'a, 'b, 'c, DeviceT: Device + 'a> Interface<'a, 'b, 'c, DeviceT> {
362
382
}
363
383
}
364
384
385
+ #[ cfg( feature = "socket-udp" ) ]
365
386
fn process_udp < ' frame > ( sockets : & mut SocketSet ,
366
387
ip_repr : IpRepr , ip_payload : & ' frame [ u8 ] ) ->
367
388
Result < Packet < ' frame > > {
@@ -403,6 +424,7 @@ impl<'a, 'b, 'c, DeviceT: Device + 'a> Interface<'a, 'b, 'c, DeviceT> {
403
424
}
404
425
}
405
426
427
+ #[ cfg( feature = "socket-tcp" ) ]
406
428
fn process_tcp < ' frame > ( sockets : & mut SocketSet , timestamp : u64 ,
407
429
ip_repr : IpRepr , ip_payload : & ' frame [ u8 ] ) ->
408
430
Result < Packet < ' frame > > {
@@ -454,17 +476,20 @@ impl<'a, 'b, 'c, DeviceT: Device + 'a> Interface<'a, 'b, 'c, DeviceT> {
454
476
icmpv4_repr. emit ( & mut Icmpv4Packet :: new ( payload) ) ;
455
477
} )
456
478
}
479
+ #[ cfg( feature = "socket-raw" ) ]
457
480
Packet :: Raw ( ( ip_repr, raw_packet) ) => {
458
481
self . dispatch_ip ( timestamp, ip_repr, |_ip_repr, payload| {
459
482
payload. copy_from_slice ( raw_packet) ;
460
483
} )
461
484
}
485
+ #[ cfg( feature = "socket-udp" ) ]
462
486
Packet :: Udp ( ( ip_repr, udp_repr) ) => {
463
487
self . dispatch_ip ( timestamp, ip_repr, |ip_repr, payload| {
464
488
udp_repr. emit ( & mut UdpPacket :: new ( payload) ,
465
489
& ip_repr. src_addr ( ) , & ip_repr. dst_addr ( ) ) ;
466
490
} )
467
491
}
492
+ #[ cfg( feature = "socket-tcp" ) ]
468
493
Packet :: Tcp ( ( ip_repr, mut tcp_repr) ) => {
469
494
let limits = self . device . limits ( ) ;
470
495
self . dispatch_ip ( timestamp, ip_repr, |ip_repr, payload| {
1 commit comments
whitequark commentedon Sep 25, 2017
cc @briansmith