Changeset b1213b0 in mainline for uspace/srv/net
- Timestamp:
- 2012-04-17T07:13:35Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 96c0b7b
- Parents:
- d76a329 (diff), 06a1d077 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - Location:
- uspace/srv/net
- Files:
-
- 39 added
- 21 deleted
- 39 moved
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/net/ethip/Makefile
rd76a329 rb1213b0 1 1 # 2 # Copyright (c) 2005 Martin Decky 3 # Copyright (c) 2007 Jakub Jermar 2 # Copyright (c) 2012 Jiri Svoboda 4 3 # All rights reserved. 5 4 # … … 28 27 # 29 28 30 USPACE_PREFIX = ../../../.. 31 LIBS = $(LIBNET_PREFIX)/libnet.a 32 EXTRA_CFLAGS = -I$(LIBNET_PREFIX)/include 33 BINARY = arp 29 USPACE_PREFIX = ../../.. 30 BINARY = ethip 34 31 35 32 SOURCES = \ 36 arp.c 33 arp.c \ 34 atrans.c \ 35 ethip.c \ 36 ethip_nic.c \ 37 pdu.c 37 38 38 39 include $(USPACE_PREFIX)/Makefile.common -
uspace/srv/net/ethip/pdu.h
rd76a329 rb1213b0 1 1 /* 2 * Copyright (c) 20 09 Lukas Mejdrech2 * Copyright (c) 2012 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 27 27 */ 28 28 29 /** @addtogroup libnet29 /** @addtogroup inet 30 30 * @{ 31 31 */ 32 /** 33 * @file 34 * @brief 35 */ 32 36 33 #ifndef LIBNET_PACKET_REMOTE_H_34 #define LIBNET_PACKET_REMOTE_H_37 #ifndef ETH_PDU_H_ 38 #define ETH_PDU_H_ 35 39 36 #include <net/packet.h> 37 #include <sys/types.h> 38 #include <async.h> 40 #include "ethip.h" 39 41 40 extern int packet_translate_remote(async_sess_t *, packet_t **, packet_id_t); 41 extern packet_t *packet_get_4_remote(async_sess_t *, size_t, size_t, size_t, 42 size_t); 43 extern packet_t *packet_get_1_remote(async_sess_t *, size_t); 44 extern void pq_release_remote(async_sess_t *, packet_id_t); 42 extern int eth_pdu_encode(eth_frame_t *, void **, size_t *); 43 extern int eth_pdu_decode(void *, size_t, eth_frame_t *); 44 extern void mac48_encode(mac48_addr_t *, void *); 45 extern void mac48_decode(void *, mac48_addr_t *); 46 extern int arp_pdu_encode(arp_eth_packet_t *, void **, size_t *); 47 extern int arp_pdu_decode(void *, size_t, arp_eth_packet_t *); 48 45 49 46 50 #endif -
uspace/srv/net/ethip/std.h
rd76a329 rb1213b0 1 1 /* 2 * Copyright (c) 20 09 Lukas Mejdrech2 * Copyright (c) 2012 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 27 27 */ 28 28 29 /** @addtogroup libnet29 /** @addtogroup ethip 30 30 * @{ 31 31 */ 32 /** @file 33 * General CRC and checksum computation. 32 /** 33 * @file Ethernet, IP/Ethernet standard definitions 34 * 34 35 */ 35 36 36 #ifndef LIBNET_CHECKSUM_H_37 #define LIBNET_CHECKSUM_H_37 #ifndef ETHIP_STD_H_ 38 #define ETHIP_STD_H_ 38 39 39 #include <byteorder.h>40 40 #include <sys/types.h> 41 41 42 /** IP checksum value for computed zero checksum. 43 * 44 * Zero is returned as 0xFFFF (not flipped) 45 * 46 */ 47 #define IP_CHECKSUM_ZERO 0xffffU 42 #define ETH_ADDR_SIZE 6 43 #define IPV4_ADDR_SIZE 4 44 #define ETH_FRAME_MIN_SIZE 60 48 45 49 #ifdef __BE__ 46 /** Ethernet frame header */ 47 typedef struct { 48 /** Destination Address */ 49 uint8_t dest[ETH_ADDR_SIZE]; 50 /** Source Address */ 51 uint8_t src[ETH_ADDR_SIZE]; 52 /** Ethertype or Length */ 53 uint16_t etype_len; 54 } eth_header_t; 50 55 51 #define compute_crc32(seed, data, length) \ 52 compute_crc32_be(seed, (uint8_t *) data, length) 56 /** ARP packet format (for 48-bit MAC addresses and IPv4) */ 57 typedef struct { 58 /** Hardware address space */ 59 uint16_t hw_addr_space; 60 /** Protocol address space */ 61 uint16_t proto_addr_space; 62 /** Hardware address size */ 63 uint8_t hw_addr_size; 64 /** Protocol address size */ 65 uint8_t proto_addr_size; 66 /** Opcode */ 67 uint16_t opcode; 68 /** Sender hardware address */ 69 uint8_t sender_hw_addr[ETH_ADDR_SIZE]; 70 /** Sender protocol address */ 71 uint32_t sender_proto_addr; 72 /** Target hardware address */ 73 uint8_t target_hw_addr[ETH_ADDR_SIZE]; 74 /** Target protocol address */ 75 uint32_t target_proto_addr; 76 } __attribute__((packed)) arp_eth_packet_fmt_t; 53 77 54 #endif 78 enum arp_opcode_fmt { 79 AOP_REQUEST = 1, 80 AOP_REPLY = 2 81 }; 55 82 56 #ifdef __LE__ 83 enum arp_hw_addr_space { 84 AHRD_ETHERNET = 1 85 }; 57 86 58 #define compute_crc32(seed, data, length) \ 59 compute_crc32_le(seed, (uint8_t *) data, length) 87 /** IP Ethertype */ 88 enum ether_type { 89 ETYPE_ARP = 0x0806, 90 ETYPE_IP = 0x0800 91 }; 60 92 61 #endif62 63 extern uint32_t compute_crc32_le(uint32_t, uint8_t *, size_t);64 extern uint32_t compute_crc32_be(uint32_t, uint8_t *, size_t);65 extern uint32_t compute_checksum(uint32_t, uint8_t *, size_t);66 extern uint16_t compact_checksum(uint32_t);67 extern uint16_t flip_checksum(uint16_t);68 extern uint16_t ip_checksum(uint8_t *, size_t);69 93 70 94 #endif -
uspace/srv/net/inet/Makefile
rd76a329 rb1213b0 1 1 # 2 # Copyright (c) 2005 Martin Decky 3 # Copyright (c) 2007 Jakub Jermar 2 # Copyright (c) 2012 Jiri Svoboda 4 3 # All rights reserved. 5 4 # … … 28 27 # 29 28 30 USPACE_PREFIX = ../../../.. 31 LIBS = $(LIBNET_PREFIX)/libnet.a 32 EXTRA_CFLAGS = -I$(LIBNET_PREFIX)/include 33 BINARY = icmp 34 STATIC_ONLY = y 29 USPACE_PREFIX = ../../.. 30 BINARY = inet 35 31 36 32 SOURCES = \ 37 icmp.c 33 addrobj.c \ 34 icmp.c \ 35 inet.c \ 36 inet_link.c \ 37 inet_util.c \ 38 inetcfg.c \ 39 inetping.c \ 40 pdu.c \ 41 reass.c \ 42 sroute.c 38 43 39 44 include $(USPACE_PREFIX)/Makefile.common -
uspace/srv/net/inet/addrobj.h
rd76a329 rb1213b0 1 1 /* 2 * Copyright (c) 20 09 Lukas Mejdrech2 * Copyright (c) 2012 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 27 27 */ 28 28 29 /** @addtogroup libnet29 /** @addtogroup inet 30 30 * @{ 31 31 */ 32 33 /** @file 34 * Internetwork layer module interface for the underlying network interface 35 * layer. This interface is always called by the remote modules. 32 /** 33 * @file 34 * @brief 36 35 */ 37 36 38 #ifndef LIBNET_IL_REMOTE_H_39 #define LIBNET_IL_REMOTE_H_37 #ifndef INET_ADDROBJ_H_ 38 #define INET_ADDROBJ_H_ 40 39 41 #include <ipc/services.h>42 40 #include <sys/types.h> 43 #include <net/device.h> 44 #include <net/packet.h> 45 #include <async.h> 41 #include "inet.h" 46 42 47 /** @name Internetwork layer module interface 48 * This interface is used by other modules. 49 */ 50 /*@{*/ 43 typedef enum { 44 /* Find matching network address (using mask) */ 45 iaf_net, 46 /* Find exact local address (not using mask) */ 47 iaf_addr 48 } inet_addrobj_find_t; 51 49 52 extern int il_device_state_msg(async_sess_t *, nic_device_id_t, 53 nic_device_state_t, services_t); 54 extern int il_received_msg(async_sess_t *, nic_device_id_t, packet_t *, 55 services_t); 56 extern int il_mtu_changed_msg(async_sess_t *, nic_device_id_t, size_t, 57 services_t); 58 extern int il_addr_changed_msg(async_sess_t *, nic_device_id_t, size_t, 59 const uint8_t *); 50 extern inet_addrobj_t *inet_addrobj_new(void); 51 extern void inet_addrobj_delete(inet_addrobj_t *); 52 extern void inet_addrobj_add(inet_addrobj_t *); 53 extern void inet_addrobj_remove(inet_addrobj_t *); 54 extern inet_addrobj_t *inet_addrobj_find(inet_addr_t *, inet_addrobj_find_t); 55 extern inet_addrobj_t *inet_addrobj_find_by_name(const char *, inet_link_t *); 56 extern inet_addrobj_t *inet_addrobj_get_by_id(sysarg_t); 57 extern int inet_addrobj_send_dgram(inet_addrobj_t *, inet_addr_t *, 58 inet_dgram_t *, uint8_t, uint8_t, int); 59 extern int inet_addrobj_get_id_list(sysarg_t **, size_t *); 60 60 61 /*@}*/62 61 63 62 #endif -
uspace/srv/net/inet/icmp_std.h
rd76a329 rb1213b0 1 1 /* 2 * Copyright (c) 20 09 Lukas Mejdrech2 * Copyright (c) 2012 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 27 27 */ 28 28 29 /** @addtogroup udp29 /** @addtogroup inet 30 30 * @{ 31 31 */ 32 33 /** @file 34 * UDP header definition. 35 * Based on the RFC 768. 32 /** 33 * @file ICMP standard definitions 34 * 36 35 */ 37 36 38 #ifndef NET_UDP_HEADER_H_39 #define NET_UDP_HEADER_H_37 #ifndef ICMP_STD_H_ 38 #define ICMP_STD_H_ 40 39 41 40 #include <sys/types.h> 42 41 43 /** UDP header size in bytes. */ 44 #define UDP_HEADER_SIZE sizeof(udp_header_t) 42 #define IP_PROTO_ICMP 1 45 43 46 /** Type definition of the user datagram header. 47 * @see udp_header 48 */ 49 typedef struct udp_header udp_header_t; 44 /** Type of service used for ICMP */ 45 #define ICMP_TOS 0 50 46 51 /** User datagram header. */ 52 struct udp_header { 53 uint16_t source_port; 54 uint16_t destination_port; 55 uint16_t total_length; 47 /** ICMP message type */ 48 enum icmp_type { 49 ICMP_ECHO_REPLY = 0, 50 ICMP_ECHO_REQUEST = 8 51 }; 52 53 /** ICMP Echo Request or Reply message header */ 54 typedef struct { 55 /** ICMP message type */ 56 uint8_t type; 57 /** Code (0) */ 58 uint8_t code; 59 /** Internet checksum of the ICMP message */ 56 60 uint16_t checksum; 57 } __attribute__ ((packed)); 61 /** Indentifier */ 62 uint16_t ident; 63 /** Sequence number */ 64 uint16_t seq_no; 65 } icmp_echo_t; 58 66 59 67 #endif -
uspace/srv/net/inet/inet_std.h
rd76a329 rb1213b0 1 1 /* 2 * Copyright (c) 20 09 Lukas Mejdrech2 * Copyright (c) 2012 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 27 27 */ 28 28 29 /** @addtogroup libc29 /** @addtogroup inet 30 30 * @{ 31 31 */ 32 33 /** @file 34 * ARP module messages. 35 * @see arp_interface.h 32 /** 33 * @file IP header definitions 34 * 36 35 */ 37 36 38 #ifndef LIBC_ARP_MESSAGES_39 #define LIBC_ARP_MESSAGES_37 #ifndef INET_STD_H_ 38 #define INET_STD_H_ 40 39 41 #include < ipc/net.h>40 #include <sys/types.h> 42 41 43 /** ARP module messages.*/44 typedef enum{45 /** Clean cache message.46 * @see arp_clean_cache()47 */48 NET_ARP_CLEAN_CACHE = NET_ARP_FIRST,49 /** Clear address cache message.50 * @see arp_clear_address_msg()51 */52 NET_ARP_CLEAR_ADDRESS,53 /** Clear device cache message.54 * @see arp_clear_device_req()55 */56 NET_ARP_CLEAR_DEVICE,57 /** New device message.58 * @see arp_device_req()59 */60 NET_ARP_DEVICE,61 /** Address translation message.62 * @see arp_translate_req()63 */64 NET_ARP_TRANSLATE65 } arp_messages;42 /** Internet Datagram header (fixed part) */ 43 typedef struct { 44 /** Version, Internet Header Length */ 45 uint8_t ver_ihl; 46 /* Type of Service */ 47 uint8_t tos; 48 /** Total Length */ 49 uint16_t tot_len; 50 /** Identification */ 51 uint16_t id; 52 /** Flags, Fragment Offset */ 53 uint16_t flags_foff; 54 /** Time to Live */ 55 uint8_t ttl; 56 /** Protocol */ 57 uint8_t proto; 58 /** Header Checksum */ 59 uint16_t chksum; 60 /** Source Address */ 61 uint32_t src_addr; 62 /** Destination Address */ 63 uint32_t dest_addr; 64 } ip_header_t; 66 65 67 /** @name ARP specific message parameters definitions */ 68 /*@{*/ 66 /** Bits in ip_header_t.ver_ihl */ 67 enum ver_ihl_bits { 68 /** Version, highest bit */ 69 VI_VERSION_h = 7, 70 /** Version, lowest bit */ 71 VI_VERSION_l = 4, 72 /** Internet Header Length, highest bit */ 73 VI_IHL_h = 3, 74 /** Internet Header Length, lowest bit */ 75 VI_IHL_l = 0 76 }; 69 77 70 /** Return the protocol service message parameter. 71 * 72 * @param[in] call Message call structure. 73 * 74 */ 75 #define ARP_GET_NETIF(call) ((services_t) IPC_GET_ARG2(call)) 78 /** Bits in ip_header_t.flags_foff */ 79 enum flags_foff_bits { 80 /** Reserved, must be zero */ 81 FF_FLAG_RSVD = 15, 82 /** Don't Fragment */ 83 FF_FLAG_DF = 14, 84 /** More Fragments */ 85 FF_FLAG_MF = 13, 86 /** Fragment Offset, highest bit */ 87 FF_FRAGOFF_h = 12, 88 /** Fragment Offset, lowest bit */ 89 FF_FRAGOFF_l = 0 90 }; 76 91 77 /*@}*/ 92 /** Fragment offset is expressed in units of 8 bytes */ 93 #define FRAG_OFFS_UNIT 8 78 94 79 95 #endif -
uspace/srv/net/tcp/Makefile
rd76a329 rb1213b0 27 27 # 28 28 29 USPACE_PREFIX = ../../.. /..29 USPACE_PREFIX = ../../.. 30 30 LIBS = $(LIBNET_PREFIX)/libnet.a 31 31 EXTRA_CFLAGS = -I$(LIBNET_PREFIX)/include -
uspace/srv/net/tcp/conn.c
rd76a329 rb1213b0 309 309 } 310 310 311 /** Compare two sockets. 312 * 313 * Two sockets are equal if the address is equal and the port number 314 * is equal. 315 */ 311 /** Match socket with pattern. */ 316 312 static bool tcp_socket_match(tcp_sock_t *sock, tcp_sock_t *patt) 317 313 { … … 332 328 } 333 329 334 /** Match socket with pattern. */330 /** Match socket pair with pattern. */ 335 331 static bool tcp_sockpair_match(tcp_sockpair_t *sp, tcp_sockpair_t *pattern) 336 332 { … … 357 353 tcp_conn_t *tcp_conn_find_ref(tcp_sockpair_t *sp) 358 354 { 359 log_msg(LVL_DEBUG, "tcp_conn_find (%p)", sp);355 log_msg(LVL_DEBUG, "tcp_conn_find_ref(%p)", sp); 360 356 361 357 fibril_mutex_lock(&conn_list_lock); -
uspace/srv/net/tcp/pdu.c
rd76a329 rb1213b0 255 255 } 256 256 257 /** Encode outgoing PDU */257 /** Decode incoming PDU */ 258 258 int tcp_pdu_decode(tcp_pdu_t *pdu, tcp_sockpair_t *sp, tcp_segment_t **seg) 259 259 { … … 279 279 } 280 280 281 /** Decode incoming PDU */281 /** Encode outgoing PDU */ 282 282 int tcp_pdu_encode(tcp_sockpair_t *sp, tcp_segment_t *seg, tcp_pdu_t **pdu) 283 283 { -
uspace/srv/net/tcp/sock.c
rd76a329 rb1213b0 38 38 #include <async.h> 39 39 #include <errno.h> 40 #include <inet/inet.h> 40 41 #include <io/log.h> 41 #include <ip _client.h>42 #include <ipc/services.h> 42 43 #include <ipc/socket.h> 43 44 #include <net/modules.h> 44 45 #include <net/socket.h> 46 #include <ns.h> 45 47 46 48 #include "sock.h" … … 63 65 static socket_ports_t gsock; 64 66 67 static void tcp_sock_connection(ipc_callid_t iid, ipc_call_t *icall, void *arg); 65 68 static void tcp_sock_cstate_cb(tcp_conn_t *conn, void *arg); 66 69 67 void tcp_sock_init(void) 68 { 70 int tcp_sock_init(void) 71 { 72 int rc; 73 69 74 socket_ports_initialize(&gsock); 75 76 async_set_client_connection(tcp_sock_connection); 77 78 rc = service_register(SERVICE_TCP); 79 if (rc != EOK) 80 return EEXIST; 81 82 return EOK; 70 83 } 71 84 … … 273 286 tcp_sock_t lsocket; 274 287 tcp_sock_t fsocket; 275 nic_device_id_t dev_id;276 tcp_phdr_t *phdr;277 size_t phdr_len;278 288 279 289 log_msg(LVL_DEBUG, "tcp_sock_connect()"); … … 309 319 310 320 if (socket->laddr.ipv4 == TCP_IPV4_ANY) { 311 /* Find route to determine local IP address. */ 312 rc = ip_get_route_req(ip_sess, IPPROTO_TCP, 313 (struct sockaddr *)addr, sizeof(*addr), &dev_id, 314 (void **)&phdr, &phdr_len); 321 /* Determine local IP address */ 322 inet_addr_t loc_addr, rem_addr; 323 324 rem_addr.ipv4 = uint32_t_be2host(addr->sin_addr.s_addr); 325 rc = inet_get_srcaddr(&rem_addr, 0, &loc_addr); 315 326 if (rc != EOK) { 316 327 fibril_mutex_unlock(&socket->lock); 317 328 async_answer_0(callid, rc); 318 log_msg(LVL_DEBUG, "tcp_transmit_connect: Failed to find route."); 319 return; 320 } 321 322 socket->laddr.ipv4 = uint32_t_be2host(phdr->src_addr); 329 log_msg(LVL_DEBUG, "tcp_sock_connect: Failed to " 330 "determine local address."); 331 return; 332 } 333 334 socket->laddr.ipv4 = loc_addr.ipv4; 323 335 log_msg(LVL_DEBUG, "Local IP address is %x", socket->laddr.ipv4); 324 free(phdr);325 336 } 326 337 … … 713 724 } 714 725 715 rc = socket_destroy( net_sess, socket_id, &client->sockets, &gsock,726 rc = socket_destroy(NULL, socket_id, &client->sockets, &gsock, 716 727 tcp_free_sock_data); 717 728 if (rc != EOK) { … … 764 775 } 765 776 766 int tcp_sock_connection(async_sess_t *sess, ipc_callid_t iid, ipc_call_t icall)777 static void tcp_sock_connection(ipc_callid_t iid, ipc_call_t *icall, void *arg) 767 778 { 768 779 ipc_callid_t callid; … … 773 784 async_answer_0(iid, EOK); 774 785 775 client.sess = sess;786 client.sess = async_callback_receive(EXCHANGE_SERIALIZE); 776 787 socket_cores_initialize(&client.sockets); 777 788 … … 824 835 } 825 836 } 826 827 return EOK;828 837 } 829 838 -
uspace/srv/net/tcp/sock.h
rd76a329 rb1213b0 38 38 #include <async.h> 39 39 40 extern void tcp_sock_init(void); 41 extern int tcp_sock_connection(async_sess_t *, ipc_callid_t, ipc_call_t); 40 extern int tcp_sock_init(void); 42 41 43 42 #endif -
uspace/srv/net/tcp/tcp.h
rd76a329 rb1213b0 37 37 38 38 #include <async.h> 39 #include <packet_remote.h>40 39 #include "tcp_type.h" 41 40 42 extern async_sess_t *net_sess;43 extern async_sess_t *ip_sess;44 41 extern void tcp_transmit_pdu(tcp_pdu_t *); 45 42 -
uspace/srv/net/udp/Makefile
rd76a329 rb1213b0 1 1 # 2 # Copyright (c) 2005 Martin Decky 3 # Copyright (c) 2007 Jakub Jermar 2 # Copyright (c) 2012 Jiri Svoboda 4 3 # All rights reserved. 5 4 # … … 28 27 # 29 28 30 USPACE_PREFIX = ../../.. /..29 USPACE_PREFIX = ../../.. 31 30 LIBS = $(LIBNET_PREFIX)/libnet.a 32 31 EXTRA_CFLAGS = -I$(LIBNET_PREFIX)/include … … 34 33 35 34 SOURCES = \ 36 udp.c 35 assoc.c \ 36 msg.c \ 37 sock.c \ 38 pdu.c \ 39 ucall.c \ 40 udp.c \ 41 udp_inet.c 37 42 38 43 include $(USPACE_PREFIX)/Makefile.common -
uspace/srv/net/udp/assoc.h
rd76a329 rb1213b0 1 1 /* 2 * Copyright (c) 20 09 Lukas Mejdrech2 * Copyright (c) 2012 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 27 27 */ 28 28 29 /** @addtogroup libnet29 /** @addtogroup udp 30 30 * @{ 31 31 */ 32 33 /** @file 34 * Ethernet protocol numbers according to the on-line IANA - Ethernet numbers 35 * http://www.iana.org/assignments/ethernet-numbers 36 * cited January 17 2009. 32 /** @file UDP associations 37 33 */ 38 34 39 #ifndef LIBNET_ETHERNET_PROTOCOLS_H_40 #define LIBNET_ETHERNET_PROTOCOLS_H_35 #ifndef ASSOC_H 36 #define ASSOC_H 41 37 42 38 #include <sys/types.h> 39 #include "udp_type.h" 43 40 44 /** Ethernet protocol type definition. */ 45 typedef uint16_t eth_type_t; 41 extern udp_assoc_t *udp_assoc_new(udp_sock_t *, udp_sock_t *); 42 extern void udp_assoc_delete(udp_assoc_t *); 43 extern void udp_assoc_add(udp_assoc_t *); 44 extern void udp_assoc_remove(udp_assoc_t *); 45 extern void udp_assoc_addref(udp_assoc_t *); 46 extern void udp_assoc_delref(udp_assoc_t *); 47 extern void udp_assoc_set_foreign(udp_assoc_t *, udp_sock_t *); 48 extern void udp_assoc_set_local(udp_assoc_t *, udp_sock_t *); 49 extern int udp_assoc_send(udp_assoc_t *, udp_sock_t *, udp_msg_t *); 50 extern int udp_assoc_recv(udp_assoc_t *, udp_msg_t **, udp_sock_t *); 51 extern void udp_assoc_received(udp_sockpair_t *, udp_msg_t *); 46 52 47 /** @name Ethernet protocols definitions */48 /*@{*/49 50 /** Ethernet minimal protocol number.51 * According to the IEEE 802.3 specification.52 */53 #define ETH_MIN_PROTO 0x0600 /* 1536 */54 55 /** Internet IP (IPv4) ethernet protocol type. */56 #define ETH_P_IP 0x080057 58 /** ARP ethernet protocol type. */59 #define ETH_P_ARP 0x080660 61 /*@}*/62 53 63 54 #endif -
uspace/srv/net/udp/sock.h
rd76a329 rb1213b0 1 1 /* 2 * Copyright (c) 20 09 Lukas Mejdrech2 * Copyright (c) 2012 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 27 27 */ 28 28 29 /** @addtogroup libc 30 * @{ 29 /** @addtogroup udp 30 * @{ 31 */ 32 /** @file Socket provider 31 33 */ 32 34 33 /** @file 34 * ICMP module common interface. 35 */ 35 #ifndef SOCK_H 36 #define SOCK_H 36 37 37 #ifndef LIBC_ICMP_COMMON_H_38 #define LIBC_ICMP_COMMON_H_39 40 #include <ipc/services.h>41 #include <sys/time.h>42 38 #include <async.h> 43 39 44 extern async_sess_t *icmp_connect_module(void);40 extern int udp_sock_init(void); 45 41 46 42 #endif -
uspace/srv/net/udp/ucall.h
rd76a329 rb1213b0 1 1 /* 2 * Copyright (c) 20 09 Lukas Mejdrech2 * Copyright (c) 2012 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 27 27 */ 28 28 29 /** @addtogroup libc29 /** @addtogroup udp 30 30 * @{ 31 31 */ 32 33 /** @file 34 * ICMP module application interface. 32 /** @file UDP user calls 35 33 */ 36 34 37 #ifndef LIBC_ICMP_API_H_38 #define LIBC_ICMP_API_H_35 #ifndef UCALL_H 36 #define UCALL_H 39 37 40 #include <net/socket_codes.h>41 #include <net/inet.h>42 38 #include <sys/types.h> 43 #include <sys/time.h> 44 #include <adt/measured_strings.h> 45 #include <net/ip_codes.h> 46 #include <net/icmp_codes.h> 47 #include <net/icmp_common.h> 48 #include <async.h> 39 #include "udp_type.h" 49 40 50 /** @name ICMP module application interface 51 * This interface is used by other application modules. 52 */ 53 /*@{*/ 54 55 extern int icmp_echo_msg(async_sess_t *, size_t, mseconds_t, ip_ttl_t, ip_tos_t,56 int, const struct sockaddr *, socklen_t);57 58 /*@}*/ 41 extern udp_error_t udp_uc_create(udp_assoc_t **); 42 extern udp_error_t udp_uc_set_foreign(udp_assoc_t *, udp_sock_t *); 43 extern udp_error_t udp_uc_set_local(udp_assoc_t *, udp_sock_t *); 44 extern udp_error_t udp_uc_send(udp_assoc_t *, udp_sock_t *, void *, size_t, 45 xflags_t); 46 extern udp_error_t udp_uc_receive(udp_assoc_t *, void *, size_t, size_t *, 47 xflags_t *, udp_sock_t *); 48 extern void udp_uc_status(udp_assoc_t *, udp_assoc_status_t *); 49 extern void udp_uc_destroy(udp_assoc_t *); 59 50 60 51 #endif -
uspace/srv/net/udp/udp.c
rd76a329 rb1213b0 1 1 /* 2 * Copyright (c) 20 08 Lukas Mejdrech2 * Copyright (c) 2012 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 31 31 */ 32 32 33 /** @file34 * UDP module.33 /** 34 * @file UDP (User Datagram Protocol) service 35 35 */ 36 36 37 #ifndef NET_UDP_H_ 38 #define NET_UDP_H_ 37 #include <async.h> 38 #include <errno.h> 39 #include <io/log.h> 40 #include <stdio.h> 41 #include <task.h> 39 42 40 #include <async.h> 41 #include <fibril_synch.h> 42 #include <socket_core.h> 43 #include <tl_common.h> 43 #include "udp_inet.h" 44 #include "sock.h" 44 45 45 /** Type definition of the UDP global data. 46 * @see udp_globals 46 #define NAME "udp" 47 48 static int udp_init(void) 49 { 50 int rc; 51 52 log_msg(LVL_DEBUG, "udp_init()"); 53 54 rc = udp_inet_init(); 55 if (rc != EOK) { 56 log_msg(LVL_ERROR, "Failed connecting to internet service."); 57 return ENOENT; 58 } 59 60 rc = udp_sock_init(); 61 if (rc != EOK) { 62 log_msg(LVL_ERROR, "Failed initializing socket service."); 63 return ENOENT; 64 } 65 66 return EOK; 67 } 68 69 int main(int argc, char **argv) 70 { 71 int rc; 72 73 printf(NAME ": UDP (User Datagram Protocol) service\n"); 74 75 rc = log_init(NAME, LVL_WARN); 76 if (rc != EOK) { 77 printf(NAME ": Failed to initialize log.\n"); 78 return 1; 79 } 80 81 rc = udp_init(); 82 if (rc != EOK) 83 return 1; 84 85 printf(NAME ": Accepting connections.\n"); 86 task_retval(0); 87 async_manager(); 88 89 /* Not reached */ 90 return 0; 91 } 92 93 /** 94 * @} 47 95 */ 48 typedef struct udp_globals udp_globals_t;49 50 /** UDP global data. */51 struct udp_globals {52 /** Networking module session. */53 async_sess_t *net_sess;54 /** IP module session. */55 async_sess_t *ip_sess;56 /** ICMP module session. */57 async_sess_t *icmp_sess;58 /** Packet dimension. */59 packet_dimension_t packet_dimension;60 /** Indicates whether UDP checksum computing is enabled. */61 int checksum_computing;62 /** Indicates whether UDP autobnding on send is enabled. */63 int autobinding;64 /** Last used free port. */65 int last_used_port;66 /** Active sockets. */67 socket_ports_t sockets;68 /** Device packet dimensions. */69 packet_dimensions_t dimensions;70 /** Safety lock. */71 fibril_rwlock_t lock;72 };73 74 #endif75 76 /** @}77 */ -
uspace/srv/net/udp/udp_inet.h
rd76a329 rb1213b0 1 1 /* 2 * Copyright (c) 20 09 Lukas Mejdrech2 * Copyright (c) 2011 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 27 27 */ 28 28 29 /** @addtogroup libnet29 /** @addtogroup udp 30 30 * @{ 31 31 */ 32 33 32 /** @file 34 * ICMP client interface.35 33 */ 36 34 37 #ifndef LIBNET_ICMP_CLIENT_H_38 #define LIBNET_ICMP_CLIENT_H_35 #ifndef UDP_INET_H 36 #define UDP_INET_H 39 37 40 #include <net/icmp_codes.h> 41 #include <net/packet.h> 38 #include "udp_type.h" 42 39 43 extern int icmp_client_process_packet(packet_t *, icmp_type_t *, icmp_code_t *, 44 icmp_param_t *, icmp_param_t *); 45 extern size_t icmp_client_header_length(packet_t *); 40 extern int udp_inet_init(void); 41 extern int udp_transmit_pdu(udp_pdu_t *); 46 42 47 43 #endif
Note:
See TracChangeset
for help on using the changeset viewer.