rust-kernel
Rustbelt: a hobby x86_64 kernel written in Rust
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 | //! The one "device" smoltcp talks to: the virtio-net card (if there is
//! one) *plus* a loopback queue.
//!
//! **Loopback.** Programs talk to themselves over the network all the
//! time: a database on 127.0.0.1, a test client and server, a compositor
//! and its clients. Linux has a separate `lo` interface for that. We keep
//! smoltcp's single Ethernet interface and give it a second address,
//! 127.0.0.1/8, next to DHCP's. Then this device does the trick: a frame
//! meant for *ourselves* never goes to the card, it's put on the `lo`
//! queue, and `receive` hands queued frames back to smoltcp first.
//! "Meant for ourselves" is:
//! * an ARP request asking who has 127.x.x.x or our own DHCP address
//! (smoltcp then answers itself: "that's me", with its own MAC), and
//! * any frame sent to our own MAC address.
//! So 127.0.0.1 works with no network card at all (MAC 02:00:00:00:00:01,
//! a "locally administered" one), and connecting to our own 10.0.2.15
//! doesn't leave the machine either, just like Linux.
use ;
use VecDeque;
use vec;
use Vec;
use ;
use Instant;
/// Our MAC when there's no card.
pub const LOOPBACK_MAC: = ;
/// Frames waiting on lo at most (more are dropped, like a full queue).
const LO_QUEUE: usize = 256;
// smoltcp asks a `Device` for *tokens*: an RxToken is "a received frame you
// may look at", a TxToken is "permission to build one frame to send".
;
;
|