Parent Directory
|
Revision Log
|
Revision Graph
pkts.c now uses the new modular API of request.c. Almost all the sources have been updated.
1 /* This file is part of Netsukuku 2 * (c) Copyright 2005 Andrea Lo Pumo aka AlpT <alpt@freaknet.org> 3 * 4 * This source code is free software; you can redistribute it and/or 5 * modify it under the terms of the GNU General Public License as published 6 * by the Free Software Foundation; either version 2 of the License, 7 * or (at your option) any later version. 8 * 9 * This source code is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 12 * Please refer to the GNU Public License for more details. 13 * 14 * You should have received a copy of the GNU Public License along with 15 * this source code; if not, write to: 16 * Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 17 */ 18 19 #ifndef ANDNA_H 20 #define ANDNA_H 21 22 #include "andna_cache.h" 23 #include "pkts.h" 24 25 #define MY_NAMESERV "nameserver 127.0.0.1" 26 #define MY_NAMESERV_IPV6 "nameserver ::1" 27 #define ETC_RESOLV_CONF "/etc/resolv.conf" 28 #define ETC_RESOLV_CONF_BAK "/etc/resolv.conf.bak" 29 30 /* How many different andna pkt can be flooded simultaneusly */ 31 #define ANDNA_MAX_FLOODS (ANDNA_MAX_QUEUE*3+1) 32 33 /* How many new hash_gnodes are supported in the andna hash_gnode mutation */ 34 #define ANDNA_MAX_NEW_GNODES 1024 35 36 /* 37 * These arrays keeps the latest reg_pkt and counter_check IDs to drop pkts 38 * alreay received during the floods. These arrays are a FIFO, so the 39 * last pkt_id will be always at the 0 position, while the first one will be 40 * at the last position 41 */ 42 int last_reg_pkt_id[ANDNA_MAX_FLOODS]; 43 int last_counter_pkt_id[ANDNA_MAX_FLOODS]; 44 int last_spread_acache_pkt_id[ANDNA_MAX_FLOODS]; 45 46 /*\ 47 * 48 * ANDNA hash notes 49 * ==================== 50 * 51 * In ANDNA there are three type of hashes: MD5, 32bit, 32bit hash of a MD5 52 * hash. These hashes are generally applied on hostnames. 53 * 54 * The andna_hash() function, defined in andna.c, is used to calculate 55 * the IP of a hash_node/hash_gnode/counter_node. It makes a MD5 digest of the 56 * input data. If we are working on ipv4, then a 32bit hash is applied to the 57 * previously calculated MD5 digest. The result is the IP of the hash_gnode. 58 * If we are in ipv6, we'll use directly the MD5 digest as the hash_gnode IP. 59 * 60 * In all the other cases we'll use directly the MD5 hash of the hostname, 61 * f.e. the hname hash of the registration and resolution packets is a MD5. 62 * The only exceptions are the lcl_cache and the rh_cache, which use 63 * internally a 32bit hash to speed up the hname lookups. 64 * 65 * The general guideline for new implementation is to always use big hashes 66 * (i.e. MD5) where we might get collisions (f.e in an andna_cache), and to 67 * use small hashes where we are safe (f.e. in the rhc_cache). 68 * 69 \*/ 70 71 72 /*\ 73 * 74 * * * * ANDNA requests/replies pkt stuff * * * 75 * 76 \*/ 77 78 /* 79 * The ANDNA requests and replies 80 */ 81 82 /* requests */ 83 rq_t ANDNA_REGISTER_HNAME, 84 ANDNA_CHECK_COUNTER, 85 ANDNA_RESOLVE_HNAME, 86 ANDNA_RESOLVE_IP, 87 ANDNA_RESOLVE_MX, 88 ANDNA_GET_ANDNA_CACHE, 89 ANDNA_GET_SINGLE_ACACHE, /* Check request for the counter node */ 90 ANDNA_SPREAD_SACACHE, /* Spread the single andna_cache */ 91 ANDNA_GET_COUNT_CACHE; 92 93 /* replies */ 94 re_t ANDNA_RESOLVE_REPLY, 95 ANDNA_REV_RESOLVE_REPLY, 96 ANDNA_MX_RESOLVE_REPLY, 97 ANDNA_PUT_COUNT_CACHE, 98 ANDNA_PUT_ANDNA_CACHE; 99 100 /* request errors */ 101 rqerr_t E_ANDNA_WRONG_HASH_GNODE, 102 E_ANDNA_QUEUE_FULL, 103 E_ANDNA_UPDATE_TOO_EARLY, 104 E_ANDNA_TOO_MANY_HNAME, 105 E_ANDNA_HUPDATE_MISMATCH, 106 E_ANDNA_NO_HNAME, 107 E_ANDNA_CHECK_COUNTER, 108 E_ANDNA_INVALID_SIGNATURE; 109 110 #define ANDNA_HOOK_TIMEOUT 8 /* seconds */ 111 #define ANDNA_REV_RESOLVE_RQ_TIMEOUT 60 112 113 /* * * andna pkt flags * * */ 114 #define ANDNA_PKT_UPDATE 1 /* Update the hostname */ 115 #define ANDNA_PKT_FORWARD (1<<1) /* Forward this pkt, plz */ 116 #define ANDNA_PKT_REV_RESOLVE (1<<2) /* Give me your hostnames */ 117 #define ANDNA_PKT_JUST_CHECK (1<<3) /* Check only, don't update 118 anything */ 119 #define ANDNA_PKT_SNSD_DEL (1<<4) /* SNSD delete request */ 120 121 /* 122 * andna_reg_pkt 123 * 124 * Andna registration request pkt used to send the registration and update 125 * requests to the hash_gnode, backup_gnode and counter_gnode. 126 * When the pkt is sent to a counter_gnode, a second `rip', which is the ip 127 * of the hash_gnode who is contacting the counter_gnode, is appended at the 128 * end of the pkt. 129 * 130 * When the packet is sent to a hash_gnode, at the end of the packet is 131 * included a packed snsd_service linked list. It is the list of snsd_records 132 * that have to be registered. However the packet forwarded to the counter 133 * node won't keep this part. 134 */ 135 struct andna_reg_pkt 136 { 137 u_int rip[MAX_IP_INT]; /* register_node ip */ 138 u_int hash[MAX_IP_INT]; /* md5 hash of the host name to 139 register. */ 140 char pubkey[ANDNA_PKEY_LEN]; /* public key of the register 141 node. */ 142 u_short hname_updates; /* number of updates already 143 made for the hostname */ 144 145 char sign[ANDNA_SIGNATURE_LEN]; /* RSA signature of the 146 entire pkt (excluding 147 `sign' itself and `flags' 148 */ 149 char flags; 150 151 } _PACKED_; 152 #define ANDNA_REG_PKT_SZ (sizeof(struct andna_reg_pkt)) 153 #define ANDNA_REG_SIGNED_BLOCK_SZ (ANDNA_REG_PKT_SZ - ANDNA_SIGNATURE_LEN - \ 154 sizeof(char)) 155 INT_INFO andna_reg_pkt_iinfo = { 1, /* `rip' and `hash' aren't considered */ 156 { INT_TYPE_16BIT }, 157 { MAX_IP_SZ*2 + ANDNA_PKEY_LEN }, 158 { 1 }, 159 }; 160 161 162 /* 163 * andna_resolve_rq_pkt 164 * 165 * The andna resolve request pkt is used to resolve hostnames, IPs and MX 166 * hostnames. 167 */ 168 struct andna_resolve_rq_pkt 169 { 170 u_int rip[MAX_IP_INT]; /* the ip of the requester node */ 171 char flags; 172 173 u_int hash[MAX_IP_INT]; /* md5 hash of the hostname to 174 resolve. */ 175 int service; /* the snsd service of the hname */ 176 u_char proto; /* the protocol of `service' */ 177 } _PACKED_; 178 #define ANDNA_RESOLVE_RQ_PKT_SZ (sizeof(struct andna_resolve_rq_pkt)) 179 INT_INFO andna_resolve_rq_pkt_iinfo = { 1, /* `rip' and `hash' are ignored */ 180 { INT_TYPE_32BIT }, 181 { MAX_IP_SZ*2+sizeof(char) }, 182 { 1 }, 183 }; 184 185 /* 186 * The reply to the resolve request 187 */ 188 struct andna_resolve_reply_pkt 189 { 190 uint32_t timestamp; /* the difference between the current 191 time and the last time the resolved 192 hname was updated */ 193 /* 194 * the rest of the pkt is a pack of one snsd_service llist: 195 * char service[SNSD_SERVICE_LLIST_PACK_SZ(service)]; 196 */ 197 } _PACKED_; 198 #define ANDNA_RESOLVE_REPLY_PKT_SZ (sizeof(struct andna_resolve_reply_pkt)) 199 INT_INFO andna_resolve_reply_pkt_iinfo = { 1, /* `ip' is ignored */ 200 { INT_TYPE_32BIT }, 201 { 0 }, 202 { 1 } 203 }; 204 205 206 /* 207 * The reply to the reverse resolve request is just the packed local cache. 208 */ 209 210 211 /* 212 * single_acache 213 * 214 * The single_acache pkt is used to get from an old hash_gnode a single 215 * andna_cache, which has the wanted `hash'. Its propagation method is similar 216 * to that of andna_resolve_rq_pkt, but each new hash_gnode, which receives 217 * the pkt, adds in the body pkt its ip. The added ips are used as excluded 218 * hash_gnode by find_hash_gnode(). In this way each time an old hash_gnode 219 * receives the pkt, can verify if it is, at that current time, the true old 220 * hash_gnode by excluding the hash_gnodes listed in the pkt body. If it 221 * notices that there's an hash_gnode older than it, it will append its ip in 222 * the pkt body and will forward it to that older hash_gnode. And so on, until 223 * the pkt reaches a true old hash_gnode, or cannot be forwarded anymore since 224 * there are no more older hash_gnodes. 225 */ 226 struct single_acache_hdr 227 { 228 u_int rip[MAX_IP_INT]; /* the ip of the requester node */ 229 u_int hash[MAX_IP_INT]; 230 u_short hgnodes; /* Number of hgnodes in the 231 body. */ 232 u_char flags; 233 } _PACKED_; 234 INT_INFO single_acache_hdr_iinfo = { 1, /* `rip' and `hash' are ignored */ 235 { INT_TYPE_16BIT }, 236 { MAX_IP_SZ*2 }, 237 { 1 }, 238 }; 239 /* 240 * The single_acache body is: 241 * struct { 242 * u_int hgnode[MAX_IP_INT]; 243 * } body[new_hash_gnode_hdr.hgnodes]; 244 */ 245 #define SINGLE_ACACHE_PKT_SZ(hgnodes) (sizeof(struct single_acache_hdr)+\ 246 MAX_IP_SZ*(hgnodes)) 247 248 /* 249 * The single_acache_reply is just an andna_cache_pkt with a single cache. 250 */ 251 252 253 /* 254 * Tell the node, which receives the pkt, to send a ANDNA_GET_SINGLE_ACACHE 255 * request to fetch the andna_cache for the `hash' included in the pkt. 256 */ 257 struct spread_acache_pkt 258 { 259 u_int hash[MAX_IP_INT]; 260 } _PACKED_; 261 #define SPREAD_ACACHE_PKT_SZ (sizeof(struct spread_acache_pkt)) 262 INT_INFO spread_acache_pkt_info = { 0, { 0 }, { 0 }, { 0 } }; 263 264 265 266 /*\ 267 * 268 * * * * Function declaration * * * 269 * 270 \*/ 271 272 int andna_load_caches(void); 273 int andna_save_caches(void); 274 275 void andna_init(void); 276 void andna_close(void); 277 void andna_resolvconf_modify(void); 278 void andna_resolvconf_restore(void); 279 280 int andna_register_hname(lcl_cache *alcl, snsd_service *snsd_delete); 281 int andna_recv_reg_rq(PACKET rpkt); 282 283 int andna_check_counter(PACKET pkt); 284 int andna_recv_check_counter(PACKET rpkt); 285 286 snsd_service *andna_resolve_hash(u_int hname_hash[MAX_IP_INT], int service, 287 u_char proto, int *records); 288 snsd_service *andna_resolve_hname(char *hname, int service, u_char proto, 289 int *records); 290 int andna_recv_resolve_rq(PACKET rpkt); 291 292 lcl_cache *andna_reverse_resolve(inet_prefix ip); 293 int andna_recv_rev_resolve_rq(PACKET rpkt); 294 295 int spread_single_acache(u_int hash[MAX_IP_INT]); 296 int recv_spread_single_acache(PACKET rpkt); 297 andna_cache *get_single_andna_c(u_int hash[MAX_IP_INT], u_int hash_gnode[MAX_IP_INT]); 298 int put_single_acache(PACKET rpkt); 299 int put_andna_cache(PACKET rq_pkt); 300 int put_counter_cache(PACKET rq_pkt); 301 302 void *andna_hook(void *); 303 void andna_update_hnames(int only_new_hname); 304 void *andna_maintain_hnames_active(void *null); 305 void *andna_main(void *); 306 307 #endif /*ANDNA_H*/
| alpt (at) freaknet (dot) org | ViewVC Help |
| Powered by ViewVC 1.1-dev |