| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #include <nft.h> | ||
| 2 | |||
| 3 | #include <stddef.h> | ||
| 4 | |||
| 5 | #include <datatype.h> | ||
| 6 | #include <dccpopt.h> | ||
| 7 | #include <expression.h> | ||
| 8 | #include <nftables.h> | ||
| 9 | #include <utils.h> | ||
| 10 | |||
| 11 | #define PHT(__token, __offset, __len) \ | ||
| 12 | PROTO_HDR_TEMPLATE(__token, &integer_type, BYTEORDER_BIG_ENDIAN, \ | ||
| 13 | __offset, __len) | ||
| 14 | |||
| 15 | static const struct proto_hdr_template dccpopt_unknown_template = | ||
| 16 | PROTO_HDR_TEMPLATE("unknown", &invalid_type, BYTEORDER_INVALID, 0, 0); | ||
| 17 | |||
| 18 | /* | ||
| 19 | * Option DCCP- Section | ||
| 20 | * Type Length Meaning Data? Reference | ||
| 21 | * ---- ------ ------- ----- --------- | ||
| 22 | * 0 1 Padding Y 5.8.1 | ||
| 23 | * 1 1 Mandatory N 5.8.2 | ||
| 24 | * 2 1 Slow Receiver Y 11.6 | ||
| 25 | * 3-31 1 Reserved | ||
| 26 | * 32 variable Change L N 6.1 | ||
| 27 | * 33 variable Confirm L N 6.2 | ||
| 28 | * 34 variable Change R N 6.1 | ||
| 29 | * 35 variable Confirm R N 6.2 | ||
| 30 | * 36 variable Init Cookie N 8.1.4 | ||
| 31 | * 37 3-8 NDP Count Y 7.7 | ||
| 32 | * 38 variable Ack Vector [Nonce 0] N 11.4 | ||
| 33 | * 39 variable Ack Vector [Nonce 1] N 11.4 | ||
| 34 | * 40 variable Data Dropped N 11.7 | ||
| 35 | * 41 6 Timestamp Y 13.1 | ||
| 36 | * 42 6/8/10 Timestamp Echo Y 13.3 | ||
| 37 | * 43 4/6 Elapsed Time N 13.2 | ||
| 38 | * 44 6 Data Checksum Y 9.3 | ||
| 39 | * 45-127 variable Reserved | ||
| 40 | * 128-255 variable CCID-specific options - 10.3 | ||
| 41 | */ | ||
| 42 | |||
| 43 | static const struct exthdr_desc dccpopt_padding = { | ||
| 44 | .name = "padding", | ||
| 45 | .type = DCCPOPT_PADDING, | ||
| 46 | .templates = { | ||
| 47 | [DCCPOPT_FIELD_TYPE] = PHT("type", 0, 8), | ||
| 48 | }, | ||
| 49 | }; | ||
| 50 | |||
| 51 | static const struct exthdr_desc dccpopt_mandatory = { | ||
| 52 | .name = "mandatory", | ||
| 53 | .type = DCCPOPT_MANDATORY, | ||
| 54 | .templates = { | ||
| 55 | [DCCPOPT_FIELD_TYPE] = PHT("type", 0, 8), | ||
| 56 | }, | ||
| 57 | }; | ||
| 58 | |||
| 59 | static const struct exthdr_desc dccpopt_slow_receiver = { | ||
| 60 | .name = "slow_receiver", | ||
| 61 | .type = DCCPOPT_SLOW_RECEIVER, | ||
| 62 | .templates = { | ||
| 63 | [DCCPOPT_FIELD_TYPE] = PHT("type", 0, 8), | ||
| 64 | }, | ||
| 65 | }; | ||
| 66 | |||
| 67 | static const struct exthdr_desc dccpopt_reserved_short = { | ||
| 68 | .name = "reserved_short", | ||
| 69 | .type = DCCPOPT_RESERVED_SHORT, | ||
| 70 | .templates = { | ||
| 71 | [DCCPOPT_FIELD_TYPE] = PHT("type", 0, 8), | ||
| 72 | }, | ||
| 73 | }; | ||
| 74 | |||
| 75 | static const struct exthdr_desc dccpopt_change_l = { | ||
| 76 | .name = "change_l", | ||
| 77 | .type = DCCPOPT_CHANGE_L, | ||
| 78 | .templates = { | ||
| 79 | [DCCPOPT_FIELD_TYPE] = PHT("type", 0, 8) | ||
| 80 | }, | ||
| 81 | }; | ||
| 82 | |||
| 83 | static const struct exthdr_desc dccpopt_confirm_l = { | ||
| 84 | .name = "confirm_l", | ||
| 85 | .type = DCCPOPT_CONFIRM_L, | ||
| 86 | .templates = { | ||
| 87 | [DCCPOPT_FIELD_TYPE] = PHT("type", 0, 8), | ||
| 88 | }, | ||
| 89 | }; | ||
| 90 | |||
| 91 | static const struct exthdr_desc dccpopt_change_r = { | ||
| 92 | .name = "change_r", | ||
| 93 | .type = DCCPOPT_CHANGE_R, | ||
| 94 | .templates = { | ||
| 95 | [DCCPOPT_FIELD_TYPE] = PHT("type", 0, 8), | ||
| 96 | }, | ||
| 97 | }; | ||
| 98 | |||
| 99 | static const struct exthdr_desc dccpopt_confirm_r = { | ||
| 100 | .name = "confirm_r", | ||
| 101 | .type = DCCPOPT_CONFIRM_R, | ||
| 102 | .templates = { | ||
| 103 | [DCCPOPT_FIELD_TYPE] = PHT("type", 0, 8), | ||
| 104 | }, | ||
| 105 | }; | ||
| 106 | |||
| 107 | static const struct exthdr_desc dccpopt_init_cookie = { | ||
| 108 | .name = "init_cookie", | ||
| 109 | .type = DCCPOPT_INIT_COOKIE, | ||
| 110 | .templates = { | ||
| 111 | [DCCPOPT_FIELD_TYPE] = PHT("type", 0, 8), | ||
| 112 | }, | ||
| 113 | }; | ||
| 114 | |||
| 115 | static const struct exthdr_desc dccpopt_ndp_count = { | ||
| 116 | .name = "ndp_count", | ||
| 117 | .type = DCCPOPT_NDP_COUNT, | ||
| 118 | .templates = { | ||
| 119 | [DCCPOPT_FIELD_TYPE] = PHT("type", 0, 8), | ||
| 120 | }, | ||
| 121 | }; | ||
| 122 | |||
| 123 | static const struct exthdr_desc dccpopt_ack_vector_nonce_0 = { | ||
| 124 | .name = "ack_vector_nonce_0", | ||
| 125 | .type = DCCPOPT_ACK_VECTOR_NONCE_0, | ||
| 126 | .templates = { | ||
| 127 | [DCCPOPT_FIELD_TYPE] = PHT("type", 0, 8), | ||
| 128 | }, | ||
| 129 | }; | ||
| 130 | |||
| 131 | static const struct exthdr_desc dccpopt_ack_vector_nonce_1 = { | ||
| 132 | .name = "ack_vector_nonce_1", | ||
| 133 | .type = DCCPOPT_ACK_VECTOR_NONCE_1, | ||
| 134 | .templates = { | ||
| 135 | [DCCPOPT_FIELD_TYPE] = PHT("type", 0, 8), | ||
| 136 | }, | ||
| 137 | }; | ||
| 138 | |||
| 139 | static const struct exthdr_desc dccpopt_data_dropped = { | ||
| 140 | .name = "data_dropped", | ||
| 141 | .type = DCCPOPT_DATA_DROPPED, | ||
| 142 | .templates = { | ||
| 143 | [DCCPOPT_FIELD_TYPE] = PHT("type", 0, 8), | ||
| 144 | }, | ||
| 145 | }; | ||
| 146 | |||
| 147 | static const struct exthdr_desc dccpopt_timestamp = { | ||
| 148 | .name = "timestamp", | ||
| 149 | .type = DCCPOPT_TIMESTAMP, | ||
| 150 | .templates = { | ||
| 151 | [DCCPOPT_FIELD_TYPE] = PHT("type", 0, 8), | ||
| 152 | }, | ||
| 153 | }; | ||
| 154 | |||
| 155 | static const struct exthdr_desc dccpopt_timestamp_echo = { | ||
| 156 | .name = "timestamp_echo", | ||
| 157 | .type = DCCPOPT_TIMESTAMP_ECHO, | ||
| 158 | .templates = { | ||
| 159 | [DCCPOPT_FIELD_TYPE] = PHT("type", 0, 8), | ||
| 160 | }, | ||
| 161 | }; | ||
| 162 | |||
| 163 | static const struct exthdr_desc dccpopt_elapsed_time = { | ||
| 164 | .name = "elapsed_time", | ||
| 165 | .type = DCCPOPT_ELAPSED_TIME, | ||
| 166 | .templates = { | ||
| 167 | [DCCPOPT_FIELD_TYPE] = PHT("type", 0, 8), | ||
| 168 | }, | ||
| 169 | }; | ||
| 170 | |||
| 171 | static const struct exthdr_desc dccpopt_data_checksum = { | ||
| 172 | .name = "data_checksum", | ||
| 173 | .type = DCCPOPT_DATA_CHECKSUM, | ||
| 174 | .templates = { | ||
| 175 | [DCCPOPT_FIELD_TYPE] = PHT("type", 0, 8), | ||
| 176 | }, | ||
| 177 | }; | ||
| 178 | |||
| 179 | static const struct exthdr_desc dccpopt_reserved_long = { | ||
| 180 | .name = "reserved_long", | ||
| 181 | .type = DCCPOPT_RESERVED_LONG, | ||
| 182 | .templates = { | ||
| 183 | [DCCPOPT_FIELD_TYPE] = PHT("type", 0, 8), | ||
| 184 | }, | ||
| 185 | }; | ||
| 186 | |||
| 187 | static const struct exthdr_desc dccpopt_ccid_specific = { | ||
| 188 | .name = "ccid_specific", | ||
| 189 | .type = DCCPOPT_CCID_SPECIFIC, | ||
| 190 | .templates = { | ||
| 191 | [DCCPOPT_FIELD_TYPE] = PHT("type", 0, 8), | ||
| 192 | }, | ||
| 193 | }; | ||
| 194 | |||
| 195 | const struct exthdr_desc *dccpopt_protocols[1 + UINT8_MAX] = { | ||
| 196 | [DCCPOPT_PADDING] = &dccpopt_padding, | ||
| 197 | [DCCPOPT_MANDATORY] = &dccpopt_mandatory, | ||
| 198 | [DCCPOPT_SLOW_RECEIVER] = &dccpopt_slow_receiver, | ||
| 199 | [DCCPOPT_RESERVED_SHORT] = &dccpopt_reserved_short, | ||
| 200 | [DCCPOPT_CHANGE_L] = &dccpopt_change_l, | ||
| 201 | [DCCPOPT_CONFIRM_L] = &dccpopt_confirm_l, | ||
| 202 | [DCCPOPT_CHANGE_R] = &dccpopt_change_r, | ||
| 203 | [DCCPOPT_CONFIRM_R] = &dccpopt_confirm_r, | ||
| 204 | [DCCPOPT_INIT_COOKIE] = &dccpopt_init_cookie, | ||
| 205 | [DCCPOPT_NDP_COUNT] = &dccpopt_ndp_count, | ||
| 206 | [DCCPOPT_ACK_VECTOR_NONCE_0] = &dccpopt_ack_vector_nonce_0, | ||
| 207 | [DCCPOPT_ACK_VECTOR_NONCE_1] = &dccpopt_ack_vector_nonce_1, | ||
| 208 | [DCCPOPT_DATA_DROPPED] = &dccpopt_data_dropped, | ||
| 209 | [DCCPOPT_TIMESTAMP] = &dccpopt_timestamp, | ||
| 210 | [DCCPOPT_TIMESTAMP_ECHO] = &dccpopt_timestamp_echo, | ||
| 211 | [DCCPOPT_ELAPSED_TIME] = &dccpopt_elapsed_time, | ||
| 212 | [DCCPOPT_DATA_CHECKSUM] = &dccpopt_data_checksum, | ||
| 213 | [DCCPOPT_RESERVED_LONG] = &dccpopt_reserved_long, | ||
| 214 | [DCCPOPT_CCID_SPECIFIC] = &dccpopt_ccid_specific, | ||
| 215 | }; | ||
| 216 | |||
| 217 | const struct exthdr_desc * | ||
| 218 | ✗ | dccpopt_find_desc(uint8_t type) | |
| 219 | { | ||
| 220 | ✗ | enum dccpopt_types proto_idx = | |
| 221 | ✗ | 3 <= type && type <= 31 ? DCCPOPT_RESERVED_SHORT : | |
| 222 | ✗ | 45 <= type && type <= 127 ? DCCPOPT_RESERVED_LONG : | |
| 223 | ✗ | 128 <= type ? DCCPOPT_CCID_SPECIFIC : type; | |
| 224 | |||
| 225 | ✗ | return dccpopt_protocols[proto_idx]; | |
| 226 | } | ||
| 227 | |||
| 228 | struct expr * | ||
| 229 | ✗ | dccpopt_expr_alloc(const struct location *loc, uint8_t type) | |
| 230 | { | ||
| 231 | const struct proto_hdr_template *tmpl; | ||
| 232 | const struct exthdr_desc *desc; | ||
| 233 | struct expr *expr; | ||
| 234 | |||
| 235 | ✗ | desc = dccpopt_find_desc(type); | |
| 236 | ✗ | tmpl = &desc->templates[DCCPOPT_FIELD_TYPE]; | |
| 237 | |||
| 238 | ✗ | expr = expr_alloc(loc, EXPR_EXTHDR, tmpl->dtype, | |
| 239 | BYTEORDER_BIG_ENDIAN, BITS_PER_BYTE); | ||
| 240 | ✗ | expr->exthdr.desc = desc; | |
| 241 | ✗ | expr->exthdr.tmpl = tmpl; | |
| 242 | ✗ | expr->exthdr.offset = tmpl->offset; | |
| 243 | ✗ | expr->exthdr.raw_type = type; | |
| 244 | ✗ | expr->exthdr.flags = NFT_EXTHDR_F_PRESENT; | |
| 245 | ✗ | expr->exthdr.op = NFT_EXTHDR_OP_DCCP; | |
| 246 | |||
| 247 | ✗ | return expr; | |
| 248 | } | ||
| 249 | |||
| 250 | void | ||
| 251 | ✗ | dccpopt_init_raw(struct expr *expr, uint8_t type, unsigned int offset, | |
| 252 | unsigned int len) | ||
| 253 | { | ||
| 254 | const struct proto_hdr_template *tmpl; | ||
| 255 | const struct exthdr_desc *desc; | ||
| 256 | |||
| 257 | ✗ | assert(expr->etype == EXPR_EXTHDR); | |
| 258 | |||
| 259 | ✗ | desc = dccpopt_find_desc(type); | |
| 260 | ✗ | tmpl = &desc->templates[DCCPOPT_FIELD_TYPE]; | |
| 261 | |||
| 262 | ✗ | expr->len = len; | |
| 263 | ✗ | datatype_set(expr, &boolean_type); | |
| 264 | |||
| 265 | ✗ | expr->exthdr.offset = offset; | |
| 266 | ✗ | expr->exthdr.desc = desc; | |
| 267 | ✗ | expr->exthdr.flags = NFT_EXTHDR_F_PRESENT; | |
| 268 | ✗ | expr->exthdr.op = NFT_EXTHDR_OP_DCCP; | |
| 269 | |||
| 270 | /* Make sure that it's the right template based on offset and | ||
| 271 | * len | ||
| 272 | */ | ||
| 273 | ✗ | if (tmpl->offset != offset || tmpl->len != len) | |
| 274 | ✗ | expr->exthdr.tmpl = &dccpopt_unknown_template; | |
| 275 | else | ||
| 276 | ✗ | expr->exthdr.tmpl = tmpl; | |
| 277 | ✗ | } | |
| 278 |