32bit seqno, bugfixes
[cor.git] / net / cor / util.c
blobe9c917cc54ec1983a8e800d6004c24a1531dd443
1 /**
2 * Connection oriented routing
3 * Copyright (C) 2007-2021 Michael Blizek
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
16 #include "cor.h"
19 static const __u32 cor_log_64_11_table[] = {0,
20 64, 68, 73, 77, 82, 88, 93, 99, 106, 113, 120,
21 128, 136, 145, 155, 165, 175, 187, 199, 212, 226, 240,
22 256, 273, 290, 309, 329, 351, 374, 398, 424, 451, 481,
23 512, 545, 581, 619, 659, 702, 747, 796, 848, 903, 961,
24 1024, 1091, 1162, 1237, 1318, 1403, 1495, 1592, 1695, 1805,
25 1923,
26 2048, 2181, 2323, 2474, 2635, 2806, 2989, 3183, 3390, 3611,
27 3846,
28 4096, 4362, 4646, 4948, 5270, 5613, 5978, 6367, 6781, 7222,
29 7692,
30 8192, 8725, 9292, 9897, 10540, 11226, 11956, 12734, 13562,
31 14444, 15383,
32 16384, 17450, 18585, 19793, 21081, 22452, 23912, 25467, 27124,
33 28888, 30767,
34 32768, 34899, 37169, 39587, 42161, 44904, 47824, 50935, 54248,
35 57776, 61534,
36 65536, 69799, 74338, 79173, 84323, 89807, 95648, 101870, 108495,
37 115552, 123068,
38 131072, 139597, 148677, 158347, 168646, 179615, 191297, 203739,
39 216991, 231104, 246135,
40 262144, 279194, 297353, 316693, 337291, 359229, 382594, 407478,
41 433981, 462208, 492270,
42 524288, 558388, 594706, 633387, 674583, 718459, 765188, 814957,
43 867962, 924415, 984540,
44 1048576, 1116777, 1189413, 1266774, 1349166, 1436917, 1530376,
45 1629913, 1735924, 1848831, 1969081,
46 2097152, 2233553, 2378826, 2533547, 2698332, 2873834, 3060752,
47 3259826, 3471849, 3697662, 3938162,
48 4194304, 4467106, 4757652, 5067094, 5396664, 5747669, 6121503,
49 6519652, 6943698, 7395323, 7876323,
50 8388608, 8934212, 9515303, 10134189, 10793327, 11495337,
51 12243006, 13039305, 13887396, 14790647,
52 15752647,
53 16777216, 17868424, 19030606, 20268378, 21586655, 22990674,
54 24486013, 26078610, 27774791, 29581294,
55 31505293,
56 33554432, 35736849, 38061212, 40536755, 43173310, 45981349,
57 48972026, 52157220, 55549582, 59162588,
58 63010587,
59 67108864, 71473698, 76122425, 81073510, 86346620, 91962698,
60 97944052, 104314440, 111099165, 118325175,
61 126021174,
62 134217728, 142947395, 152244850, 162147020, 172693239,
63 183925396, 195888104, 208628880, 222198329,
64 236650351, 252042347,
65 268435456, 285894791, 304489699, 324294041, 345386479,
66 367850791, 391776208, 417257759, 444396658,
67 473300701, 504084694,
68 536870912, 571789581};
70 #warning todo use this for the window size
71 __u8 __attribute__((const)) cor_enc_log_64_11(__u32 value)
73 int i;
75 BUILD_BUG_ON(cor_log_64_11_table[255] != 571789581);
76 for (i = 1; i < 256; i++) {
77 if (cor_log_64_11_table[i] > value)
78 break;
81 return (__u8)(i - 1); /* round down */
84 __u32 __attribute__((const)) cor_dec_log_64_11(__u8 value)
86 BUILD_BUG_ON(cor_log_64_11_table[255] != 571789581);
87 return cor_log_64_11_table[value];
90 static void __init cor_check_log_64_11_table(void)
92 int i;
94 BUG_ON(cor_log_64_11_table[0] != 0);
95 for (i = 1; i < 256; i++) {
96 BUG_ON(cor_log_64_11_table[i] <= cor_log_64_11_table[i - 1]);
101 void cor_swap_list_items(struct list_head *lh1, struct list_head *lh2)
103 struct list_head *tmp;
105 tmp = (lh1->next == lh1 ? lh2 : lh1->next);
106 lh1->next = (lh2->next == lh2 ? lh1 : lh2->next);
107 lh2->next = tmp;
109 tmp = (lh1->prev == lh1 ? lh2 : lh2->prev);
110 lh1->prev = (lh2->prev == lh2 ? lh1 : lh2->prev);
111 lh2->prev = tmp;
113 lh1->next->prev = lh1;
114 lh1->prev->next = lh1;
116 lh2->next->prev = lh2;
117 lh2->prev->next = lh2;
120 void cor_kreffree_bug(struct kref *ref)
122 BUG();
125 int __init cor_util_init(void)
127 cor_check_log_64_11_table();
129 return 0;
132 MODULE_LICENSE("GPL");