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