version 1.1, 2012/02/21 17:26:12
|
version 1.1.1.3, 2016/11/02 10:09:11
|
Line 27
|
Line 27
|
#include "sockunion.h" |
#include "sockunion.h" |
#include "memory.h" |
#include "memory.h" |
#include "log.h" |
#include "log.h" |
| |
/* Maskbit. */ |
/* Maskbit. */ |
static const u_char maskbit[] = {0x00, 0x80, 0xc0, 0xe0, 0xf0, |
static const u_char maskbit[] = {0x00, 0x80, 0xc0, 0xe0, 0xf0, |
0xf8, 0xfc, 0xfe, 0xff}; |
0xf8, 0xfc, 0xfe, 0xff}; |
|
|
|
static const struct in6_addr maskbytes6[] = |
|
{ |
|
/* /0 */ { { { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } }, |
|
/* /1 */ { { { 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } }, |
|
/* /2 */ { { { 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } }, |
|
/* /3 */ { { { 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } }, |
|
/* /4 */ { { { 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } }, |
|
/* /5 */ { { { 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } }, |
|
/* /6 */ { { { 0xfc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } }, |
|
/* /7 */ { { { 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } }, |
|
/* /8 */ { { { 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } }, |
|
/* /9 */ { { { 0xff, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } }, |
|
/* /10 */ { { { 0xff, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } }, |
|
/* /11 */ { { { 0xff, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } }, |
|
/* /12 */ { { { 0xff, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } }, |
|
/* /13 */ { { { 0xff, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } }, |
|
/* /14 */ { { { 0xff, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } }, |
|
/* /15 */ { { { 0xff, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } }, |
|
/* /16 */ { { { 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } }, |
|
/* /17 */ { { { 0xff, 0xff, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } }, |
|
/* /18 */ { { { 0xff, 0xff, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } }, |
|
/* /19 */ { { { 0xff, 0xff, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } }, |
|
/* /20 */ { { { 0xff, 0xff, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } }, |
|
/* /21 */ { { { 0xff, 0xff, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } }, |
|
/* /22 */ { { { 0xff, 0xff, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } }, |
|
/* /23 */ { { { 0xff, 0xff, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } }, |
|
/* /24 */ { { { 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } }, |
|
/* /25 */ { { { 0xff, 0xff, 0xff, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } }, |
|
/* /26 */ { { { 0xff, 0xff, 0xff, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } }, |
|
/* /27 */ { { { 0xff, 0xff, 0xff, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } }, |
|
/* /28 */ { { { 0xff, 0xff, 0xff, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } }, |
|
/* /29 */ { { { 0xff, 0xff, 0xff, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } }, |
|
/* /30 */ { { { 0xff, 0xff, 0xff, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } }, |
|
/* /31 */ { { { 0xff, 0xff, 0xff, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } }, |
|
/* /32 */ { { { 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } }, |
|
/* /33 */ { { { 0xff, 0xff, 0xff, 0xff, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } }, |
|
/* /34 */ { { { 0xff, 0xff, 0xff, 0xff, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } }, |
|
/* /35 */ { { { 0xff, 0xff, 0xff, 0xff, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } }, |
|
/* /36 */ { { { 0xff, 0xff, 0xff, 0xff, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } }, |
|
/* /37 */ { { { 0xff, 0xff, 0xff, 0xff, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } }, |
|
/* /38 */ { { { 0xff, 0xff, 0xff, 0xff, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } }, |
|
/* /39 */ { { { 0xff, 0xff, 0xff, 0xff, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } }, |
|
/* /40 */ { { { 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } }, |
|
/* /41 */ { { { 0xff, 0xff, 0xff, 0xff, 0xff, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } }, |
|
/* /42 */ { { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } }, |
|
/* /43 */ { { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } }, |
|
/* /44 */ { { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } }, |
|
/* /45 */ { { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } }, |
|
/* /46 */ { { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } }, |
|
/* /47 */ { { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } }, |
|
/* /48 */ { { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } }, |
|
/* /49 */ { { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } }, |
|
/* /50 */ { { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } }, |
|
/* /51 */ { { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } }, |
|
/* /52 */ { { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } }, |
|
/* /53 */ { { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } }, |
|
/* /54 */ { { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } }, |
|
/* /55 */ { { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } }, |
|
/* /56 */ { { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } }, |
|
/* /57 */ { { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } }, |
|
/* /58 */ { { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } }, |
|
/* /59 */ { { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } }, |
|
/* /60 */ { { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } }, |
|
/* /61 */ { { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } }, |
|
/* /62 */ { { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } }, |
|
/* /63 */ { { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } }, |
|
/* /64 */ { { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } }, |
|
/* /65 */ { { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } }, |
|
/* /66 */ { { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } }, |
|
/* /67 */ { { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } }, |
|
/* /68 */ { { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } }, |
|
/* /69 */ { { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } }, |
|
/* /70 */ { { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } }, |
|
/* /71 */ { { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } }, |
|
/* /72 */ { { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } }, |
|
/* /73 */ { { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } }, |
|
/* /74 */ { { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } }, |
|
/* /75 */ { { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } }, |
|
/* /76 */ { { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } }, |
|
/* /77 */ { { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } }, |
|
/* /78 */ { { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } }, |
|
/* /79 */ { { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } }, |
|
/* /80 */ { { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } }, |
|
/* /81 */ { { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00 } } }, |
|
/* /82 */ { { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00 } } }, |
|
/* /83 */ { { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00 } } }, |
|
/* /84 */ { { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00 } } }, |
|
/* /85 */ { { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00 } } }, |
|
/* /86 */ { { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x00 } } }, |
|
/* /87 */ { { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00 } } }, |
|
/* /88 */ { { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00 } } }, |
|
/* /89 */ { { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x80, 0x00, 0x00, 0x00, 0x00 } } }, |
|
/* /90 */ { { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xc0, 0x00, 0x00, 0x00, 0x00 } } }, |
|
/* /91 */ { { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xe0, 0x00, 0x00, 0x00, 0x00 } } }, |
|
/* /92 */ { { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf0, 0x00, 0x00, 0x00, 0x00 } } }, |
|
/* /93 */ { { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf8, 0x00, 0x00, 0x00, 0x00 } } }, |
|
/* /94 */ { { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfc, 0x00, 0x00, 0x00, 0x00 } } }, |
|
/* /95 */ { { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0x00, 0x00, 0x00, 0x00 } } }, |
|
/* /96 */ { { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00 } } }, |
|
/* /97 */ { { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x80, 0x00, 0x00, 0x00 } } }, |
|
/* /98 */ { { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xc0, 0x00, 0x00, 0x00 } } }, |
|
/* /99 */ { { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xe0, 0x00, 0x00, 0x00 } } }, |
|
/* /100 */ { { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf0, 0x00, 0x00, 0x00 } } }, |
|
/* /101 */ { { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf8, 0x00, 0x00, 0x00 } } }, |
|
/* /102 */ { { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfc, 0x00, 0x00, 0x00 } } }, |
|
/* /103 */ { { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0x00, 0x00, 0x00 } } }, |
|
/* /104 */ { { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00 } } }, |
|
/* /105 */ { { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x80, 0x00, 0x00 } } }, |
|
/* /106 */ { { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xc0, 0x00, 0x00 } } }, |
|
/* /107 */ { { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xe0, 0x00, 0x00 } } }, |
|
/* /108 */ { { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf0, 0x00, 0x00 } } }, |
|
/* /109 */ { { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf8, 0x00, 0x00 } } }, |
|
/* /110 */ { { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfc, 0x00, 0x00 } } }, |
|
/* /111 */ { { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0x00, 0x00 } } }, |
|
/* /112 */ { { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00 } } }, |
|
/* /113 */ { { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x80, 0x00 } } }, |
|
/* /114 */ { { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xc0, 0x00 } } }, |
|
/* /115 */ { { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xe0, 0x00 } } }, |
|
/* /116 */ { { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf0, 0x00 } } }, |
|
/* /117 */ { { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf8, 0x00 } } }, |
|
/* /118 */ { { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfc, 0x00 } } }, |
|
/* /119 */ { { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0x00 } } }, |
|
/* /120 */ { { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00 } } }, |
|
/* /121 */ { { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x80 } } }, |
|
/* /122 */ { { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xc0 } } }, |
|
/* /123 */ { { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xe0 } } }, |
|
/* /124 */ { { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf0 } } }, |
|
/* /125 */ { { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf8 } } }, |
|
/* /126 */ { { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfc } } }, |
|
/* /127 */ { { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe } } }, |
|
/* /128 */ { { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff } } } |
|
}; |
|
|
/* Number of bits in prefix type. */ |
/* Number of bits in prefix type. */ |
#ifndef PNBBY |
#ifndef PNBBY |
#define PNBBY 8 |
#define PNBBY 8 |
Line 39 static const u_char maskbit[] = {0x00, 0x80, 0xc0, 0xe
|
Line 172 static const u_char maskbit[] = {0x00, 0x80, 0xc0, 0xe
|
|
|
#define MASKBIT(offset) ((0xff << (PNBBY - (offset))) & 0xff) |
#define MASKBIT(offset) ((0xff << (PNBBY - (offset))) & 0xff) |
|
|
|
unsigned int |
|
prefix_bit (const u_char *prefix, const u_char prefixlen) |
|
{ |
|
unsigned int offset = prefixlen / 8; |
|
unsigned int shift = 7 - (prefixlen % 8); |
|
|
|
return (prefix[offset] >> shift) & 1; |
|
} |
|
|
|
unsigned int |
|
prefix6_bit (const struct in6_addr *prefix, const u_char prefixlen) |
|
{ |
|
return prefix_bit((const u_char *) &prefix->s6_addr, prefixlen); |
|
} |
|
|
|
int |
|
str2family(const char *string) |
|
{ |
|
if (!strcmp("ipv4", string)) |
|
return AF_INET; |
|
else if (!strcmp("ipv6", string)) |
|
return AF_INET6; |
|
else |
|
return -1; |
|
} |
|
|
/* Address Famiy Identifier to Address Family converter. */ |
/* Address Famiy Identifier to Address Family converter. */ |
int |
int |
afi2family (afi_t afi) |
afi2family (afi_t afi) |
Line 64 family2afi (int family)
|
Line 223 family2afi (int family)
|
return 0; |
return 0; |
} |
} |
|
|
|
const char * |
|
safi2str(safi_t safi) |
|
{ |
|
switch (safi) { |
|
case SAFI_UNICAST: |
|
return "unicast"; |
|
case SAFI_MULTICAST: |
|
return "multicast"; |
|
case SAFI_ENCAP: |
|
return "encap"; |
|
case SAFI_MPLS_VPN: |
|
return "vpn"; |
|
} |
|
return NULL; |
|
} |
|
|
/* If n includes p prefix then return 1 else return 0. */ |
/* If n includes p prefix then return 1 else return 0. */ |
int |
int |
prefix_match (const struct prefix *n, const struct prefix *p) |
prefix_match (const struct prefix *n, const struct prefix *p) |
Line 133 prefix_same (const struct prefix *p1, const struct pre
|
Line 308 prefix_same (const struct prefix *p1, const struct pre
|
if (p1->family == p2->family && p1->prefixlen == p2->prefixlen) |
if (p1->family == p2->family && p1->prefixlen == p2->prefixlen) |
{ |
{ |
if (p1->family == AF_INET) |
if (p1->family == AF_INET) |
if (IPV4_ADDR_SAME (&p1->u.prefix, &p2->u.prefix)) | if (IPV4_ADDR_SAME (&p1->u.prefix4.s_addr, &p2->u.prefix4.s_addr)) |
return 1; |
return 1; |
#ifdef HAVE_IPV6 |
#ifdef HAVE_IPV6 |
if (p1->family == AF_INET6 ) |
if (p1->family == AF_INET6 ) |
if (IPV6_ADDR_SAME (&p1->u.prefix, &p2->u.prefix)) | if (IPV6_ADDR_SAME (&p1->u.prefix6.s6_addr, &p2->u.prefix6.s6_addr)) |
return 1; |
return 1; |
#endif /* HAVE_IPV6 */ |
#endif /* HAVE_IPV6 */ |
} |
} |
Line 167 prefix_cmp (const struct prefix *p1, const struct pref
|
Line 342 prefix_cmp (const struct prefix *p1, const struct pref
|
if (p1->family != p2->family || p1->prefixlen != p2->prefixlen) |
if (p1->family != p2->family || p1->prefixlen != p2->prefixlen) |
return 1; |
return 1; |
|
|
offset = p1->prefixlen / 8; | offset = p1->prefixlen / PNBBY; |
shift = p1->prefixlen % 8; | shift = p1->prefixlen % PNBBY; |
|
|
if (shift) |
if (shift) |
if (maskbit[shift] & (pp1[offset] ^ pp2[offset])) |
if (maskbit[shift] & (pp1[offset] ^ pp2[offset])) |
Line 181 prefix_cmp (const struct prefix *p1, const struct pref
|
Line 356 prefix_cmp (const struct prefix *p1, const struct pref
|
return 0; |
return 0; |
} |
} |
|
|
|
/* |
|
* Count the number of common bits in 2 prefixes. The prefix length is |
|
* ignored for this function; the whole prefix is compared. If the prefix |
|
* address families don't match, return -1; otherwise the return value is |
|
* in range 0 ... maximum prefix length for the address family. |
|
*/ |
|
int |
|
prefix_common_bits (const struct prefix *p1, const struct prefix *p2) |
|
{ |
|
int pos, bit; |
|
int length = 0; |
|
u_char xor; |
|
|
|
/* Set both prefix's head pointer. */ |
|
const u_char *pp1 = (const u_char *)&p1->u.prefix; |
|
const u_char *pp2 = (const u_char *)&p2->u.prefix; |
|
|
|
if (p1->family == AF_INET) |
|
length = IPV4_MAX_BYTELEN; |
|
#ifdef HAVE_IPV6 |
|
if (p1->family == AF_INET6) |
|
length = IPV6_MAX_BYTELEN; |
|
#endif |
|
if (p1->family != p2->family || !length) |
|
return -1; |
|
|
|
for (pos = 0; pos < length; pos++) |
|
if (pp1[pos] != pp2[pos]) |
|
break; |
|
if (pos == length) |
|
return pos * 8; |
|
|
|
xor = pp1[pos] ^ pp2[pos]; |
|
for (bit = 0; bit < 8; bit++) |
|
if (xor & (1 << (7 - bit))) |
|
break; |
|
|
|
return pos * 8 + bit; |
|
} |
|
|
/* Return prefix family type string. */ |
/* Return prefix family type string. */ |
const char * |
const char * |
prefix_family_str (const struct prefix *p) |
prefix_family_str (const struct prefix *p) |
Line 261 str2prefix_ipv4 (const char *str, struct prefix_ipv4 *
|
Line 476 str2prefix_ipv4 (const char *str, struct prefix_ipv4 *
|
return ret; |
return ret; |
} |
} |
|
|
/* Convert masklen into IP address's netmask. */ | /* Convert masklen into IP address's netmask (network byte order). */ |
void |
void |
masklen2ip (int masklen, struct in_addr *netmask) | masklen2ip (const int masklen, struct in_addr *netmask) |
{ |
{ |
u_char *pnt; | assert (masklen >= 0 && masklen <= IPV4_MAX_BITLEN); |
int bit; | |
int offset; | |
|
|
memset (netmask, 0, sizeof (struct in_addr)); | /* left shift is only defined for less than the size of the type. |
pnt = (unsigned char *) netmask; | * we unconditionally use long long in case the target platform |
| * has defined behaviour for << 32 (or has a 64-bit left shift) */ |
|
|
offset = masklen / 8; | if (sizeof(unsigned long long) > 4) |
bit = masklen % 8; | netmask->s_addr = htonl(0xffffffffULL << (32 - masklen)); |
| else |
while (offset--) | netmask->s_addr = htonl(masklen ? 0xffffffffU << (32 - masklen) : 0); |
*pnt++ = 0xff; | |
| |
if (bit) | |
*pnt = maskbit[bit]; | |
} |
} |
|
|
/* Convert IP address's netmask into integer. We assume netmask is |
/* Convert IP address's netmask into integer. We assume netmask is |
Line 287 masklen2ip (int masklen, struct in_addr *netmask)
|
Line 497 masklen2ip (int masklen, struct in_addr *netmask)
|
u_char |
u_char |
ip_masklen (struct in_addr netmask) |
ip_masklen (struct in_addr netmask) |
{ |
{ |
u_char len; | uint32_t tmp = ~ntohl(netmask.s_addr); |
u_char *pnt; | if (tmp) |
u_char *end; | /* clz: count leading zeroes. sadly, the behaviour of this builtin |
u_char val; | * is undefined for a 0 argument, even though most CPUs give 32 */ |
| return __builtin_clz(tmp); |
len = 0; | else |
pnt = (u_char *) &netmask; | return 32; |
end = pnt + 4; | |
| |
while ((pnt < end) && (*pnt == 0xff)) | |
{ | |
len+= 8; | |
pnt++; | |
} | |
| |
if (pnt < end) | |
{ | |
val = *pnt; | |
while (val) | |
{ | |
len++; | |
val <<= 1; | |
} | |
} | |
return len; | |
} |
} |
|
|
/* Apply mask to IPv4 prefix. */ | /* Apply mask to IPv4 prefix (network byte order). */ |
void |
void |
apply_mask_ipv4 (struct prefix_ipv4 *p) |
apply_mask_ipv4 (struct prefix_ipv4 *p) |
{ |
{ |
u_char *pnt; | struct in_addr mask; |
int index; | masklen2ip(p->prefixlen, &mask); |
int offset; | p->prefix.s_addr &= mask.s_addr; |
| |
index = p->prefixlen / 8; | |
| |
if (index < 4) | |
{ | |
pnt = (u_char *) &p->prefix; | |
offset = p->prefixlen % 8; | |
| |
pnt[index] &= maskbit[offset]; | |
index++; | |
| |
while (index < 4) | |
pnt[index++] = 0; | |
} | |
} |
} |
|
|
/* If prefix is 0.0.0.0/0 then return 1 else return 0. */ |
/* If prefix is 0.0.0.0/0 then return 1 else return 0. */ |
Line 343 prefix_ipv4_any (const struct prefix_ipv4 *p)
|
Line 521 prefix_ipv4_any (const struct prefix_ipv4 *p)
|
{ |
{ |
return (p->prefix.s_addr == 0 && p->prefixlen == 0); |
return (p->prefix.s_addr == 0 && p->prefixlen == 0); |
} |
} |
| |
#ifdef HAVE_IPV6 |
#ifdef HAVE_IPV6 |
|
|
/* Allocate a new ip version 6 route */ |
/* Allocate a new ip version 6 route */ |
Line 396 str2prefix_ipv6 (const char *str, struct prefix_ipv6 *
|
Line 574 str2prefix_ipv6 (const char *str, struct prefix_ipv6 *
|
if (ret == 0) |
if (ret == 0) |
return 0; |
return 0; |
plen = (u_char) atoi (++pnt); |
plen = (u_char) atoi (++pnt); |
if (plen > 128) | if (plen > IPV6_MAX_BITLEN) |
return 0; |
return 0; |
p->prefixlen = plen; |
p->prefixlen = plen; |
} |
} |
Line 416 ip6_masklen (struct in6_addr netmask)
|
Line 594 ip6_masklen (struct in6_addr netmask)
|
|
|
pnt = (unsigned char *) & netmask; |
pnt = (unsigned char *) & netmask; |
|
|
while ((*pnt == 0xff) && len < 128) | while ((*pnt == 0xff) && len < IPV6_MAX_BITLEN) |
{ |
{ |
len += 8; |
len += 8; |
pnt++; |
pnt++; |
} |
} |
|
|
if (len < 128) | if (len < IPV6_MAX_BITLEN) |
{ |
{ |
val = *pnt; |
val = *pnt; |
while (val) |
while (val) |
Line 435 ip6_masklen (struct in6_addr netmask)
|
Line 613 ip6_masklen (struct in6_addr netmask)
|
} |
} |
|
|
void |
void |
masklen2ip6 (int masklen, struct in6_addr *netmask) | masklen2ip6 (const int masklen, struct in6_addr *netmask) |
{ |
{ |
unsigned char *pnt; | assert (masklen >= 0 && masklen <= IPV6_MAX_BITLEN); |
int bit; | memcpy (netmask, maskbytes6 + masklen, sizeof (struct in6_addr)); |
int offset; | |
| |
memset (netmask, 0, sizeof (struct in6_addr)); | |
pnt = (unsigned char *) netmask; | |
| |
offset = masklen / 8; | |
bit = masklen % 8; | |
| |
while (offset--) | |
*pnt++ = 0xff; | |
| |
if (bit) | |
*pnt = maskbit[bit]; | |
} |
} |
|
|
void |
void |
Line 543 sockunion2prefix (const union sockunion *dest,
|
Line 708 sockunion2prefix (const union sockunion *dest,
|
|
|
/* Utility function of convert between struct prefix <=> union sockunion. */ |
/* Utility function of convert between struct prefix <=> union sockunion. */ |
struct prefix * |
struct prefix * |
sockunion2hostprefix (const union sockunion *su) | sockunion2hostprefix (const union sockunion *su, struct prefix *prefix) |
{ |
{ |
if (su->sa.sa_family == AF_INET) |
if (su->sa.sa_family == AF_INET) |
{ |
{ |
struct prefix_ipv4 *p; |
struct prefix_ipv4 *p; |
|
|
p = prefix_ipv4_new (); | p = prefix ? (struct prefix_ipv4 *) prefix : prefix_ipv4_new (); |
p->family = AF_INET; |
p->family = AF_INET; |
p->prefix = su->sin.sin_addr; |
p->prefix = su->sin.sin_addr; |
p->prefixlen = IPV4_MAX_BITLEN; |
p->prefixlen = IPV4_MAX_BITLEN; |
Line 560 sockunion2hostprefix (const union sockunion *su)
|
Line 725 sockunion2hostprefix (const union sockunion *su)
|
{ |
{ |
struct prefix_ipv6 *p; |
struct prefix_ipv6 *p; |
|
|
p = prefix_ipv6_new (); | p = prefix ? (struct prefix_ipv6 *) prefix : prefix_ipv6_new (); |
p->family = AF_INET6; |
p->family = AF_INET6; |
p->prefixlen = IPV6_MAX_BITLEN; |
p->prefixlen = IPV6_MAX_BITLEN; |
memcpy (&p->prefix, &su->sin6.sin6_addr, sizeof (struct in6_addr)); |
memcpy (&p->prefix, &su->sin6.sin6_addr, sizeof (struct in6_addr)); |
Line 570 sockunion2hostprefix (const union sockunion *su)
|
Line 735 sockunion2hostprefix (const union sockunion *su)
|
return NULL; |
return NULL; |
} |
} |
|
|
|
void |
|
prefix2sockunion (const struct prefix *p, union sockunion *su) |
|
{ |
|
memset (su, 0, sizeof (*su)); |
|
|
|
su->sa.sa_family = p->family; |
|
if (p->family == AF_INET) |
|
su->sin.sin_addr = p->u.prefix4; |
|
#ifdef HAVE_IPV6 |
|
if (p->family == AF_INET6) |
|
memcpy (&su->sin6.sin6_addr, &p->u.prefix6, sizeof (struct in6_addr)); |
|
#endif /* HAVE_IPV6 */ |
|
} |
|
|
int |
int |
prefix_blen (const struct prefix *p) |
prefix_blen (const struct prefix *p) |
{ |
{ |
Line 608 str2prefix (const char *str, struct prefix *p)
|
Line 787 str2prefix (const char *str, struct prefix *p)
|
return 0; |
return 0; |
} |
} |
|
|
int | const char * |
prefix2str (const struct prefix *p, char *str, int size) | prefix2str (union prefix46constptr pu, char *str, int size) |
{ |
{ |
|
const struct prefix *p = pu.p; |
char buf[BUFSIZ]; |
char buf[BUFSIZ]; |
|
|
inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ); |
inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ); |
snprintf (str, size, "%s/%d", buf, p->prefixlen); |
snprintf (str, size, "%s/%d", buf, p->prefixlen); |
return 0; | return str; |
} |
} |
|
|
struct prefix * |
struct prefix * |