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