[59157eb] | 1 | /*
|
---|
| 2 | * Copyright (c) 2012 Jiri Svoboda
|
---|
| 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>
|
---|
[ceba4bed] | 43 | #include <inet/iplink.h>
|
---|
| 44 | #include <ipc/loc.h>
|
---|
[59157eb] | 45 | #include <sys/types.h>
|
---|
| 46 | #include <async.h>
|
---|
| 47 |
|
---|
| 48 | /** Inet Client */
|
---|
| 49 | typedef struct {
|
---|
| 50 | async_sess_t *sess;
|
---|
| 51 | uint8_t protocol;
|
---|
| 52 | link_t client_list;
|
---|
| 53 | } inet_client_t;
|
---|
| 54 |
|
---|
[6428115] | 55 | /** Inetping Client */
|
---|
| 56 | typedef struct {
|
---|
| 57 | /** Callback session */
|
---|
| 58 | async_sess_t *sess;
|
---|
| 59 | /** Session identifier */
|
---|
| 60 | uint16_t ident;
|
---|
| 61 | /** Link to client list */
|
---|
| 62 | link_t client_list;
|
---|
| 63 | } inetping_client_t;
|
---|
| 64 |
|
---|
[1d24ad3] | 65 | /** Inetping6 Client */
|
---|
| 66 | typedef struct {
|
---|
| 67 | /** Callback session */
|
---|
| 68 | async_sess_t *sess;
|
---|
| 69 | /** Session identifier */
|
---|
| 70 | uint16_t ident;
|
---|
| 71 | /** Link to client list */
|
---|
| 72 | link_t client_list;
|
---|
| 73 | } inetping6_client_t;
|
---|
| 74 |
|
---|
[0e25780] | 75 | /** Address object info */
|
---|
| 76 | typedef struct {
|
---|
| 77 | /** Network address */
|
---|
| 78 | inet_naddr_t naddr;
|
---|
[0e94b979] | 79 | /** Link service ID */
|
---|
| 80 | sysarg_t ilink;
|
---|
| 81 | /** Address object name */
|
---|
| 82 | char *name;
|
---|
[0e25780] | 83 | } inet_addr_info_t;
|
---|
| 84 |
|
---|
| 85 | /** IP link info */
|
---|
| 86 | typedef struct {
|
---|
[0e94b979] | 87 | /** Link service name */
|
---|
| 88 | char *name;
|
---|
[347768d] | 89 | /** Default MTU */
|
---|
| 90 | size_t def_mtu;
|
---|
[0e25780] | 91 | } inet_link_info_t;
|
---|
| 92 |
|
---|
[8bf672d] | 93 | /** Static route info */
|
---|
| 94 | typedef struct {
|
---|
| 95 | /** Destination network address */
|
---|
| 96 | inet_naddr_t dest;
|
---|
| 97 | /** Router address */
|
---|
| 98 | inet_addr_t router;
|
---|
| 99 | /** Static route name */
|
---|
| 100 | char *name;
|
---|
| 101 | } inet_sroute_info_t;
|
---|
| 102 |
|
---|
[fe4310f] | 103 | typedef struct {
|
---|
[7f95c904] | 104 | /** Source address */
|
---|
[fe4310f] | 105 | inet_addr_t src;
|
---|
[7f95c904] | 106 | /** Destination address */
|
---|
[fe4310f] | 107 | inet_addr_t dest;
|
---|
[7f95c904] | 108 | /** Type of service */
|
---|
[fe4310f] | 109 | uint8_t tos;
|
---|
[7f95c904] | 110 | /** Protocol */
|
---|
[fe4310f] | 111 | uint8_t proto;
|
---|
[7f95c904] | 112 | /** Time to live */
|
---|
[fe4310f] | 113 | uint8_t ttl;
|
---|
[7f95c904] | 114 | /** Identifier */
|
---|
| 115 | uint16_t ident;
|
---|
| 116 | /** Do not fragment */
|
---|
| 117 | bool df;
|
---|
| 118 | /** More fragments */
|
---|
| 119 | bool mf;
|
---|
| 120 | /** Offset of fragment into datagram, in bytes */
|
---|
| 121 | size_t offs;
|
---|
| 122 | /** Packet data */
|
---|
[fe4310f] | 123 | void *data;
|
---|
[7f95c904] | 124 | /** Packet data size in bytes */
|
---|
[fe4310f] | 125 | size_t size;
|
---|
| 126 | } inet_packet_t;
|
---|
| 127 |
|
---|
[59157eb] | 128 | typedef struct {
|
---|
| 129 | inet_addr_t src;
|
---|
| 130 | inet_addr_t dest;
|
---|
| 131 | uint8_t tos;
|
---|
| 132 | void *data;
|
---|
| 133 | size_t size;
|
---|
| 134 | } inet_dgram_t;
|
---|
| 135 |
|
---|
[ceba4bed] | 136 | typedef struct {
|
---|
| 137 | link_t link_list;
|
---|
| 138 | service_id_t svc_id;
|
---|
| 139 | char *svc_name;
|
---|
| 140 | async_sess_t *sess;
|
---|
| 141 | iplink_t *iplink;
|
---|
[347768d] | 142 | size_t def_mtu;
|
---|
[ceba4bed] | 143 | } inet_link_t;
|
---|
| 144 |
|
---|
| 145 | typedef struct {
|
---|
| 146 | link_t addr_list;
|
---|
[0e94b979] | 147 | sysarg_t id;
|
---|
[ceba4bed] | 148 | inet_naddr_t naddr;
|
---|
| 149 | inet_link_t *ilink;
|
---|
[0e94b979] | 150 | char *name;
|
---|
[ceba4bed] | 151 | } inet_addrobj_t;
|
---|
| 152 |
|
---|
[8bf672d] | 153 | /** Static route configuration */
|
---|
| 154 | typedef struct {
|
---|
| 155 | link_t sroute_list;
|
---|
| 156 | sysarg_t id;
|
---|
| 157 | /** Destination network */
|
---|
| 158 | inet_naddr_t dest;
|
---|
| 159 | /** Router via which to route packets */
|
---|
| 160 | inet_addr_t router;
|
---|
| 161 | char *name;
|
---|
| 162 | } inet_sroute_t;
|
---|
| 163 |
|
---|
| 164 | typedef enum {
|
---|
| 165 | /** Destination is on this network node */
|
---|
| 166 | dt_local,
|
---|
| 167 | /** Destination is directly reachable */
|
---|
| 168 | dt_direct,
|
---|
| 169 | /** Destination is behind a router */
|
---|
| 170 | dt_router
|
---|
| 171 | } inet_dir_type_t;
|
---|
| 172 |
|
---|
| 173 | /** Direction (next hop) to a destination */
|
---|
| 174 | typedef struct {
|
---|
| 175 | /** Route type */
|
---|
| 176 | inet_dir_type_t dtype;
|
---|
| 177 | /** Address object (direction) */
|
---|
| 178 | inet_addrobj_t *aobj;
|
---|
| 179 | /** Local destination address */
|
---|
| 180 | inet_addr_t ldest;
|
---|
| 181 | } inet_dir_t;
|
---|
| 182 |
|
---|
[6428115] | 183 | typedef struct {
|
---|
[a2e3ee6] | 184 | uint32_t src;
|
---|
| 185 | uint32_t dest;
|
---|
[6428115] | 186 | uint16_t seq_no;
|
---|
| 187 | void *data;
|
---|
| 188 | size_t size;
|
---|
| 189 | } inetping_sdu_t;
|
---|
| 190 |
|
---|
[1d24ad3] | 191 | typedef struct {
|
---|
| 192 | addr128_t src;
|
---|
| 193 | addr128_t dest;
|
---|
| 194 | uint16_t seq_no;
|
---|
| 195 | void *data;
|
---|
| 196 | size_t size;
|
---|
| 197 | } inetping6_sdu_t;
|
---|
| 198 |
|
---|
[59157eb] | 199 | extern int inet_ev_recv(inet_client_t *, inet_dgram_t *);
|
---|
[fe4310f] | 200 | extern int inet_recv_packet(inet_packet_t *);
|
---|
[637a3b4] | 201 | extern int inet_route_packet(inet_dgram_t *, uint8_t, uint8_t, int);
|
---|
[6428115] | 202 | extern int inet_get_srcaddr(inet_addr_t *, uint8_t, inet_addr_t *);
|
---|
[7f95c904] | 203 | extern int inet_recv_dgram_local(inet_dgram_t *, uint8_t);
|
---|
[59157eb] | 204 |
|
---|
| 205 | #endif
|
---|
| 206 |
|
---|
| 207 | /** @}
|
---|
| 208 | */
|
---|