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 mutex 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 uint32 flags; 48 }; 49 50 typedef int32 (*net_deframe_func)(struct net_device *device, 51 struct net_buffer *buffer); 52 typedef status_t (*net_receive_func)(void *cookie, struct net_device *device, 53 struct net_buffer *buffer); 54 55 enum { 56 B_DEVICE_GOING_UP = 1, 57 B_DEVICE_GOING_DOWN, 58 B_DEVICE_BEING_REMOVED, 59 }; 60 61 struct net_device_monitor { 62 struct list_link link; 63 void *cookie; 64 65 status_t (*receive)(struct net_device_monitor *monitor, 66 struct net_buffer *buffer); 67 void (*event)(struct net_device_monitor *monitor, int32 event); 68 }; 69 70 typedef struct ancillary_data_header { 71 int level; 72 int type; 73 size_t len; 74 } ancillary_data_header; 75 76 struct net_stack_module_info { 77 module_info info; 78 79 status_t (*register_domain)(int family, const char *name, 80 struct net_protocol_module_info *module, 81 struct net_address_module_info *addressModule, 82 struct net_domain **_domain); 83 status_t (*unregister_domain)(struct net_domain *domain); 84 struct net_domain *(*get_domain)(int family); 85 86 status_t (*register_domain_protocols)(int family, int type, int protocol, ...); 87 status_t (*register_domain_datalink_protocols)(int family, int type, ...); 88 status_t (*register_domain_receiving_protocol)(int family, int type, 89 const char *moduleName); 90 91 status_t (*get_domain_receiving_protocol)(struct net_domain *domain, 92 uint32 type, struct net_protocol_module_info **_module); 93 status_t (*put_domain_receiving_protocol)(struct net_domain *domain, 94 uint32 type); 95 96 // devices 97 status_t (*register_device_deframer)(struct net_device *device, 98 net_deframe_func deframeFunc); 99 status_t (*unregister_device_deframer)(struct net_device *device); 100 101 status_t (*register_domain_device_handler)(struct net_device *device, 102 int32 type, struct net_domain *domain); 103 status_t (*register_device_handler)(struct net_device *device, int32 type, 104 net_receive_func receiveFunc, void *cookie); 105 status_t (*unregister_device_handler)(struct net_device *device, int32 type); 106 107 status_t (*register_device_monitor)(struct net_device *device, 108 struct net_device_monitor *monitor); 109 status_t (*unregister_device_monitor)(struct net_device *device, 110 struct net_device_monitor *monitor); 111 112 status_t (*device_link_changed)(struct net_device *device); 113 status_t (*device_removed)(struct net_device *device); 114 115 status_t (*device_enqueue_buffer)(struct net_device *device, 116 struct net_buffer *buffer); 117 118 // Utility Functions 119 120 // notification 121 status_t (*notify_socket)(struct net_socket *socket, uint8 event, 122 int32 value); 123 124 // checksum 125 uint16 (*checksum)(uint8 *buffer, size_t length); 126 127 // fifo 128 status_t (*init_fifo)(struct net_fifo *fifo, const char *name, 129 size_t maxBytes); 130 void (*uninit_fifo)(struct net_fifo *fifo); 131 status_t (*fifo_enqueue_buffer)(struct net_fifo *fifo, 132 struct net_buffer *buffer); 133 ssize_t (*fifo_dequeue_buffer)(struct net_fifo *fifo, uint32 flags, 134 bigtime_t timeout, struct net_buffer **_buffer); 135 status_t (*clear_fifo)(struct net_fifo *fifo); 136 status_t (*fifo_socket_enqueue_buffer)(struct net_fifo *fifo, 137 struct net_socket *socket, uint8 event, 138 struct net_buffer *buffer); 139 140 // timer 141 void (*init_timer)(struct net_timer *timer, net_timer_func hook, void *data); 142 void (*set_timer)(struct net_timer *timer, bigtime_t delay); 143 bool (*cancel_timer)(struct net_timer *timer); 144 status_t (*wait_for_timer)(struct net_timer *timer); 145 bool (*is_timer_active)(struct net_timer *timer); 146 bool (*is_timer_running)(struct net_timer *timer); 147 148 // syscall restart 149 bool (*is_syscall)(void); 150 bool (*is_restarted_syscall)(void); 151 void (*store_syscall_restart_timeout)(bigtime_t timeout); 152 bigtime_t (*restore_syscall_restart_timeout)(void); 153 154 // ancillary data 155 ancillary_data_container* (*create_ancillary_data_container)(); 156 void (*delete_ancillary_data_container)( 157 ancillary_data_container* container); 158 status_t (*add_ancillary_data)(ancillary_data_container *container, 159 const ancillary_data_header *header, const void *data, 160 void (*destructor)(const ancillary_data_header*, void*), 161 void **_allocatedData); 162 status_t (*remove_ancillary_data)(ancillary_data_container *container, 163 void *data, bool destroy); 164 void* (*move_ancillary_data)(ancillary_data_container *from, 165 ancillary_data_container *to); 166 void* (*next_ancillary_data)(ancillary_data_container *container, 167 void *previousData, ancillary_data_header *_header); 168 }; 169 170 #endif // NET_STACK_H 171