Changeset 6428115 in mainline
- Timestamp:
- 2012-03-11T23:07:29Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 3b3c689
- Parents:
- ffa8912
- Location:
- uspace
- Files:
-
- 6 added
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/Makefile
rffa8912 r6428115 66 66 app/nettest2 \ 67 67 app/nettest3 \ 68 app/ping \ 68 69 app/websrv \ 69 70 app/sysinfo \ -
uspace/lib/c/Makefile
rffa8912 r6428115 89 89 generic/inet.c \ 90 90 generic/inetcfg.c \ 91 generic/inetping.c \ 91 92 generic/io/asprintf.c \ 92 93 generic/io/io.c \ -
uspace/lib/c/include/ipc/inet.h
rffa8912 r6428115 43 43 INET_PORT_DEFAULT = 1, 44 44 /** Configuration port */ 45 INET_PORT_CFG 45 INET_PORT_CFG, 46 /** Ping service port */ 47 INET_PORT_PING 46 48 } inet_port_t; 47 49 … … 70 72 } inetcfg_request_t; 71 73 74 /** Events on Inet ping port */ 75 typedef enum { 76 INETPING_EV_RECV = IPC_FIRST_USER_METHOD 77 } inetping_event_t; 78 79 /** Requests on Inet ping port */ 80 typedef enum { 81 INETPING_SEND = IPC_FIRST_USER_METHOD, 82 INETPING_GET_SRCADDR 83 } inetping_request_t; 84 72 85 #endif 73 86 -
uspace/lib/c/include/ipc/services.h
rffa8912 r6428115 52 52 } services_t; 53 53 54 #define SERVICE_NAME_INET "net/inet" 55 #define SERVICE_NAME_INETCFG "net/inetcfg" 54 #define SERVICE_NAME_INET "net/inet" 55 #define SERVICE_NAME_INETCFG "net/inetcfg" 56 #define SERVICE_NAME_INETPING "net/inetping" 56 57 57 58 #endif -
uspace/srv/inet/Makefile
rffa8912 r6428115 36 36 inet_link.c \ 37 37 inetcfg.c \ 38 inetping.c \ 38 39 pdu.c 39 40 -
uspace/srv/inet/icmp.c
rffa8912 r6428115 44 44 #include "icmp_std.h" 45 45 #include "inet.h" 46 #include "inetping.h" 46 47 #include "pdu.h" 47 48 … … 49 50 #define INET_TTL_MAX 255 50 51 51 static int icmp_echo_request(inet_dgram_t *); 52 static int icmp_recv_echo_request(inet_dgram_t *); 53 static int icmp_recv_echo_reply(inet_dgram_t *); 52 54 53 55 int icmp_recv(inet_dgram_t *dgram) … … 64 66 switch (type) { 65 67 case ICMP_ECHO_REQUEST: 66 return icmp_echo_request(dgram); 68 return icmp_recv_echo_request(dgram); 69 case ICMP_ECHO_REPLY: 70 return icmp_recv_echo_reply(dgram); 67 71 default: 68 72 break; … … 72 76 } 73 77 74 static int icmp_ echo_request(inet_dgram_t *dgram)78 static int icmp_recv_echo_request(inet_dgram_t *dgram) 75 79 { 76 80 icmp_echo_t *request, *reply; … … 80 84 int rc; 81 85 82 log_msg(LVL_DEBUG, "icmp_ echo_request()");86 log_msg(LVL_DEBUG, "icmp_recv_echo_request()"); 83 87 84 88 if (dgram->size < sizeof(icmp_echo_t)) … … 103 107 rdgram.src = dgram->dest; 104 108 rdgram.dest = dgram->src; 105 rdgram.tos = 0;109 rdgram.tos = ICMP_TOS; 106 110 rdgram.data = reply; 107 111 rdgram.size = size; … … 114 118 } 115 119 120 static int icmp_recv_echo_reply(inet_dgram_t *dgram) 121 { 122 icmp_echo_t *reply; 123 inetping_sdu_t sdu; 124 uint16_t ident; 125 126 log_msg(LVL_DEBUG, "icmp_recv_echo_reply()"); 127 128 if (dgram->size < sizeof(icmp_echo_t)) 129 return EINVAL; 130 131 reply = (icmp_echo_t *)dgram->data; 132 133 sdu.src = dgram->src; 134 sdu.dest = dgram->dest; 135 sdu.seq_no = uint16_t_be2host(reply->seq_no); 136 sdu.data = reply + sizeof(icmp_echo_t); 137 sdu.size = dgram->size - sizeof(icmp_echo_t); 138 ident = uint16_t_be2host(reply->ident); 139 140 return inetping_recv(ident, &sdu); 141 } 142 143 int icmp_ping_send(uint16_t ident, inetping_sdu_t *sdu) 144 { 145 inet_dgram_t dgram; 146 icmp_echo_t *request; 147 void *rdata; 148 size_t rsize; 149 uint16_t checksum; 150 int rc; 151 152 rsize = sizeof(icmp_echo_t) + sdu->size; 153 rdata = calloc(rsize, 1); 154 if (rdata == NULL) 155 return ENOMEM; 156 157 request = (icmp_echo_t *)rdata; 158 159 request->type = ICMP_ECHO_REQUEST; 160 request->code = 0; 161 request->checksum = 0; 162 request->ident = host2uint16_t_be(ident); 163 request->seq_no = host2uint16_t_be(sdu->seq_no); 164 165 memcpy(rdata + sizeof(icmp_echo_t), sdu->data, sdu->size); 166 167 checksum = inet_checksum_calc(INET_CHECKSUM_INIT, rdata, rsize); 168 request->checksum = host2uint16_t_be(checksum); 169 170 dgram.src = sdu->src; 171 dgram.dest = sdu->dest; 172 dgram.tos = ICMP_TOS; 173 dgram.data = rdata; 174 dgram.size = rsize; 175 176 rc = inet_route_packet(&dgram, IP_PROTO_ICMP, INET_TTL_MAX, 0); 177 178 free(rdata); 179 return rc; 180 } 181 116 182 /** @} 117 183 */ -
uspace/srv/inet/icmp.h
rffa8912 r6428115 41 41 42 42 extern int icmp_recv(inet_dgram_t *); 43 extern int icmp_ping_send(uint16_t, inetping_sdu_t *); 43 44 44 45 #endif -
uspace/srv/inet/icmp_std.h
rffa8912 r6428115 42 42 #define IP_PROTO_ICMP 1 43 43 44 /** Type of service used for ICMP */ 45 #define ICMP_TOS 0 46 44 47 /** ICMP message type */ 45 48 enum icmp_type { -
uspace/srv/inet/inet.c
rffa8912 r6428115 52 52 #include "inet.h" 53 53 #include "inetcfg.h" 54 #include "inetping.h" 54 55 #include "inet_link.h" 55 56 … … 85 86 rc = loc_service_register_with_iface(SERVICE_NAME_INETCFG, &sid, 86 87 INET_PORT_CFG); 88 if (rc != EOK) { 89 log_msg(LVL_ERROR, "Failed registering service (%d).", rc); 90 return EEXIST; 91 } 92 93 rc = loc_service_register_with_iface(SERVICE_NAME_INETPING, &sid, 94 INET_PORT_PING); 87 95 if (rc != EOK) { 88 96 log_msg(LVL_ERROR, "Failed registering service (%d).", rc); … … 134 142 } 135 143 136 static int inet_get_srcaddr(inet_client_t *client, inet_addr_t *remote, 137 uint8_t tos, inet_addr_t *local) 144 int inet_get_srcaddr(inet_addr_t *remote, uint8_t tos, inet_addr_t *local) 138 145 { 139 146 inet_addrobj_t *addr; … … 163 170 local.ipv4 = 0; 164 171 165 rc = inet_get_srcaddr( client,&remote, tos, &local);172 rc = inet_get_srcaddr(&remote, tos, &local); 166 173 async_answer_1(callid, rc, local.ipv4); 167 174 } … … 287 294 inet_cfg_conn(iid, icall, arg); 288 295 break; 296 case INET_PORT_PING: 297 inetping_conn(iid, icall, arg); 298 break; 289 299 default: 290 300 async_answer_0(iid, ENOTSUP); -
uspace/srv/inet/inet.h
rffa8912 r6428115 50 50 link_t client_list; 51 51 } inet_client_t; 52 53 /** Inetping Client */ 54 typedef struct { 55 /** Callback session */ 56 async_sess_t *sess; 57 /** Session identifier */ 58 uint16_t ident; 59 /** Link to client list */ 60 link_t client_list; 61 } inetping_client_t; 52 62 53 63 /** Host address */ … … 115 125 } inet_addrobj_t; 116 126 127 typedef struct { 128 inet_addr_t src; 129 inet_addr_t dest; 130 uint16_t seq_no; 131 void *data; 132 size_t size; 133 } inetping_sdu_t; 134 117 135 extern int inet_ev_recv(inet_client_t *, inet_dgram_t *); 118 136 extern int inet_recv_packet(inet_packet_t *); 119 137 extern int inet_route_packet(inet_dgram_t *, uint8_t, uint8_t, int); 138 extern int inet_get_srcaddr(inet_addr_t *, uint8_t, inet_addr_t *); 139 120 140 121 141 #endif
Note:
See TracChangeset
for help on using the changeset viewer.