Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/aienux/blob/main/native/kernel/dev/net_udp.h # aienux Aienux, the AienOS kernel: boot, scheduling, IPC and capability boundaries. Pre-alpha; host, emulator and physical evidence are labelled separately. Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `aienux / native / kernel / dev / net_udp.h` 70 lines ยท 3408 bytes Raw Blame History 1 /* SPDX-License-Identifier: Apache-2.0 2 * Copyright 2026 Drake Stapleton (AIEN / aien-dev) 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 /* net_udp.h -- the C kernel's UDP round-trip frames over the M6-A protocol 18 * layer (native/net/aienos_net.h): ARP for the gateway, one UDP datagram 19 * out, one UDP datagram back. Pure functions over caller buffers (no device, 20 * no clock), so they are host-tested in svc/tests/stage_test.c. 21 * 22 * Addresses are QEMU user networking (slirp) defaults: guest 10.0.2.15, 23 * gateway/host 10.0.2.2. Slirp forwards a datagram for 10.0.2.2:PORT to the 24 * host's 127.0.0.1:PORT (scripts/qemu_ck_net_test.sh runs the echo helper 25 * native/kernel/tools/ck_udp_echo.c there). QEMU is not hardware. */ 26 #ifndef AIENOS_CK_NET_UDP_H 27 #define AIENOS_CK_NET_UDP_H 28 #include 29 #include 30 #include "aienos_net.h" 31 32 #define CK_NET_ECHO_PORT 47029u /* host helper port (scripts read this line) */ 33 #define CK_NET_LOCAL_PORT 47030u /* guest source port */ 34 35 typedef struct { 36 net_mac mac; /* ours (virtio-net config) */ 37 net_ipv4 ip; /* ours */ 38 net_mac gw_mac; /* learned from the ARP reply */ 39 net_ipv4 gw_ip; 40 uint16_t lport, rport; 41 } ck_net_peer; 42 43 /* Frame builders: bytes written, 0 when the buffer is too small or an 44 * argument is bad. */ 45 size_t ck_net_arp_request(const ck_net_peer *p, uint8_t *out, size_t cap); 46 /* ARP reply to `req` (a request for p->ip), sent to its sender. */ 47 size_t ck_net_arp_reply(const ck_net_peer *p, const net_arp_packet *req, uint8_t *out, size_t cap); 48 /* Ethernet + IPv4 + UDP from p->ip:lport to p->gw_ip:rport via p->gw_mac. */ 49 size_t ck_net_udp_frame(const ck_net_peer *p, uint16_t ip_id, const uint8_t *data, size_t n, uint8_t *out, 50 size_t cap); 51 52 typedef enum { 53 CK_NET_IGNORED = 0, /* not for us, malformed, or not what we wait for */ 54 CK_NET_ARP_GW = 1, /* ARP reply from gw_ip to us: *mac = gateway MAC */ 55 CK_NET_ARP_ASK = 2, /* ARP request for our ip: *arp = the request */ 56 CK_NET_UDP_REPLY = 3, /* UDP gw_ip:rport -> ip:lport, checksum ok: payload view */ 57 } ck_net_kind; 58 59 /* Classify one received frame (Ethernet, no FCS). Every field is checked by 60 * the M6-A parsers; anything else is CK_NET_IGNORED. A gateway MAC that is 61 * zero, broadcast or multicast is ignored. For CK_NET_UDP_REPLY, *csum = 1 62 * when the datagram carried a UDP checksum (verified by net_udp_parse), 0 63 * when it carried none (allowed for UDP over IPv4). */ 64 ck_net_kind ck_net_classify(const ck_net_peer *p, const uint8_t *frame, size_t len, net_mac *mac, 65 net_arp_packet *arp, const uint8_t **payload, size_t *payload_len, int *csum); 66 67 /* Copy at most cap-1 bytes of `b` as printable ASCII ('.' for anything 68 * else, '\'' for '"' and '\\'), NUL-terminated. */ 69 void ck_net_printable(const uint8_t *b, size_t n, char *out, size_t cap); 70 #endif