[59157eb] | 1 | /*
|
---|
[1bbc6dc] | 2 | * Copyright (c) 2024 Jiri Svoboda
|
---|
[59157eb] | 3 | * All rights reserved.
|
---|
| 4 | *
|
---|
| 5 | * Redistribution and use in source and binary forms, with or without
|
---|
| 6 | * modification, are permitted provided that the following conditions
|
---|
| 7 | * are met:
|
---|
| 8 | *
|
---|
| 9 | * - Redistributions of source code must retain the above copyright
|
---|
| 10 | * notice, this list of conditions and the following disclaimer.
|
---|
| 11 | * - Redistributions in binary form must reproduce the above copyright
|
---|
| 12 | * notice, this list of conditions and the following disclaimer in the
|
---|
| 13 | * documentation and/or other materials provided with the distribution.
|
---|
| 14 | * - The name of the author may not be used to endorse or promote products
|
---|
| 15 | * derived from this software without specific prior written permission.
|
---|
| 16 | *
|
---|
| 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
---|
| 18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
---|
| 19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
---|
| 20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
---|
| 21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
---|
| 22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
---|
| 23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
---|
| 24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
| 25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
---|
| 26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
| 27 | */
|
---|
| 28 |
|
---|
[b4ec1ea] | 29 | /** @addtogroup inetsrv
|
---|
[59157eb] | 30 | * @{
|
---|
| 31 | */
|
---|
| 32 | /**
|
---|
| 33 | * @file
|
---|
| 34 | * @brief
|
---|
| 35 | */
|
---|
| 36 |
|
---|
[b4ec1ea] | 37 | #ifndef INETSRV_H_
|
---|
| 38 | #define INETSRV_H_
|
---|
[59157eb] | 39 |
|
---|
| 40 | #include <adt/list.h>
|
---|
[3e6a98c5] | 41 | #include <stdbool.h>
|
---|
[1c7ba2da] | 42 | #include <inet/addr.h>
|
---|
[b4edc96] | 43 | #include <inet/eth_addr.h>
|
---|
[ceba4bed] | 44 | #include <inet/iplink.h>
|
---|
| 45 | #include <ipc/loc.h>
|
---|
[1bbc6dc] | 46 | #include <sif.h>
|
---|
[8d2dd7f2] | 47 | #include <stddef.h>
|
---|
| 48 | #include <stdint.h>
|
---|
[b8b1adb1] | 49 | #include <types/inet.h>
|
---|
[59157eb] | 50 | #include <async.h>
|
---|
| 51 |
|
---|
| 52 | /** Inet Client */
|
---|
| 53 | typedef struct {
|
---|
| 54 | async_sess_t *sess;
|
---|
| 55 | uint8_t protocol;
|
---|
| 56 | link_t client_list;
|
---|
| 57 | } inet_client_t;
|
---|
| 58 |
|
---|
[6428115] | 59 | /** Inetping Client */
|
---|
| 60 | typedef struct {
|
---|
| 61 | /** Callback session */
|
---|
| 62 | async_sess_t *sess;
|
---|
| 63 | /** Session identifier */
|
---|
| 64 | uint16_t ident;
|
---|
| 65 | /** Link to client list */
|
---|
| 66 | link_t client_list;
|
---|
| 67 | } inetping_client_t;
|
---|
| 68 |
|
---|
[1d24ad3] | 69 | /** Inetping6 Client */
|
---|
| 70 | typedef struct {
|
---|
| 71 | /** Callback session */
|
---|
| 72 | async_sess_t *sess;
|
---|
| 73 | /** Session identifier */
|
---|
| 74 | uint16_t ident;
|
---|
| 75 | /** Link to client list */
|
---|
| 76 | link_t client_list;
|
---|
| 77 | } inetping6_client_t;
|
---|
| 78 |
|
---|
[fe4310f] | 79 | typedef struct {
|
---|
[8d48c7e] | 80 | /** Local link ID */
|
---|
| 81 | service_id_t link_id;
|
---|
[7f95c904] | 82 | /** Source address */
|
---|
[fe4310f] | 83 | inet_addr_t src;
|
---|
[7f95c904] | 84 | /** Destination address */
|
---|
[fe4310f] | 85 | inet_addr_t dest;
|
---|
[7f95c904] | 86 | /** Type of service */
|
---|
[fe4310f] | 87 | uint8_t tos;
|
---|
[7f95c904] | 88 | /** Protocol */
|
---|
[fe4310f] | 89 | uint8_t proto;
|
---|
[7f95c904] | 90 | /** Time to live */
|
---|
[fe4310f] | 91 | uint8_t ttl;
|
---|
[7f95c904] | 92 | /** Identifier */
|
---|
[313824a] | 93 | uint32_t ident;
|
---|
[7f95c904] | 94 | /** Do not fragment */
|
---|
| 95 | bool df;
|
---|
| 96 | /** More fragments */
|
---|
| 97 | bool mf;
|
---|
| 98 | /** Offset of fragment into datagram, in bytes */
|
---|
| 99 | size_t offs;
|
---|
| 100 | /** Packet data */
|
---|
[fe4310f] | 101 | void *data;
|
---|
[7f95c904] | 102 | /** Packet data size in bytes */
|
---|
[fe4310f] | 103 | size_t size;
|
---|
| 104 | } inet_packet_t;
|
---|
| 105 |
|
---|
[ceba4bed] | 106 | typedef struct {
|
---|
| 107 | link_t link_list;
|
---|
| 108 | service_id_t svc_id;
|
---|
| 109 | char *svc_name;
|
---|
| 110 | async_sess_t *sess;
|
---|
| 111 | iplink_t *iplink;
|
---|
[347768d] | 112 | size_t def_mtu;
|
---|
[b4edc96] | 113 | eth_addr_t mac;
|
---|
[a17356fd] | 114 | bool mac_valid;
|
---|
[ceba4bed] | 115 | } inet_link_t;
|
---|
| 116 |
|
---|
[1bbc6dc] | 117 | /** Link information needed for autoconfiguration */
|
---|
[ceba4bed] | 118 | typedef struct {
|
---|
[1bbc6dc] | 119 | service_id_t svc_id;
|
---|
| 120 | char *svc_name;
|
---|
| 121 | } inet_link_cfg_info_t;
|
---|
| 122 |
|
---|
| 123 | /** Address object */
|
---|
| 124 | typedef struct {
|
---|
| 125 | /** Link to list of addresses */
|
---|
[ceba4bed] | 126 | link_t addr_list;
|
---|
[1bbc6dc] | 127 | /** Address object ID */
|
---|
[0e94b979] | 128 | sysarg_t id;
|
---|
[1bbc6dc] | 129 | /** Network address */
|
---|
[ceba4bed] | 130 | inet_naddr_t naddr;
|
---|
[1bbc6dc] | 131 | /** Underlying IP link */
|
---|
[ceba4bed] | 132 | inet_link_t *ilink;
|
---|
[1bbc6dc] | 133 | /** Address name */
|
---|
[0e94b979] | 134 | char *name;
|
---|
[1bbc6dc] | 135 | /** Temporary object */
|
---|
| 136 | bool temp;
|
---|
[ceba4bed] | 137 | } inet_addrobj_t;
|
---|
| 138 |
|
---|
[8bf672d] | 139 | /** Static route configuration */
|
---|
| 140 | typedef struct {
|
---|
| 141 | link_t sroute_list;
|
---|
[1bbc6dc] | 142 | /** ID */
|
---|
[8bf672d] | 143 | sysarg_t id;
|
---|
| 144 | /** Destination network */
|
---|
| 145 | inet_naddr_t dest;
|
---|
| 146 | /** Router via which to route packets */
|
---|
| 147 | inet_addr_t router;
|
---|
[1bbc6dc] | 148 | /** Route name */
|
---|
[8bf672d] | 149 | char *name;
|
---|
[1bbc6dc] | 150 | /** Temporary route */
|
---|
| 151 | bool temp;
|
---|
[8bf672d] | 152 | } inet_sroute_t;
|
---|
| 153 |
|
---|
| 154 | typedef enum {
|
---|
| 155 | /** Destination is on this network node */
|
---|
| 156 | dt_local,
|
---|
| 157 | /** Destination is directly reachable */
|
---|
| 158 | dt_direct,
|
---|
| 159 | /** Destination is behind a router */
|
---|
| 160 | dt_router
|
---|
| 161 | } inet_dir_type_t;
|
---|
| 162 |
|
---|
| 163 | /** Direction (next hop) to a destination */
|
---|
| 164 | typedef struct {
|
---|
| 165 | /** Route type */
|
---|
| 166 | inet_dir_type_t dtype;
|
---|
| 167 | /** Address object (direction) */
|
---|
| 168 | inet_addrobj_t *aobj;
|
---|
| 169 | /** Local destination address */
|
---|
| 170 | inet_addr_t ldest;
|
---|
| 171 | } inet_dir_t;
|
---|
| 172 |
|
---|
[1bbc6dc] | 173 | /** Internet server configuration */
|
---|
| 174 | typedef struct {
|
---|
| 175 | /** Configuration file path */
|
---|
| 176 | char *cfg_path;
|
---|
| 177 | } inet_cfg_t;
|
---|
| 178 |
|
---|
| 179 | extern inet_cfg_t *cfg;
|
---|
| 180 |
|
---|
[b7fd2a0] | 181 | extern errno_t inet_ev_recv(inet_client_t *, inet_dgram_t *);
|
---|
| 182 | extern errno_t inet_recv_packet(inet_packet_t *);
|
---|
| 183 | extern errno_t inet_route_packet(inet_dgram_t *, uint8_t, uint8_t, int);
|
---|
| 184 | extern errno_t inet_get_srcaddr(inet_addr_t *, uint8_t, inet_addr_t *);
|
---|
| 185 | extern errno_t inet_recv_dgram_local(inet_dgram_t *, uint8_t);
|
---|
[59157eb] | 186 |
|
---|
| 187 | #endif
|
---|
| 188 |
|
---|
| 189 | /** @}
|
---|
| 190 | */
|
---|