[59157eb] | 1 | /*
|
---|
[b4edc96] | 2 | * Copyright (c) 2021 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>
|
---|
[8d2dd7f2] | 46 | #include <stddef.h>
|
---|
| 47 | #include <stdint.h>
|
---|
[b8b1adb1] | 48 | #include <types/inet.h>
|
---|
[59157eb] | 49 | #include <async.h>
|
---|
| 50 |
|
---|
| 51 | /** Inet Client */
|
---|
| 52 | typedef struct {
|
---|
| 53 | async_sess_t *sess;
|
---|
| 54 | uint8_t protocol;
|
---|
| 55 | link_t client_list;
|
---|
| 56 | } inet_client_t;
|
---|
| 57 |
|
---|
[6428115] | 58 | /** Inetping Client */
|
---|
| 59 | typedef struct {
|
---|
| 60 | /** Callback session */
|
---|
| 61 | async_sess_t *sess;
|
---|
| 62 | /** Session identifier */
|
---|
| 63 | uint16_t ident;
|
---|
| 64 | /** Link to client list */
|
---|
| 65 | link_t client_list;
|
---|
| 66 | } inetping_client_t;
|
---|
| 67 |
|
---|
[1d24ad3] | 68 | /** Inetping6 Client */
|
---|
| 69 | typedef struct {
|
---|
| 70 | /** Callback session */
|
---|
| 71 | async_sess_t *sess;
|
---|
| 72 | /** Session identifier */
|
---|
| 73 | uint16_t ident;
|
---|
| 74 | /** Link to client list */
|
---|
| 75 | link_t client_list;
|
---|
| 76 | } inetping6_client_t;
|
---|
| 77 |
|
---|
[fe4310f] | 78 | typedef struct {
|
---|
[8d48c7e] | 79 | /** Local link ID */
|
---|
| 80 | service_id_t link_id;
|
---|
[7f95c904] | 81 | /** Source address */
|
---|
[fe4310f] | 82 | inet_addr_t src;
|
---|
[7f95c904] | 83 | /** Destination address */
|
---|
[fe4310f] | 84 | inet_addr_t dest;
|
---|
[7f95c904] | 85 | /** Type of service */
|
---|
[fe4310f] | 86 | uint8_t tos;
|
---|
[7f95c904] | 87 | /** Protocol */
|
---|
[fe4310f] | 88 | uint8_t proto;
|
---|
[7f95c904] | 89 | /** Time to live */
|
---|
[fe4310f] | 90 | uint8_t ttl;
|
---|
[7f95c904] | 91 | /** Identifier */
|
---|
[313824a] | 92 | uint32_t ident;
|
---|
[7f95c904] | 93 | /** Do not fragment */
|
---|
| 94 | bool df;
|
---|
| 95 | /** More fragments */
|
---|
| 96 | bool mf;
|
---|
| 97 | /** Offset of fragment into datagram, in bytes */
|
---|
| 98 | size_t offs;
|
---|
| 99 | /** Packet data */
|
---|
[fe4310f] | 100 | void *data;
|
---|
[7f95c904] | 101 | /** Packet data size in bytes */
|
---|
[fe4310f] | 102 | size_t size;
|
---|
| 103 | } inet_packet_t;
|
---|
| 104 |
|
---|
[ceba4bed] | 105 | typedef struct {
|
---|
| 106 | link_t link_list;
|
---|
| 107 | service_id_t svc_id;
|
---|
| 108 | char *svc_name;
|
---|
| 109 | async_sess_t *sess;
|
---|
| 110 | iplink_t *iplink;
|
---|
[347768d] | 111 | size_t def_mtu;
|
---|
[b4edc96] | 112 | eth_addr_t mac;
|
---|
[a17356fd] | 113 | bool mac_valid;
|
---|
[ceba4bed] | 114 | } inet_link_t;
|
---|
| 115 |
|
---|
| 116 | typedef struct {
|
---|
| 117 | link_t addr_list;
|
---|
[0e94b979] | 118 | sysarg_t id;
|
---|
[ceba4bed] | 119 | inet_naddr_t naddr;
|
---|
| 120 | inet_link_t *ilink;
|
---|
[0e94b979] | 121 | char *name;
|
---|
[ceba4bed] | 122 | } inet_addrobj_t;
|
---|
| 123 |
|
---|
[8bf672d] | 124 | /** Static route configuration */
|
---|
| 125 | typedef struct {
|
---|
| 126 | link_t sroute_list;
|
---|
| 127 | sysarg_t id;
|
---|
| 128 | /** Destination network */
|
---|
| 129 | inet_naddr_t dest;
|
---|
| 130 | /** Router via which to route packets */
|
---|
| 131 | inet_addr_t router;
|
---|
| 132 | char *name;
|
---|
| 133 | } inet_sroute_t;
|
---|
| 134 |
|
---|
| 135 | typedef enum {
|
---|
| 136 | /** Destination is on this network node */
|
---|
| 137 | dt_local,
|
---|
| 138 | /** Destination is directly reachable */
|
---|
| 139 | dt_direct,
|
---|
| 140 | /** Destination is behind a router */
|
---|
| 141 | dt_router
|
---|
| 142 | } inet_dir_type_t;
|
---|
| 143 |
|
---|
| 144 | /** Direction (next hop) to a destination */
|
---|
| 145 | typedef struct {
|
---|
| 146 | /** Route type */
|
---|
| 147 | inet_dir_type_t dtype;
|
---|
| 148 | /** Address object (direction) */
|
---|
| 149 | inet_addrobj_t *aobj;
|
---|
| 150 | /** Local destination address */
|
---|
| 151 | inet_addr_t ldest;
|
---|
| 152 | } inet_dir_t;
|
---|
| 153 |
|
---|
[b7fd2a0] | 154 | extern errno_t inet_ev_recv(inet_client_t *, inet_dgram_t *);
|
---|
| 155 | extern errno_t inet_recv_packet(inet_packet_t *);
|
---|
| 156 | extern errno_t inet_route_packet(inet_dgram_t *, uint8_t, uint8_t, int);
|
---|
| 157 | extern errno_t inet_get_srcaddr(inet_addr_t *, uint8_t, inet_addr_t *);
|
---|
| 158 | extern errno_t inet_recv_dgram_local(inet_dgram_t *, uint8_t);
|
---|
[59157eb] | 159 |
|
---|
| 160 | #endif
|
---|
| 161 |
|
---|
| 162 | /** @}
|
---|
| 163 | */
|
---|