1c22d69bfSAxel Dörfler /* 22b415445SAxel Dörfler * Copyright 2006-2010, Haiku, Inc. All Rights Reserved. 3c22d69bfSAxel Dörfler * Distributed under the terms of the MIT License. 4c22d69bfSAxel Dörfler */ 5c22d69bfSAxel Dörfler #ifndef NET_PROTOCOL_H 6c22d69bfSAxel Dörfler #define NET_PROTOCOL_H 7c22d69bfSAxel Dörfler 8c22d69bfSAxel Dörfler 9c22d69bfSAxel Dörfler #include <net_buffer.h> 10c22d69bfSAxel Dörfler #include <net_socket.h> 11c22d69bfSAxel Dörfler 12c22d69bfSAxel Dörfler 132b415445SAxel Dörfler struct ancillary_data_container; 142b415445SAxel Dörfler struct ancillary_data_header; 152b415445SAxel Dörfler struct iovec; 162b415445SAxel Dörfler typedef struct net_domain net_domain; 172b415445SAxel Dörfler typedef struct net_route net_route; 182b415445SAxel Dörfler 192b415445SAxel Dörfler 20c22d69bfSAxel Dörfler // level flags to pass to control() 21c22d69bfSAxel Dörfler #define LEVEL_SET_OPTION 0x10000000 22c22d69bfSAxel Dörfler #define LEVEL_GET_OPTION 0x20000000 23c22d69bfSAxel Dörfler #define LEVEL_DRIVER_IOCTL 0x0f000000 24c22d69bfSAxel Dörfler #define LEVEL_MASK 0x0fffffff 25c22d69bfSAxel Dörfler 262b415445SAxel Dörfler // Error codes for error_received(), and error_reply() 272b415445SAxel Dörfler enum net_error { 282b415445SAxel Dörfler B_NET_ERROR_REDIRECT_HOST = 1, 292b415445SAxel Dörfler B_NET_ERROR_UNREACH_NET, 302b415445SAxel Dörfler B_NET_ERROR_UNREACH_HOST, 312b415445SAxel Dörfler B_NET_ERROR_UNREACH_PROTOCOL, 322b415445SAxel Dörfler B_NET_ERROR_UNREACH_PORT, 332b415445SAxel Dörfler B_NET_ERROR_MESSAGE_SIZE, 342b415445SAxel Dörfler B_NET_ERROR_TRANSIT_TIME_EXCEEDED, 352b415445SAxel Dörfler B_NET_ERROR_REASSEMBLY_TIME_EXCEEDED, 362b415445SAxel Dörfler B_NET_ERROR_PARAMETER_PROBLEM, 372b415445SAxel Dörfler B_NET_ERROR_QUENCH, 382b415445SAxel Dörfler }; 3949e00d1fSIngo Weinhold 402b415445SAxel Dörfler typedef union net_error_data { 412b415445SAxel Dörfler struct sockaddr_storage gateway; 422b415445SAxel Dörfler uint32 mtu; 432b415445SAxel Dörfler uint32 error_offset; 442b415445SAxel Dörfler } net_error_data; 45cdc00dadSIngo Weinhold 46c22d69bfSAxel Dörfler typedef struct net_protocol { 47c22d69bfSAxel Dörfler struct net_protocol* next; 48c22d69bfSAxel Dörfler struct net_protocol_module_info* module; 49c22d69bfSAxel Dörfler net_socket* socket; 50c22d69bfSAxel Dörfler } net_protocol; 51c22d69bfSAxel Dörfler 522b415445SAxel Dörfler 536f58064fSAxel Dörfler // net_protocol_module_info::flags field 546f58064fSAxel Dörfler #define NET_PROTOCOL_ATOMIC_MESSAGES 0x01 556f58064fSAxel Dörfler 562b415445SAxel Dörfler 57c22d69bfSAxel Dörfler struct net_protocol_module_info { 58c22d69bfSAxel Dörfler module_info info; 596f58064fSAxel Dörfler uint32 flags; 60c22d69bfSAxel Dörfler 61c22d69bfSAxel Dörfler net_protocol* (*init_protocol)(net_socket* socket); 62c22d69bfSAxel Dörfler status_t (*uninit_protocol)(net_protocol* self); 63c22d69bfSAxel Dörfler 64c22d69bfSAxel Dörfler status_t (*open)(net_protocol* self); 65c22d69bfSAxel Dörfler status_t (*close)(net_protocol* self); 66c22d69bfSAxel Dörfler status_t (*free)(net_protocol* self); 67c22d69bfSAxel Dörfler 68c22d69bfSAxel Dörfler status_t (*connect)(net_protocol* self, const struct sockaddr* address); 692b415445SAxel Dörfler status_t (*accept)(net_protocol* self, net_socket** _acceptedSocket); 702b415445SAxel Dörfler status_t (*control)(net_protocol* self, int level, int option, 712b415445SAxel Dörfler void* value, size_t* _length); 722445c00eSHugo Santos status_t (*getsockopt)(net_protocol* self, int level, int option, 732445c00eSHugo Santos void* value, int* _length); 742445c00eSHugo Santos status_t (*setsockopt)(net_protocol* self, int level, int option, 752445c00eSHugo Santos const void* value, int length); 76c22d69bfSAxel Dörfler 7753f23f85SHugo Santos status_t (*bind)(net_protocol* self, const struct sockaddr* address); 78c22d69bfSAxel Dörfler status_t (*unbind)(net_protocol* self, struct sockaddr* address); 79c22d69bfSAxel Dörfler status_t (*listen)(net_protocol* self, int count); 80c22d69bfSAxel Dörfler status_t (*shutdown)(net_protocol* self, int direction); 81c22d69bfSAxel Dörfler 82c22d69bfSAxel Dörfler status_t (*send_data)(net_protocol* self, net_buffer* buffer); 832b415445SAxel Dörfler status_t (*send_routed_data)(net_protocol* self, net_route* route, 842b415445SAxel Dörfler net_buffer* buffer); 85c22d69bfSAxel Dörfler ssize_t (*send_avail)(net_protocol* self); 86c22d69bfSAxel Dörfler 87c22d69bfSAxel Dörfler status_t (*read_data)(net_protocol* self, size_t numBytes, uint32 flags, 88c22d69bfSAxel Dörfler net_buffer** _buffer); 89c22d69bfSAxel Dörfler ssize_t (*read_avail)(net_protocol* self); 90c22d69bfSAxel Dörfler 912b415445SAxel Dörfler net_domain* (*get_domain)(net_protocol* self); 92c22d69bfSAxel Dörfler size_t (*get_mtu)(net_protocol* self, const struct sockaddr* address); 93c22d69bfSAxel Dörfler 94c22d69bfSAxel Dörfler status_t (*receive_data)(net_buffer* data); 952b415445SAxel Dörfler status_t (*deliver_data)(net_protocol* self, net_buffer* data); 96c22d69bfSAxel Dörfler 972b415445SAxel Dörfler status_t (*error_received)(net_error error, net_buffer* data); 982b415445SAxel Dörfler status_t (*error_reply)(net_protocol* self, net_buffer* cause, 992b415445SAxel Dörfler net_error error, net_error_data* errorData); 10097cdbb54SIngo Weinhold 10149e00d1fSIngo Weinhold status_t (*add_ancillary_data)(net_protocol* self, 10249e00d1fSIngo Weinhold ancillary_data_container* container, const cmsghdr* header); 10397cdbb54SIngo Weinhold ssize_t (*process_ancillary_data)(net_protocol* self, 104*36708e6aSAugustin Cavalier const ancillary_data_container* container, 10597cdbb54SIngo Weinhold void* buffer, size_t bufferSize); 10678888c44SAxel Dörfler ssize_t (*process_ancillary_data_no_container)(net_protocol* self, 107b78c74fdSMichael Lotz net_buffer* buffer, void* data, size_t bufferSize); 108cdc00dadSIngo Weinhold 109cdc00dadSIngo Weinhold ssize_t (*send_data_no_buffer)(net_protocol* self, const iovec* vecs, 110cdc00dadSIngo Weinhold size_t vecCount, ancillary_data_container* ancillaryData, 11134874537SJérôme Duval const struct sockaddr* address, socklen_t addressLength, 11234874537SJérôme Duval int flags); 113cdc00dadSIngo Weinhold ssize_t (*read_data_no_buffer)(net_protocol* self, const iovec* vecs, 114cdc00dadSIngo Weinhold size_t vecCount, ancillary_data_container** _ancillaryData, 115b761f925SJérôme Duval struct sockaddr* _address, socklen_t* _addressLength, 116b761f925SJérôme Duval int flags); 117c22d69bfSAxel Dörfler }; 118c22d69bfSAxel Dörfler 1192b415445SAxel Dörfler 120c22d69bfSAxel Dörfler #endif // NET_PROTOCOL_H 121