00001
00002
00003
00004
00005
00006
00007 #ifndef INET_IP_INT_H
00008 #define INET_IP_INT_H
00009
00010 #define IP_FD_NR (8*IP_PORT_MAX)
00011 #define IP_ASS_NR 3
00012
00013 #define IP_42BSD_BCAST 1
00014
00015
00016 #define IP_LT_NORMAL 0
00017 #define IP_LT_BROADCAST 1
00018 #define IP_LT_MULTICAST 2
00019
00020 struct ip_port;
00021 struct ip_fd;
00022 typedef void (*ip_dev_t) ARGS(( struct ip_port *ip_port ));
00023 typedef int (*ip_dev_send_t) ARGS(( struct ip_port *ip_port, ipaddr_t dest,
00024 acc_t *pack, int type ));
00025
00026 #define IP_PROTO_HASH_NR 32
00027
00028 typedef struct ip_port
00029 {
00030 int ip_flags, ip_dl_type;
00031 int ip_port;
00032 union
00033 {
00034 struct
00035 {
00036 int de_state;
00037 int de_flags;
00038 int de_port;
00039 int de_fd;
00040 acc_t *de_frame;
00041 acc_t *de_q_head;
00042 acc_t *de_q_tail;
00043 acc_t *de_arp_head;
00044 acc_t *de_arp_tail;
00045 } dl_eth;
00046 struct
00047 {
00048 int ps_port;
00049 acc_t *ps_send_head;
00050 acc_t *ps_send_tail;
00051 } dl_ps;
00052 } ip_dl;
00053 ipaddr_t ip_ipaddr;
00054 ipaddr_t ip_subnetmask;
00055 ipaddr_t ip_classfulmask;
00056 u16_t ip_frame_id;
00057 u16_t ip_mtu;
00058 u16_t ip_mtu_max;
00059 ip_dev_t ip_dev_main;
00060 ip_dev_t ip_dev_set_ipaddr;
00061 ip_dev_send_t ip_dev_send;
00062 acc_t *ip_loopb_head;
00063 acc_t *ip_loopb_tail;
00064 event_t ip_loopb_event;
00065 acc_t *ip_routeq_head;
00066 acc_t *ip_routeq_tail;
00067 event_t ip_routeq_event;
00068 struct ip_fd *ip_proto_any;
00069 struct ip_fd *ip_proto[IP_PROTO_HASH_NR];
00070 } ip_port_t;
00071
00072 #define IES_EMPTY 0x0
00073 #define IES_SETPROTO 0x1
00074 #define IES_GETIPADDR 0x2
00075 #define IES_MAIN 0x3
00076 #define IES_ERROR 0x4
00077
00078 #define IEF_EMPTY 0x1
00079 #define IEF_SUSPEND 0x8
00080 #define IEF_READ_IP 0x10
00081 #define IEF_READ_SP 0x20
00082 #define IEF_WRITE_SP 0x80
00083
00084 #define IPF_EMPTY 0x0
00085 #define IPF_CONFIGURED 0x1
00086 #define IPF_IPADDRSET 0x2
00087 #define IPF_NETMASKSET 0x4
00088 #define IPF_SUBNET_BCAST 0x8
00089
00090 #define IPDL_ETH NETTYPE_ETH
00091 #define IPDL_PSIP NETTYPE_PSIP
00092
00093 typedef struct ip_ass
00094 {
00095 acc_t *ia_frags;
00096 int ia_min_ttl;
00097 ip_port_t *ia_port;
00098 time_t ia_first_time;
00099 ipaddr_t ia_srcaddr, ia_dstaddr;
00100 int ia_proto, ia_id;
00101 } ip_ass_t;
00102
00103 typedef struct ip_fd
00104 {
00105 int if_flags;
00106 struct nwio_ipopt if_ipopt;
00107 ip_port_t *if_port;
00108 struct ip_fd *if_proto_next;
00109 int if_srfd;
00110 acc_t *if_rdbuf_head;
00111 acc_t *if_rdbuf_tail;
00112 get_userdata_t if_get_userdata;
00113 put_userdata_t if_put_userdata;
00114 put_pkt_t if_put_pkt;
00115 time_t if_exp_time;
00116 size_t if_rd_count;
00117 ioreq_t if_ioctl;
00118 } ip_fd_t;
00119
00120 #define IFF_EMPTY 0x00
00121 #define IFF_INUSE 0x01
00122 #define IFF_OPTSET 0x02
00123 #define IFF_BUSY 0x1C
00124 # define IFF_READ_IP 0x04
00125 # define IFF_IOCTL_IP 0x08
00126
00127 typedef enum nettype
00128 {
00129 IPNT_ZERO,
00130 IPNT_CLASS_A,
00131 IPNT_LOCAL,
00132 IPNT_CLASS_B,
00133 IPNT_CLASS_C,
00134 IPNT_CLASS_D,
00135 IPNT_CLASS_E,
00136 IPNT_MARTIAN,
00137 IPNT_BROADCAST
00138 } nettype_t;
00139
00140 struct nwio_ipconf;
00141
00142
00143 int ipeth_init ARGS(( ip_port_t *ip_port ));
00144
00145
00146 void ip_hash_proto ARGS(( ip_fd_t *ip_fd ));
00147 void ip_unhash_proto ARGS(( ip_fd_t *ip_fd ));
00148 int ip_setconf ARGS(( int ip_port, struct nwio_ipconf *ipconfp ));
00149
00150
00151 ipaddr_t ip_get_netmask ARGS(( ipaddr_t hostaddr ));
00152 ipaddr_t ip_get_ifaddr ARGS(( int ip_port_nr ));
00153 int ip_chk_hdropt ARGS(( u8_t *opt, int optlen ));
00154 void ip_print_frags ARGS(( acc_t *acc ));
00155 nettype_t ip_nettype ARGS(( ipaddr_t ipaddr ));
00156 ipaddr_t ip_netmask ARGS(( nettype_t nettype ));
00157 char *ip_nettoa ARGS(( nettype_t nettype ));
00158
00159
00160 int ipps_init ARGS(( ip_port_t *ip_port ));
00161 void ipps_get ARGS(( int ip_port_nr ));
00162 void ipps_put ARGS(( int ip_port_nr, ipaddr_t nexthop, acc_t *pack ));
00163
00164
00165 void ip_port_arrive ARGS(( ip_port_t *port, acc_t *pack, ip_hdr_t *ip_hdr ));
00166 void ip_arrived ARGS(( ip_port_t *port, acc_t *pack ));
00167 void ip_arrived_broadcast ARGS(( ip_port_t *port, acc_t *pack ));
00168 void ip_process_loopb ARGS(( event_t *ev, ev_arg_t arg ));
00169 void ip_packet2user ARGS(( ip_fd_t *ip_fd, acc_t *pack, time_t exp_time,
00170 size_t data_len ));
00171
00172
00173 void dll_eth_write_frame ARGS(( ip_port_t *port ));
00174 acc_t *ip_split_pack ARGS(( ip_port_t *ip_port, acc_t **ref_last, int mtu ));
00175 void ip_hdr_chksum ARGS(( ip_hdr_t *ip_hdr, int ip_hdr_len ));
00176
00177
00178 extern ip_fd_t ip_fd_table[IP_FD_NR];
00179 extern ip_port_t *ip_port_table;
00180 extern ip_ass_t ip_ass_table[IP_ASS_NR];
00181
00182 #define NWIO_DEFAULT (NWIO_EN_LOC | NWIO_EN_BROAD | NWIO_REMANY | \
00183 NWIO_RWDATALL | NWIO_HDR_O_SPEC)
00184
00185 #endif
00186
00187
00188
00189