XenevaOS
Loading...
Searching...
No Matches
aunet.h
Go to the documentation of this file.
1
30#ifndef __AUNET_H__
31#define __AUNET_H__
32
33#include <stdint.h>
34#include <aurora.h>
35#include <Fs/vfs.h>
36#include <Net/ipv6.h>
37
38#define NETDEV_TYPE_ETHERNET 1
39#define NETDEV_TYPE_802_11 2
40#define NETDEV_TYPE_BLUETOOTH 3
41#define NETDEV_TYPE_LOOPBACK 4
42
43/* Wire/MAKE_IP form used by NIC ipv4addr and on-wire headers (LE host). */
44#ifndef MAKE_IP
45#define MAKE_IP(a, b, c, d) \
46 ((uint32_t)(d) << 24 | (uint32_t)(c) << 16 | (uint32_t)(b) << 8 | (uint32_t)(a))
47#endif
48
49#ifdef ARCH_X64
50#pragma pack(push,1)
51#endif
67#ifdef ARCH_X64
68#pragma pack(pop)
69#endif
70
71
72#define htonl(l) ((((l) & 0xFF) << 24) | (((l) & 0xFF00) << 8) | (((l) & 0xFF0000) >> 8) | (((l) & 0xFF000000) >> 24))
73#define htons(s) ((((s) & 0xFF) << 8) | (((s) & 0xFF00) >> 8))
74#define ntohl(l) htonl((l))
75#define ntohs(s) htons((s))
76
77/*I/O Codes used for network interfaces */
78#define AUNET_GET_HARDWARE_ADDRESS 0x100
79#define AUNET_SET_IPV4_ADDRESS 0x101
80#define AUNET_GET_IPV4_ADDRESS 0x102
81#define AUNET_GET_GATEWAY_ADDRESS 0x103
82#define AUNET_SET_GATEWAY_ADDRESS 0x104
83#define AUNET_GET_SUBNET_MASK 0x105
84#define AUNET_SET_SUBNET_MASK 0x106
85#define AUNET_GET_LINK_STATUS 0x107
86#define AUNET_GET_IPV6_ADDRESS 0x108
87#define AUNET_SET_IPV6_ADDRESS 0x109
88#define AUNET_GET_IPV6_GATEWAY 0x10A
89#define AUNET_SET_IPV6_GATEWAY 0x10B
90#define AUNET_GET_IPV6_PREFIX 0x10C
91#define AUNET_SET_IPV6_PREFIX 0x10D
92
93/* 802.11 station ioctls (IEEE 802.11-2020). Arg is Wifi* from Net/wifi.h. */
94#define WIFI_SCAN 0x140
95#define WIFI_GET_SCAN 0x141
96#define WIFI_CONNECT 0x142
97#define WIFI_DISCONNECT 0x143
98#define WIFI_GET_STATUS 0x144
99#define WIFI_UPLINK 0x145
100
101/*
102* AuInitialiseNet -- initialise network data structures
103*/
104extern void AuInitialiseNet();
105
106/*
107* AuAddNetAdapter -- add a net adapter to the adapter
108* list
109*/
111
112/*
113* AuRemoveNetAdapter -- the driver behind an adapter is going away; the node
114* stays but goes dead (see aunet.c)
115*/
117/*
118* AuGetNetworkAdapter -- get a network adapter
119* @param name -- adapter name
120*/
122
123/*
124 * AuNetworkRoute -- select NIC via FIB (RFC 1122 §3.3.1).
125 * Local/127/8 → lo. FIB hit → that NIC. Miss → NULL (ENETUNREACH).
126 */
127extern AuVFSNode* AuNetworkRoute(uint32_t address);
128
129/*
130 * AuNetworkRoute6 -- select NIC for an IPv6 destination.
131 * Miss → NULL (no silent virtio-net fallback).
132 */
133extern AuVFSNode* AuNetworkRoute6(const ip6_addr* address);
134
135/* Local-address checks (127/8, ::1, or any configured NIC address). */
136extern int AuAddrIsLocal4(uint32_t address);
137extern int AuAddrIsLocal6(const ip6_addr* address);
138
139/* Install connected / default routes after address/gateway ioctl. */
140AU_EXTERN AU_EXPORT void AuNetAddConnectedRoute4(AuVFSNode* nic, const char* ifname);
141AU_EXTERN AU_EXPORT void AuNetAddConnectedRoute6(AuVFSNode* nic, const char* ifname);
142AU_EXTERN AU_EXPORT void AuNetAddDefaultRoute4(AuVFSNode* nic, const char* ifname);
143AU_EXTERN AU_EXPORT void AuNetAddDefaultRoute6(AuVFSNode* nic, const char* ifname);
144
145/* Global nameserver table (not tied to a bound NIC). Index is 1-based. */
146#define AU_DNS_MAX4 4
147#define AU_DNS_MAX6 2
150extern int AuDnsGetServer4(int index, uint32_t* out);
152AU_EXTERN AU_EXPORT void AuDnsSetServer6(int index, const ip6_addr* addr);
153extern int AuDnsGetServer6(int index, ip6_addr* out);
154
155/* Driver registers so socket recv can drain RX while userspace waits. */
156AU_EXTERN AU_EXPORT void AuNetRegisterRxPoll(void (*fn)(void));
158
159#endif
#define AU_EXTERN
Definition aurora.h:54
#define AU_EXPORT
Definition aurora.h:40
#define index(str, chr)
Definition string.h:66
#define out(...)
Definition main.cpp:65
unsigned int uint32_t
Definition acefiex.h:163
unsigned char uint8_t
Definition acefiex.h:161
void * fn
Definition audrv.c:980
AU_EXTERN AU_EXPORT int AuRemoveNetAdapter(char *name)
AuRemoveNetAdapter – the driver behind an adapter is going away. The node itself stays (open handles ...
Definition aunet.c:333
int AuAddrIsLocal4(uint32_t address)
Definition aunet.cpp:82
AuVFSNode * AuNetworkRoute(uint32_t address)
AuNetworkRoute – select NIC for an IPv4 destination.
Definition aunet.cpp:121
AU_EXTERN AU_EXPORT void AuNetRxPoll(void)
Definition aunet.c:57
AU_EXTERN AU_EXPORT void AuDnsAddServer6(const ip6_addr *addr)
Definition aunet.c:96
int AuDnsGetServer6(int index, ip6_addr *out)
Definition aunet.c:119
AuVFSNode * AuNetworkRoute6(const ip6_addr *address)
Definition aunet.cpp:132
struct _netdev_ AuNetworkDevice
int AuDnsGetServer4(int index, uint32_t *out)
Definition aunet.c:89
void AuInitialiseNet()
AuInitialiseNet – initialise network data structures.
Definition aunet.cpp:48
AU_EXTERN AU_EXPORT void AuDnsAddServer4(uint32_t addr)
Definition aunet.c:66
int AuAddrIsLocal6(const ip6_addr *address)
Definition aunet.cpp:90
AU_EXTERN AU_EXPORT void AuDnsSetServer6(int index, const ip6_addr *addr)
Definition aunet.c:113
struct drm_crtc struct drm_plane struct drm_plane const struct drm_crtc_funcs const char * name
Definition drm_crtc.h:1242
AuVFSNode * nic
Definition e1000.cpp:67
void AuNetAddDefaultRoute6(void)
void AuNetRegisterRxPoll(void)
void AuGetNetworkAdapter(void)
void AuNetAddConnectedRoute4(void)
void AuAddNetAdapter(void)
void AuNetAddConnectedRoute6(void)
void AuDnsSetServer4(void)
void AuNetAddDefaultRoute4(void)
Definition vfs.h:129
Definition ipv6.h:45
Definition aunet.h:52
int linkStatus
Definition aunet.h:54
uint8_t ipv6prefixLen
Definition aunet.h:64
uint32_t dns_ipv4_2
Definition aunet.h:60
uint32_t ipv4addr
Definition aunet.h:56
uint8_t type
Definition aunet.h:55
uint32_t ipv4gateway
Definition aunet.h:58
uint32_t dns_ipv4_1
Definition aunet.h:59
uint8_t mac[6]
Definition aunet.h:53
uint32_t dns_ipv4_3
Definition aunet.h:61
ip6_addr ipv6gateway
Definition aunet.h:63
ip6_addr dns_ipv6_1
Definition aunet.h:65
ip6_addr ipv6addr
Definition aunet.h:62
uint32_t ipv4subnet
Definition aunet.h:57