1 /* 2 * Copyright 2006-2008, Haiku, Inc. All Rights Reserved. 3 * Distributed under the terms of the MIT License. 4 */ 5 #ifndef NET_STACK_H 6 #define NET_STACK_H 7 8 9 #include <lock.h> 10 #include <util/list.h> 11 12 #include <module.h> 13 14 15 #define NET_STACK_MODULE_NAME "network/stack/v1" 16 17 18 struct net_address_module_info; 19 struct net_protocol_module_info; 20 21 struct net_buffer; 22 struct net_device; 23 struct net_domain; 24 struct net_socket; 25 struct net_timer; 26 27 typedef struct ancillary_data_container ancillary_data_container; 28 29 struct net_fifo { 30 benaphore lock; 31 sem_id notify; 32 int32 waiting; 33 34 size_t max_bytes; 35 size_t current_bytes; 36 37 struct list buffers; 38 }; 39 40 typedef void (*net_timer_func)(struct net_timer *timer, void *data); 41 42 struct net_timer { 43 struct list_link link; 44 net_timer_func hook; 45 void *data; 46 bigtime_t due; 47 }; 48 49 typedef int32 (*net_deframe_func)(struct net_device *device, 50 struct net_buffer *buffer); 51 typedef status_t (*net_receive_func)(void *cookie, struct net_device *device, 52 struct net_buffer *buffer); 53 54 enum { 55 B_DEVICE_GOING_UP = 1, 56 B_DEVICE_GOING_DOWN, 57 B_DEVICE_BEING_REMOVED, 58 }; 59 60 struct net_device_monitor { 61 struct list_link link; 62 void *cookie; 63 64 status_t (*receive)(struct net_device_monitor *monitor, 65 struct net_buffer *buffer); 66 void (*event)(struct net_device_monitor *monitor, int32 event); 67 }; 68 69 typedef struct ancillary_data_header { 70 int level; 71 int type; 72 size_t len; 73 } ancillary_data_header; 74 75 struct net_stack_module_info { 76 module_info info; 77 78 status_t (*register_domain)(int family, const char *name, 79 struct net_protocol_module_info *module, 80 struct net_address_module_info *addressModule, 81 struct net_domain **_domain); 82 status_t (*unregister_domain)(struct net_domain *domain); 83 struct net_domain *(*get_domain)(int family); 84 85 status_t (*register_domain_protocols)(int family, int type, int protocol, ...); 86 status_t (*register_domain_datalink_protocols)(int family, int type, ...); 87 status_t (*register_domain_receiving_protocol)(int family, int type, 88 const char *moduleName); 89 90 status_t (*get_domain_receiving_protocol)(struct net_domain *domain, 91 uint32 type, struct net_protocol_module_info **_module); 92 status_t (*put_domain_receiving_protocol)(struct net_domain *domain, 93 uint32 type); 94 95 // devices 96 status_t (*register_device_deframer)(struct net_device *device, 97 net_deframe_func deframeFunc); 98 status_t (*unregister_device_deframer)(struct net_device *device); 99 100 status_t (*register_domain_device_handler)(struct net_device *device, 101 int32 type, struct net_domain *domain); 102 status_t (*register_device_handler)(struct net_device *device, int32 type, 103 net_receive_func receiveFunc, void *cookie); 104 status_t (*unregister_device_handler)(struct net_device *device, int32 type); 105 106 status_t (*register_device_monitor)(struct net_device *device, 107 struct net_device_monitor *monitor); 108 status_t (*unregister_device_monitor)(struct net_device *device, 109 struct net_device_monitor *monitor); 110 111 status_t (*device_link_changed)(struct net_device *device); 112 status_t (*device_removed)(struct net_device *device); 113 114 status_t (*device_enqueue_buffer)(struct net_device *device, 115 struct net_buffer *buffer); 116 117 // Utility Functions 118 119 // notification 120 status_t (*notify_socket)(struct net_socket *socket, uint8 event, 121 int32 value); 122 123 // checksum 124 uint16 (*checksum)(uint8 *buffer, size_t length); 125 126 // fifo 127 status_t (*init_fifo)(struct net_fifo *fifo, const char *name, 128 size_t maxBytes); 129 void (*uninit_fifo)(struct net_fifo *fifo); 130 status_t (*fifo_enqueue_buffer)(struct net_fifo *fifo, 131 struct net_buffer *buffer); 132 ssize_t (*fifo_dequeue_buffer)(struct net_fifo *fifo, uint32 flags, 133 bigtime_t timeout, struct net_buffer **_buffer); 134 status_t (*clear_fifo)(struct net_fifo *fifo); 135 status_t (*fifo_socket_enqueue_buffer)(struct net_fifo *fifo, 136 struct net_socket *socket, uint8 event, 137 struct net_buffer *buffer); 138 139 // timer 140 void (*init_timer)(struct net_timer *timer, net_timer_func hook, void *data); 141 void (*set_timer)(struct net_timer *timer, bigtime_t delay); 142 bool (*cancel_timer)(struct net_timer *timer); 143 bool (*is_timer_active)(struct net_timer *timer); 144 145 // syscall restart 146 bool (*is_syscall)(void); 147 bool (*is_restarted_syscall)(void); 148 void (*store_syscall_restart_timeout)(bigtime_t timeout); 149 bigtime_t (*restore_syscall_restart_timeout)(void); 150 151 // ancillary data 152 ancillary_data_container* (*create_ancillary_data_container)(); 153 void (*delete_ancillary_data_container)( 154 ancillary_data_container* container); 155 status_t (*add_ancillary_data)(ancillary_data_container *container, 156 const ancillary_data_header *header, const void *data, 157 void (*destructor)(const ancillary_data_header*, void*), 158 void **_allocatedData); 159 status_t (*remove_ancillary_data)(ancillary_data_container *container, 160 void *data, bool destroy); 161 void* (*move_ancillary_data)(ancillary_data_container *from, 162 ancillary_data_container *to); 163 void* (*next_ancillary_data)(ancillary_data_container *container, 164 void *previousData, ancillary_data_header *_header); 165 }; 166 167 #endif // NET_STACK_H 168