Lines 1-146
Link Here
|
1 |
/*- |
1 |
/*- |
2 |
* SPDX-License-Identifier: BSD-2-Clause-FreeBSD |
2 |
* SPDX-License-Identifier: BSD-2-Clause-FreeBSD |
3 |
* |
3 |
* |
4 |
* Copyright (C) 2019 Jan Sucan <jansucan@FreeBSD.org> |
4 |
* Copyright (C) 2019 Jan Sucan <jansucan@FreeBSD.org> |
5 |
* All rights reserved. |
5 |
* All rights reserved. |
6 |
* |
6 |
* |
7 |
* Redistribution and use in source and binary forms, with or without |
7 |
* Redistribution and use in source and binary forms, with or without |
8 |
* modification, are permitted provided that the following conditions |
8 |
* modification, are permitted provided that the following conditions |
9 |
* are met: |
9 |
* are met: |
10 |
* 1. Redistributions of source code must retain the above copyright |
10 |
* 1. Redistributions of source code must retain the above copyright |
11 |
* notice, this list of conditions and the following disclaimer. |
11 |
* notice, this list of conditions and the following disclaimer. |
12 |
* 2. Redistributions in binary form must reproduce the above copyright |
12 |
* 2. Redistributions in binary form must reproduce the above copyright |
13 |
* notice, this list of conditions and the following disclaimer in the |
13 |
* notice, this list of conditions and the following disclaimer in the |
14 |
* documentation and/or other materials provided with the distribution. |
14 |
* documentation and/or other materials provided with the distribution. |
15 |
* |
15 |
* |
16 |
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND |
16 |
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND |
17 |
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
17 |
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
18 |
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
18 |
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
19 |
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE |
19 |
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE |
20 |
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
20 |
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
21 |
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
21 |
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
22 |
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
22 |
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
23 |
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
23 |
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
24 |
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
24 |
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
25 |
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
25 |
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
26 |
* SUCH DAMAGE. |
26 |
* SUCH DAMAGE. |
27 |
*/ |
27 |
*/ |
28 |
|
28 |
|
29 |
#include <sys/cdefs.h> |
29 |
#include <sys/cdefs.h> |
30 |
__FBSDID("$FreeBSD$"); |
30 |
__FBSDID("$FreeBSD$"); |
31 |
|
31 |
|
32 |
#include <sys/param.h> |
32 |
#include <sys/param.h> |
33 |
|
33 |
|
34 |
#include <atf-c.h> |
34 |
#include <atf-c.h> |
35 |
|
35 |
|
|
|
36 |
#include <sys/socket.h> |
37 |
#include "../../../include/protocols/routed.h" |
36 |
#include "../utils.h" |
38 |
#include "../utils.h" |
37 |
|
39 |
|
38 |
/* |
40 |
/* |
39 |
* Test cases. |
41 |
* Test cases. |
40 |
*/ |
42 |
*/ |
41 |
|
43 |
|
42 |
ATF_TC_WITHOUT_HEAD(aligned_even_length_big_endian); |
44 |
ATF_TC_WITHOUT_HEAD(aligned_even_length_big_endian); |
43 |
ATF_TC_BODY(aligned_even_length_big_endian, tc) |
45 |
ATF_TC_BODY(aligned_even_length_big_endian, tc) |
44 |
{ |
46 |
{ |
45 |
u_char data[] __aligned(sizeof(u_short)) = |
47 |
u_char data[] __aligned(sizeof(u_short)) = |
46 |
{0x12, 0x34, 0x56, 0x78}; |
48 |
{0x12, 0x34, 0x56, 0x78}; |
47 |
u_short sum; |
49 |
u_short sum; |
48 |
|
50 |
|
49 |
sum = in_cksum(data, nitems(data)); |
51 |
sum = in_cksum(data, sizeof(struct rip), MAXPACKETSIZE, nitems(data)); |
50 |
ATF_REQUIRE(sum == 0x5397); |
52 |
ATF_REQUIRE(sum == 0x5397); |
51 |
} |
53 |
} |
52 |
|
54 |
|
53 |
ATF_TC_WITHOUT_HEAD(aligned_odd_length_big_endian); |
55 |
ATF_TC_WITHOUT_HEAD(aligned_odd_length_big_endian); |
54 |
ATF_TC_BODY(aligned_odd_length_big_endian, tc) |
56 |
ATF_TC_BODY(aligned_odd_length_big_endian, tc) |
55 |
{ |
57 |
{ |
56 |
u_char data[] __aligned(sizeof(u_short)) = |
58 |
u_char data[] __aligned(sizeof(u_short)) = |
57 |
{0x12, 0x34, 0x56, 0x78, 0x9a}; |
59 |
{0x12, 0x34, 0x56, 0x78, 0x9a}; |
58 |
u_short sum; |
60 |
u_short sum; |
59 |
|
61 |
|
60 |
sum = in_cksum(data, nitems(data)); |
62 |
sum = in_cksum(data, sizeof(struct rip), MAXPACKETSIZE, nitems(data)); |
61 |
ATF_REQUIRE(sum == 0x52fd); |
63 |
ATF_REQUIRE(sum == 0x52fd); |
62 |
} |
64 |
} |
63 |
|
65 |
|
64 |
ATF_TC_WITHOUT_HEAD(aligned_even_length_little_endian); |
66 |
ATF_TC_WITHOUT_HEAD(aligned_even_length_little_endian); |
65 |
ATF_TC_BODY(aligned_even_length_little_endian, tc) |
67 |
ATF_TC_BODY(aligned_even_length_little_endian, tc) |
66 |
{ |
68 |
{ |
67 |
u_char data[] __aligned(sizeof(u_short)) = |
69 |
u_char data[] __aligned(sizeof(u_short)) = |
68 |
{0x34, 0x12, 0x78, 0x56}; |
70 |
{0x34, 0x12, 0x78, 0x56}; |
69 |
u_short sum; |
71 |
u_short sum; |
70 |
|
72 |
|
71 |
sum = in_cksum(data, nitems(data)); |
73 |
sum = in_cksum(data, sizeof(struct rip), MAXPACKETSIZE, nitems(data)); |
72 |
ATF_REQUIRE_MSG(sum == 0x9753, "%d", sum); |
74 |
ATF_REQUIRE_MSG(sum == 0x9753, "%d", sum); |
73 |
} |
75 |
} |
74 |
|
76 |
|
75 |
ATF_TC_WITHOUT_HEAD(aligned_odd_length_little_endian); |
77 |
ATF_TC_WITHOUT_HEAD(aligned_odd_length_little_endian); |
76 |
ATF_TC_BODY(aligned_odd_length_little_endian, tc) |
78 |
ATF_TC_BODY(aligned_odd_length_little_endian, tc) |
77 |
{ |
79 |
{ |
78 |
u_char data[] __aligned(sizeof(u_short)) = |
80 |
u_char data[] __aligned(sizeof(u_short)) = |
79 |
{0x34, 0x12, 0x78, 0x56, 0x00, 0x9a}; |
81 |
{0x34, 0x12, 0x78, 0x56, 0x00, 0x9a}; |
80 |
u_short sum; |
82 |
u_short sum; |
81 |
|
83 |
|
82 |
sum = in_cksum(data, nitems(data)); |
84 |
sum = in_cksum(data, sizeof(struct rip), MAXPACKETSIZE, nitems(data)); |
83 |
ATF_REQUIRE(sum == 0xfd52); |
85 |
ATF_REQUIRE(sum == 0xfd52); |
84 |
} |
86 |
} |
85 |
|
87 |
|
86 |
ATF_TC_WITHOUT_HEAD(unaligned_even_length_big_endian); |
88 |
ATF_TC_WITHOUT_HEAD(unaligned_even_length_big_endian); |
87 |
ATF_TC_BODY(unaligned_even_length_big_endian, tc) |
89 |
ATF_TC_BODY(unaligned_even_length_big_endian, tc) |
88 |
{ |
90 |
{ |
89 |
u_char data[] __aligned(sizeof(u_short)) = |
91 |
u_char data[] __aligned(sizeof(u_short)) = |
90 |
{0x00, 0x12, 0x34, 0x56, 0x78}; |
92 |
{0x00, 0x12, 0x34, 0x56, 0x78}; |
91 |
u_short sum; |
93 |
u_short sum; |
92 |
|
94 |
|
93 |
sum = in_cksum(data + 1, nitems(data) - 1); |
95 |
sum = in_cksum(data + 1, sizeof(struct rip), MAXPACKETSIZE, nitems(data) - 1); |
94 |
ATF_REQUIRE(sum == 0x5397); |
96 |
ATF_REQUIRE(sum == 0x5397); |
95 |
} |
97 |
} |
96 |
|
98 |
|
97 |
ATF_TC_WITHOUT_HEAD(unaligned_odd_length_big_endian); |
99 |
ATF_TC_WITHOUT_HEAD(unaligned_odd_length_big_endian); |
98 |
ATF_TC_BODY(unaligned_odd_length_big_endian, tc) |
100 |
ATF_TC_BODY(unaligned_odd_length_big_endian, tc) |
99 |
{ |
101 |
{ |
100 |
u_char data[] __aligned(sizeof(u_short)) = |
102 |
u_char data[] __aligned(sizeof(u_short)) = |
101 |
{0x00, 0x12, 0x34, 0x56, 0x78, 0x9a}; |
103 |
{0x00, 0x12, 0x34, 0x56, 0x78, 0x9a}; |
102 |
u_short sum; |
104 |
u_short sum; |
103 |
|
105 |
|
104 |
sum = in_cksum(data + 1, nitems(data) - 1); |
106 |
sum = in_cksum(data + 1, sizeof(struct rip), MAXPACKETSIZE, nitems(data) - 1); |
105 |
ATF_REQUIRE(sum == 0x52fd); |
107 |
ATF_REQUIRE(sum == 0x52fd); |
106 |
} |
108 |
} |
107 |
|
109 |
|
108 |
ATF_TC_WITHOUT_HEAD(unaligned_even_length_little_endian); |
110 |
ATF_TC_WITHOUT_HEAD(unaligned_even_length_little_endian); |
109 |
ATF_TC_BODY(unaligned_even_length_little_endian, tc) |
111 |
ATF_TC_BODY(unaligned_even_length_little_endian, tc) |
110 |
{ |
112 |
{ |
111 |
u_char data[] __aligned(sizeof(u_short)) = |
113 |
u_char data[] __aligned(sizeof(u_short)) = |
112 |
{0x00, 0x34, 0x12, 0x78, 0x56}; |
114 |
{0x00, 0x34, 0x12, 0x78, 0x56}; |
113 |
u_short sum; |
115 |
u_short sum; |
114 |
|
116 |
|
115 |
sum = in_cksum(data + 1, nitems(data) - 1); |
117 |
sum = in_cksum(data + 1, sizeof(struct rip), MAXPACKETSIZE, nitems(data) - 1); |
116 |
ATF_REQUIRE_MSG(sum == 0x9753, "%d", sum); |
118 |
ATF_REQUIRE_MSG(sum == 0x9753, "%d", sum); |
117 |
} |
119 |
} |
118 |
|
120 |
|
119 |
ATF_TC_WITHOUT_HEAD(unaligned_odd_length_little_endian); |
121 |
ATF_TC_WITHOUT_HEAD(unaligned_odd_length_little_endian); |
120 |
ATF_TC_BODY(unaligned_odd_length_little_endian, tc) |
122 |
ATF_TC_BODY(unaligned_odd_length_little_endian, tc) |
121 |
{ |
123 |
{ |
122 |
u_char data[] __aligned(sizeof(u_short)) = |
124 |
u_char data[] __aligned(sizeof(u_short)) = |
123 |
{0x00, 0x34, 0x12, 0x78, 0x56, 0x00, 0x9a}; |
125 |
{0x00, 0x34, 0x12, 0x78, 0x56, 0x00, 0x9a}; |
124 |
u_short sum; |
126 |
u_short sum; |
125 |
|
127 |
|
126 |
sum = in_cksum(data + 1, nitems(data) - 1); |
128 |
sum = in_cksum(data + 1, sizeof(struct rip), MAXPACKETSIZE, nitems(data) - 1); |
127 |
ATF_REQUIRE(sum == 0xfd52); |
129 |
ATF_REQUIRE(sum == 0xfd52); |
128 |
} |
130 |
} |
129 |
|
131 |
|
130 |
/* |
132 |
/* |
131 |
* Main. |
133 |
* Main. |
132 |
*/ |
134 |
*/ |
133 |
|
135 |
|
134 |
ATF_TP_ADD_TCS(tp) |
136 |
ATF_TP_ADD_TCS(tp) |
135 |
{ |
137 |
{ |
136 |
ATF_TP_ADD_TC(tp, aligned_even_length_big_endian); |
138 |
ATF_TP_ADD_TC(tp, aligned_even_length_big_endian); |
137 |
ATF_TP_ADD_TC(tp, aligned_odd_length_big_endian); |
139 |
ATF_TP_ADD_TC(tp, aligned_odd_length_big_endian); |
138 |
ATF_TP_ADD_TC(tp, aligned_even_length_little_endian); |
140 |
ATF_TP_ADD_TC(tp, aligned_even_length_little_endian); |
139 |
ATF_TP_ADD_TC(tp, aligned_odd_length_little_endian); |
141 |
ATF_TP_ADD_TC(tp, aligned_odd_length_little_endian); |
140 |
ATF_TP_ADD_TC(tp, unaligned_even_length_big_endian); |
142 |
ATF_TP_ADD_TC(tp, unaligned_even_length_big_endian); |
141 |
ATF_TP_ADD_TC(tp, unaligned_odd_length_big_endian); |
143 |
ATF_TP_ADD_TC(tp, unaligned_odd_length_big_endian); |
142 |
ATF_TP_ADD_TC(tp, unaligned_even_length_little_endian); |
144 |
ATF_TP_ADD_TC(tp, unaligned_even_length_little_endian); |
143 |
ATF_TP_ADD_TC(tp, unaligned_odd_length_little_endian); |
145 |
ATF_TP_ADD_TC(tp, unaligned_odd_length_little_endian); |
144 |
|
146 |
|
145 |
return (atf_no_error()); |
147 |
return (atf_no_error()); |
146 |
} |
148 |
} |