1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655
| /* SPDX-License-Identifier: BSD-3-Clause * Copyright(c) 2010-2016 Intel Corporation */
#include <stdio.h> #include <stdlib.h> #include <stdint.h> #include <inttypes.h> #include <sys/types.h> #include <string.h> #include <sys/queue.h> #include <stdarg.h> #include <errno.h> #include <getopt.h>
#include <rte_common.h> #include <rte_byteorder.h> #include <rte_log.h> #include <rte_memory.h> #include <rte_memcpy.h> #include <rte_eal.h> #include <rte_launch.h> #include <rte_atomic.h> #include <rte_cycles.h> #include <rte_prefetch.h> #include <rte_lcore.h> #include <rte_per_lcore.h> #include <rte_branch_prediction.h> #include <rte_interrupts.h> #include <rte_random.h> #include <rte_debug.h> #include <rte_ether.h> #include <rte_ethdev.h> #include <rte_mempool.h> #include <rte_mbuf.h> #include <rte_ip.h> #include <rte_tcp.h> #include <rte_udp.h> #include <rte_string_fns.h> #include <rte_acl.h>
//Frame : 6 [Protocols in frame: eth:ip:tcp:http] char http_req[] = { 0x30, 0xfc, 0x68, 0xff, 0x70, 0xfb, 0x02, 0xa9, 0x1c, 0x7d, 0xea, 0x54, 0x08, 0x00, 0x45, 0x00, 0x05, 0x25, 0xe5, 0xdd, 0x40, 0x00, 0x80, 0x06, 0x80, 0x99, 0xac, 0x10, 0x14, 0x3a, 0x7a, 0xe2, 0x54, 0x2f, 0x15, 0xba, 0x00, 0x50, 0x7e, 0xf8, 0x4b, 0xfc, 0x92, 0xd3, 0x8d, 0x1d, 0x50, 0x18, 0x01, 0x00, 0xaf, 0x4d, 0x00, 0x00, 0x47, 0x45, 0x54, 0x20, 0x2f, 0x63, 0x75, 0x73, 0x74, 0x6f, 0x6d, 0x2f, 0x37, 0x32, 0x31, 0x31, 0x30, 0x33, 0x34, 0x38, 0x2f, 0x6d, 0x6f, 0x62, 0x69, 0x6c, 0x65, 0x5f, 0x69, 0x63, 0x6f, 0x6e, 0x5f, 0x37, 0x32, 0x31, 0x31, 0x30, 0x33, 0x34, 0x38, 0x5f, 0x32, 0x2e, 0x6a, 0x73, 0x3f, 0x76, 0x3d, 0x31, 0x35, 0x30, 0x32, 0x31, 0x37, 0x39, 0x36, 0x30, 0x31, 0x20, 0x48, 0x54, 0x54, 0x50, 0x2f, 0x31, 0x2e, 0x31, 0x0d, 0x0a, 0x48, 0x6f, 0x73, 0x74, 0x3a, 0x20, 0x77, 0x77, 0x77, 0x31, 0x30, 0x63, 0x31, 0x2e, 0x35, 0x33, 0x6b, 0x66, 0x2e, 0x63, 0x6f, 0x6d, 0x0d, 0x0a, 0x43, 0x6f, 0x6e, 0x6e, 0x65, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x3a, 0x20, 0x6b, 0x65, 0x65, 0x70, 0x2d, 0x61, 0x6c, 0x69, 0x76, 0x65, 0x0d, 0x0a, 0x55, 0x73, 0x65, 0x72, 0x2d, 0x41, 0x67, 0x65, 0x6e, 0x74, 0x3a, 0x20, 0x4d, 0x6f, 0x7a, 0x69, 0x6c, 0x6c, 0x61, 0x2f, 0x35, 0x2e, 0x30, 0x20, 0x28, 0x57, 0x69, 0x6e, 0x64, 0x6f, 0x77, 0x73, 0x20, 0x4e, 0x54, 0x20, 0x31, 0x30, 0x2e, 0x30, 0x3b, 0x20, 0x57, 0x69, 0x6e, 0x36, 0x34, 0x3b, 0x20, 0x78, 0x36, 0x34, 0x29, 0x20, 0x41, 0x70, 0x70, 0x6c, 0x65, 0x57, 0x65, 0x62, 0x4b, 0x69, 0x74, 0x2f, 0x35, 0x33, 0x37, 0x2e, 0x33, 0x36, 0x20, 0x28, 0x4b, 0x48, 0x54, 0x4d, 0x4c, 0x2c, 0x20, 0x6c, 0x69, 0x6b, 0x65, 0x20, 0x47, 0x65, 0x63, 0x6b, 0x6f, 0x29, 0x20, 0x43, 0x68, 0x72, 0x6f, 0x6d, 0x65, 0x2f, 0x38, 0x31, 0x2e, 0x30, 0x2e, 0x34, 0x30, 0x34, 0x34, 0x2e, 0x31, 0x33, 0x38, 0x20, 0x53, 0x61, 0x66, 0x61, 0x72, 0x69, 0x2f, 0x35, 0x33, 0x37, 0x2e, 0x33, 0x36, 0x0d, 0x0a, 0x41, 0x63, 0x63, 0x65, 0x70, 0x74, 0x3a, 0x20, 0x2a, 0x2f, 0x2a, 0x0d, 0x0a, 0x52, 0x65, 0x66, 0x65, 0x72, 0x65, 0x72, 0x3a, 0x20, 0x68, 0x74, 0x74, 0x70, 0x3a, 0x2f, 0x2f, 0x77, 0x77, 0x77, 0x2e, 0x69, 0x62, 0x65, 0x69, 0x66, 0x65, 0x6e, 0x67, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x0d, 0x0a, 0x41, 0x63, 0x63, 0x65, 0x70, 0x74, 0x2d, 0x45, 0x6e, 0x63, 0x6f, 0x64, 0x69, 0x6e, 0x67, 0x3a, 0x20, 0x67, 0x7a, 0x69, 0x70, 0x2c, 0x20, 0x64, 0x65, 0x66, 0x6c, 0x61, 0x74, 0x65, 0x0d, 0x0a, 0x41, 0x63, 0x63, 0x65, 0x70, 0x74, 0x2d, 0x4c, 0x61, 0x6e, 0x67, 0x75, 0x61, 0x67, 0x65, 0x3a, 0x20, 0x7a, 0x68, 0x2d, 0x43, 0x4e, 0x2c, 0x7a, 0x68, 0x3b, 0x71, 0x3d, 0x30, 0x2e, 0x39, 0x2c, 0x65, 0x6e, 0x3b, 0x71, 0x3d, 0x30, 0x2e, 0x38, 0x0d, 0x0a, 0x43, 0x6f, 0x6f, 0x6b, 0x69, 0x65, 0x3a, 0x20, 0x67, 0x75, 0x65, 0x73, 0x74, 0x5f, 0x69, 0x64, 0x3d, 0x31, 0x31, 0x36, 0x35, 0x38, 0x31, 0x33, 0x34, 0x30, 0x37, 0x36, 0x30, 0x30, 0x35, 0x3b, 0x20, 0x6c, 0x61, 0x6e, 0x64, 0x5f, 0x70, 0x61, 0x67, 0x65, 0x5f, 0x37, 0x32, 0x31, 0x34, 0x35, 0x34, 0x32, 0x33, 0x3d, 0x68, 0x74, 0x74, 0x70, 0x25, 0x33, 0x41, 0x25, 0x32, 0x46, 0x25, 0x32, 0x46, 0x77, 0x77, 0x77, 0x2e, 0x6d, 0x61, 0x67, 0x65, 0x64, 0x75, 0x2e, 0x63, 0x6f, 0x6d, 0x25, 0x32, 0x46, 0x3b, 0x20, 0x35, 0x33, 0x63, 0x74, 0x5f, 0x31, 0x31, 0x36, 0x35, 0x38, 0x31, 0x33, 0x34, 0x30, 0x37, 0x36, 0x30, 0x30, 0x35, 0x3d, 0x31, 0x35, 0x38, 0x39, 0x33, 0x36, 0x30, 0x39, 0x35, 0x34, 0x5f, 0x31, 0x3b, 0x20, 0x74, 0x61, 0x6c, 0x6b, 0x74, 0x69, 0x74, 0x6c, 0x65, 0x5f, 0x37, 0x32, 0x31, 0x34, 0x35, 0x34, 0x32, 0x33, 0x3d, 0x25, 0x45, 0x39, 0x25, 0x41, 0x39, 0x25, 0x41, 0x43, 0x25, 0x45, 0x35, 0x25, 0x39, 0x33, 0x25, 0x41, 0x35, 0x25, 0x45, 0x36, 0x25, 0x39, 0x35, 0x25, 0x39, 0x39, 0x25, 0x45, 0x38, 0x25, 0x38, 0x32, 0x25, 0x42, 0x32, 0x25, 0x45, 0x35, 0x25, 0x41, 0x45, 0x25, 0x39, 0x38, 0x25, 0x45, 0x37, 0x25, 0x42, 0x44, 0x25, 0x39, 0x31, 0x2d, 0x25, 0x45, 0x34, 0x25, 0x42, 0x38, 0x25, 0x39, 0x33, 0x25, 0x45, 0x34, 0x25, 0x42, 0x38, 0x25, 0x39, 0x41, 0x4c, 0x69, 0x6e, 0x75, 0x78, 0x25, 0x45, 0x35, 0x25, 0x39, 0x46, 0x25, 0x42, 0x39, 0x25, 0x45, 0x38, 0x25, 0x41, 0x45, 0x25, 0x41, 0x44, 0x25, 0x45, 0x37, 0x25, 0x38, 0x46, 0x25, 0x41, 0x44, 0x25, 0x32, 0x43, 0x50, 0x79, 0x74, 0x68, 0x6f, 0x6e, 0x25, 0x45, 0x35, 0x25, 0x39, 0x46, 0x25, 0x42, 0x39, 0x25, 0x45, 0x38, 0x25, 0x41, 0x45, 0x25, 0x41, 0x44, 0x25, 0x45, 0x36, 0x25, 0x39, 0x43, 0x25, 0x42, 0x41, 0x25, 0x45, 0x36, 0x25, 0x39, 0x45, 0x25, 0x38, 0x34, 0x3b, 0x20, 0x63, 0x75, 0x73, 0x74, 0x6f, 0x6d, 0x65, 0x72, 0x5f, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x5f, 0x6c, 0x61, 0x6e, 0x67, 0x75, 0x61, 0x67, 0x65, 0x3d, 0x63, 0x6e, 0x3b, 0x20, 0x69, 0x73, 0x5f, 0x67, 0x72, 0x6f, 0x75, 0x70, 0x5f, 0x3d, 0x30, 0x3b, 0x20, 0x6c, 0x61, 0x6e, 0x64, 0x5f, 0x70, 0x61, 0x67, 0x65, 0x5f, 0x37, 0x32, 0x31, 0x39, 0x36, 0x35, 0x35, 0x30, 0x3d, 0x68, 0x74, 0x74, 0x70, 0x73, 0x25, 0x33, 0x41, 0x25, 0x32, 0x46, 0x25, 0x32, 0x46, 0x77, 0x77, 0x77, 0x2e, 0x71, 0x69, 0x64, 0x69, 0x61, 0x6e, 0x6c, 0x61, 0x2e, 0x63, 0x6f, 0x6d, 0x25, 0x32, 0x46, 0x3b, 0x20, 0x74, 0x61, 0x6c, 0x6b, 0x74, 0x69, 0x74, 0x6c, 0x65, 0x5f, 0x37, 0x32, 0x31, 0x39, 0x36, 0x35, 0x35, 0x30, 0x3d, 0x25, 0x45, 0x38, 0x25, 0x42, 0x35, 0x25, 0x42, 0x37, 0x25, 0x45, 0x37, 0x25, 0x38, 0x32, 0x25, 0x42, 0x39, 0x25, 0x45, 0x35, 0x25, 0x41, 0x44, 0x25, 0x41, 0x36, 0x25, 0x45, 0x39, 0x25, 0x39, 0x39, 0x25, 0x41, 0x32, 0x2d, 0x25, 0x45, 0x34, 0x25, 0x42, 0x41, 0x25, 0x41, 0x37, 0x25, 0x45, 0x35, 0x25, 0x39, 0x33, 0x25, 0x38, 0x31, 0x25, 0x45, 0x37, 0x25, 0x42, 0x42, 0x25, 0x38, 0x46, 0x25, 0x45, 0x37, 0x25, 0x39, 0x30, 0x25, 0x38, 0x36, 0x25, 0x45, 0x35, 0x25, 0x39, 0x46, 0x25, 0x42, 0x39, 0x25, 0x45, 0x38, 0x25, 0x41, 0x45, 0x25, 0x41, 0x44, 0x2b, 0x25, 0x37, 0x43, 0x2b, 0x25, 0x45, 0x34, 0x25, 0x42, 0x41, 0x25, 0x41, 0x37, 0x25, 0x45, 0x35, 0x25, 0x39, 0x33, 0x25, 0x38, 0x31, 0x25, 0x45, 0x37, 0x25, 0x42, 0x42, 0x25, 0x38, 0x46, 0x25, 0x45, 0x37, 0x25, 0x39, 0x30, 0x25, 0x38, 0x36, 0x25, 0x45, 0x35, 0x25, 0x39, 0x46, 0x25, 0x42, 0x39, 0x25, 0x45, 0x38, 0x25, 0x41, 0x45, 0x25, 0x41, 0x44, 0x25, 0x45, 0x38, 0x25, 0x41, 0x46, 0x25, 0x42, 0x45, 0x25, 0x45, 0x37, 0x25, 0x41, 0x38, 0x25, 0x38, 0x42, 0x2b, 0x25, 0x37, 0x43, 0x2b, 0x25, 0x45, 0x38, 0x25, 0x38, 0x37, 0x25, 0x42, 0x34, 0x25, 0x45, 0x35, 0x25, 0x38, 0x41, 0x25, 0x39, 0x42, 0x25, 0x45, 0x34, 0x25, 0x42, 0x41, 0x25, 0x38, 0x45, 0x25, 0x45, 0x34, 0x25, 0x42, 0x38, 0x25, 0x42, 0x41, 0x49, 0x54, 0x25, 0x45, 0x34, 0x25, 0x42, 0x42, 0x25, 0x38, 0x45, 0x25, 0x45, 0x34, 0x25, 0x42, 0x38, 0x25, 0x39, 0x41, 0x25, 0x45, 0x38, 0x25, 0x38, 0x30, 0x25, 0x38, 0x35, 0x25, 0x45, 0x36, 0x25, 0x38, 0x46, 0x25, 0x39, 0x30, 0x25, 0x45, 0x34, 0x25, 0x42, 0x45, 0x25, 0x39, 0x42, 0x25, 0x45, 0x34, 0x25, 0x42, 0x38, 0x25, 0x39, 0x33, 0x25, 0x45, 0x34, 0x25, 0x42, 0x38, 0x25, 0x39, 0x41, 0x25, 0x45, 0x33, 0x25, 0x38, 0x30, 0x25, 0x38, 0x31, 0x25, 0x45, 0x37, 0x25, 0x42, 0x33, 0x25, 0x42, 0x42, 0x25, 0x45, 0x37, 0x25, 0x42, 0x42, 0x25, 0x39, 0x46, 0x25, 0x45, 0x37, 0x25, 0x39, 0x41, 0x25, 0x38, 0x34, 0x25, 0x45, 0x34, 0x25, 0x42, 0x41, 0x25, 0x41, 0x37, 0x25, 0x45, 0x35, 0x25, 0x39, 0x33, 0x25, 0x38, 0x31, 0x25, 0x45, 0x37, 0x25, 0x42, 0x42, 0x25, 0x38, 0x46, 0x25, 0x45, 0x37, 0x25, 0x39, 0x30, 0x25, 0x38, 0x36, 0x25, 0x45, 0x35, 0x25, 0x41, 0x44, 0x25, 0x41, 0x36, 0x25, 0x45, 0x34, 0x25, 0x42, 0x39, 0x25, 0x41, 0x30, 0x25, 0x45, 0x36, 0x25, 0x39, 0x43, 0x25, 0x38, 0x44, 0x25, 0x45, 0x35, 0x25, 0x38, 0x41, 0x25, 0x41, 0x31, 0x25, 0x45, 0x46, 0x25, 0x42, 0x43, 0x25, 0x38, 0x43, 0x25, 0x45, 0x37, 0x25, 0x39, 0x42, 0x25, 0x41, 0x45, 0x25, 0x45, 0x36, 0x25, 0x41, 0x30, 0x25, 0x38, 0x37, 0x25, 0x45, 0x36, 0x25, 0x38, 0x38, 0x25, 0x39, 0x30, 0x25, 0x45, 0x34, 0x25, 0x42, 0x38, 0x25, 0x42, 0x41, 0x25, 0x45, 0x34, 0x25, 0x42, 0x41, 0x25, 0x41, 0x37, 0x25, 0x45, 0x35, 0x25, 0x39, 0x33, 0x25, 0x38, 0x31, 0x25, 0x45, 0x37, 0x25, 0x42, 0x42, 0x25, 0x38, 0x46, 0x25, 0x45, 0x37, 0x25, 0x39, 0x30, 0x25, 0x38, 0x36, 0x25, 0x45, 0x39, 0x25, 0x42, 0x42, 0x25, 0x38, 0x34, 0x25, 0x45, 0x35, 0x25, 0x39, 0x46, 0x25, 0x39, 0x34, 0x25, 0x45, 0x35, 0x25, 0x38, 0x36, 0x25, 0x39, 0x42, 0x25, 0x45, 0x36, 0x25, 0x41, 0x30, 0x25, 0x41, 0x31, 0x0d, 0x0a, 0x0d, 0x0a };
//Frame : 9 [Protocols in frame: eth:ip:tcp:http] char http_rep[] = { 0x02, 0xa9, 0x1c, 0x7d, 0xea, 0x54, 0x30, 0xfc, 0x68, 0xff, 0x70, 0xfb, 0x08, 0x00, 0x45, 0x00, 0x02, 0x07, 0xe4, 0x35, 0x40, 0x00, 0x33, 0x06, 0xd2, 0x5f, 0x7a, 0xe2, 0x54, 0x2f, 0xac, 0x10, 0x14, 0x3a, 0x00, 0x50, 0x15, 0xba, 0x92, 0xd3, 0x8d, 0x1d, 0x7e, 0xf8, 0x50, 0xf9, 0x50, 0x18, 0x00, 0x14, 0x39, 0xb8, 0x00, 0x00, 0x48, 0x54, 0x54, 0x50, 0x2f, 0x31, 0x2e, 0x31, 0x20, 0x32, 0x30, 0x30, 0x20, 0x4f, 0x4b, 0x0d, 0x0a, 0x53, 0x65, 0x72, 0x76, 0x65, 0x72, 0x3a, 0x20, 0x6f, 0x70, 0x65, 0x6e, 0x72, 0x65, 0x73, 0x74, 0x79, 0x0d, 0x0a, 0x44, 0x61, 0x74, 0x65, 0x3a, 0x20, 0x57, 0x65, 0x64, 0x2c, 0x20, 0x31, 0x33, 0x20, 0x4d, 0x61, 0x79, 0x20, 0x32, 0x30, 0x32, 0x30, 0x20, 0x30, 0x39, 0x3a, 0x30, 0x39, 0x3a, 0x34, 0x30, 0x20, 0x47, 0x4d, 0x54, 0x0d, 0x0a, 0x43, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x2d, 0x54, 0x79, 0x70, 0x65, 0x3a, 0x20, 0x61, 0x70, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x2f, 0x78, 0x2d, 0x6a, 0x61, 0x76, 0x61, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x0d, 0x0a, 0x43, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x2d, 0x4c, 0x65, 0x6e, 0x67, 0x74, 0x68, 0x3a, 0x20, 0x31, 0x35, 0x39, 0x0d, 0x0a, 0x43, 0x6f, 0x6e, 0x6e, 0x65, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x3a, 0x20, 0x6b, 0x65, 0x65, 0x70, 0x2d, 0x61, 0x6c, 0x69, 0x76, 0x65, 0x0d, 0x0a, 0x4c, 0x61, 0x73, 0x74, 0x2d, 0x4d, 0x6f, 0x64, 0x69, 0x66, 0x69, 0x65, 0x64, 0x3a, 0x20, 0x54, 0x68, 0x75, 0x2c, 0x20, 0x32, 0x35, 0x20, 0x4a, 0x75, 0x6c, 0x20, 0x32, 0x30, 0x31, 0x39, 0x20, 0x31, 0x39, 0x3a, 0x30, 0x37, 0x3a, 0x33, 0x33, 0x20, 0x47, 0x4d, 0x54, 0x0d, 0x0a, 0x45, 0x54, 0x61, 0x67, 0x3a, 0x20, 0x22, 0x35, 0x64, 0x33, 0x39, 0x66, 0x64, 0x66, 0x35, 0x2d, 0x39, 0x66, 0x22, 0x0d, 0x0a, 0x45, 0x78, 0x70, 0x69, 0x72, 0x65, 0x73, 0x3a, 0x20, 0x53, 0x61, 0x74, 0x2c, 0x20, 0x31, 0x36, 0x20, 0x4d, 0x61, 0x79, 0x20, 0x32, 0x30, 0x32, 0x30, 0x20, 0x30, 0x39, 0x3a, 0x30, 0x39, 0x3a, 0x34, 0x30, 0x20, 0x47, 0x4d, 0x54, 0x0d, 0x0a, 0x43, 0x61, 0x63, 0x68, 0x65, 0x2d, 0x43, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x3a, 0x20, 0x6d, 0x61, 0x78, 0x2d, 0x61, 0x67, 0x65, 0x3d, 0x32, 0x35, 0x39, 0x32, 0x30, 0x30, 0x0d, 0x0a, 0x41, 0x63, 0x63, 0x65, 0x70, 0x74, 0x2d, 0x52, 0x61, 0x6e, 0x67, 0x65, 0x73, 0x3a, 0x20, 0x62, 0x79, 0x74, 0x65, 0x73, 0x0d, 0x0a, 0x0d, 0x0a, 0x24, 0x35, 0x33, 0x2e, 0x64, 0x61, 0x74, 0x61, 0x28, 0x22, 0x6d, 0x6f, 0x62, 0x69, 0x6c, 0x65, 0x5f, 0x69, 0x63, 0x6f, 0x6e, 0x22, 0x2c, 0x7b, 0x22, 0x6f, 0x6e, 0x5f, 0x69, 0x73, 0x5f, 0x6f, 0x70, 0x65, 0x6e, 0x22, 0x3a, 0x22, 0x6e, 0x6f, 0x22, 0x2c, 0x22, 0x6f, 0x6e, 0x5f, 0x74, 0x6f, 0x70, 0x22, 0x3a, 0x22, 0x34, 0x30, 0x22, 0x2c, 0x22, 0x6f, 0x6e, 0x5f, 0x6c, 0x65, 0x66, 0x74, 0x22, 0x3a, 0x22, 0x31, 0x30, 0x30, 0x22, 0x2c, 0x22, 0x6f, 0x66, 0x66, 0x5f, 0x69, 0x73, 0x5f, 0x6f, 0x70, 0x65, 0x6e, 0x22, 0x3a, 0x22, 0x6e, 0x6f, 0x22, 0x2c, 0x22, 0x6f, 0x66, 0x66, 0x5f, 0x74, 0x6f, 0x70, 0x22, 0x3a, 0x22, 0x34, 0x30, 0x22, 0x2c, 0x22, 0x6f, 0x66, 0x66, 0x5f, 0x6c, 0x65, 0x66, 0x74, 0x22, 0x3a, 0x22, 0x31, 0x30, 0x30, 0x22, 0x2c, 0x22, 0x6f, 0x6e, 0x5f, 0x63, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x22, 0x3a, 0x22, 0x22, 0x2c, 0x22, 0x6f, 0x66, 0x66, 0x5f, 0x63, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x22, 0x3a, 0x22, 0x22, 0x7d, 0x29, 0x3b, 0x0a };
enum { PROTO_FIELD_IPV4, SRC_FIELD_IPV4, DST_FIELD_IPV4, SRCP_FIELD_IPV4, DSTP_FIELD_IPV4, NUM_FIELDS_IPV4 };
enum { RTE_ACL_IPV4VLAN_PROTO, RTE_ACL_IPV4VLAN_VLAN, RTE_ACL_IPV4VLAN_SRC, RTE_ACL_IPV4VLAN_DST, RTE_ACL_IPV4VLAN_PORTS, RTE_ACL_IPV4VLAN_NUM };
enum { CB_FLD_SRC_ADDR, CB_FLD_DST_ADDR, CB_FLD_SRC_PORT_LOW, CB_FLD_SRC_PORT_DLM, CB_FLD_SRC_PORT_HIGH, CB_FLD_DST_PORT_LOW, CB_FLD_DST_PORT_DLM, CB_FLD_DST_PORT_HIGH, CB_FLD_PROTO, CB_FLD_USERDATA, CB_FLD_CATEGORY_MASK, CB_FLD_NUM, };
struct rte_acl_field_def ipv4_defs[NUM_FIELDS_IPV4] = { { .type = RTE_ACL_FIELD_TYPE_BITMASK, .size = sizeof(uint8_t), .field_index = PROTO_FIELD_IPV4, .input_index = RTE_ACL_IPV4VLAN_PROTO, .offset = 0, }, { .type = RTE_ACL_FIELD_TYPE_MASK, .size = sizeof(uint32_t), .field_index = SRC_FIELD_IPV4, .input_index = RTE_ACL_IPV4VLAN_SRC, .offset = offsetof(struct ipv4_hdr, src_addr) - offsetof(struct ipv4_hdr, next_proto_id), }, { .type = RTE_ACL_FIELD_TYPE_MASK, .size = sizeof(uint32_t), .field_index = DST_FIELD_IPV4, .input_index = RTE_ACL_IPV4VLAN_DST, .offset = offsetof(struct ipv4_hdr, dst_addr) - offsetof(struct ipv4_hdr, next_proto_id), }, { .type = RTE_ACL_FIELD_TYPE_RANGE, .size = sizeof(uint16_t), .field_index = SRCP_FIELD_IPV4, .input_index = RTE_ACL_IPV4VLAN_PORTS, .offset = sizeof(struct ipv4_hdr) - offsetof(struct ipv4_hdr, next_proto_id), }, { .type = RTE_ACL_FIELD_TYPE_RANGE, .size = sizeof(uint16_t), .field_index = DSTP_FIELD_IPV4, .input_index = RTE_ACL_IPV4VLAN_PORTS, .offset = sizeof(struct ipv4_hdr) - offsetof(struct ipv4_hdr, next_proto_id) + sizeof(uint16_t), }, };
RTE_ACL_RULE_DEF(acl4_rule, RTE_DIM(ipv4_defs));
const char cb_port_delim[] = ":"; #define MAX_ACL_RULE_NUM 100000
#define OFF_ETHHEAD (sizeof(struct ether_hdr)) #define OFF_IPV42PROTO (offsetof(struct ipv4_hdr, next_proto_id))
#define GET_CB_FIELD(in, fd, base, lim, dlm) do { \ unsigned long val; \ char *end; \ errno = 0; \ val = strtoul((in), &end, (base)); \ if (errno != 0 || end[0] != (dlm) || val > (lim)) \ return -EINVAL; \ (fd) = (typeof(fd))val; \ (in) = end + 1; \ } while (0)
#define uint32_t_to_char(ip, a, b, c, d) do {\ *a = (unsigned char)(ip >> 24 & 0xff);\ *b = (unsigned char)(ip >> 16 & 0xff);\ *c = (unsigned char)(ip >> 8 & 0xff);\ *d = (unsigned char)(ip & 0xff);\ } while (0)
static int parse_ipv4_net(const char *in, uint32_t *addr, uint32_t *mask_len) { uint8_t a, b, c, d, m;
GET_CB_FIELD(in, a, 0, UINT8_MAX, '.'); GET_CB_FIELD(in, b, 0, UINT8_MAX, '.'); GET_CB_FIELD(in, c, 0, UINT8_MAX, '.'); GET_CB_FIELD(in, d, 0, UINT8_MAX, '/'); GET_CB_FIELD(in, m, 0, sizeof(uint32_t) * CHAR_BIT, 0);
addr[0] = IPv4(a, b, c, d); mask_len[0] = m;
return 0; }
static int parse_ipv4_rule(const char *str, struct rte_acl_rule *v) { int i, rc; char *s, *sp, *in[CB_FLD_NUM]; const char *dlm = " \t\n"; int dim = CB_FLD_NUM;
char buff[1024]; strcpy(buff, str); s = buff;
for (i = 0; i != dim; i++, s = NULL) { in[i] = strtok_r(s, dlm, &sp); if (in[i] == NULL) { printf("ERROR: near by %s %s\n", s, sp); return -EINVAL; } }
rc = parse_ipv4_net(in[CB_FLD_SRC_ADDR], &v->field[SRC_FIELD_IPV4].value.u32, &v->field[SRC_FIELD_IPV4].mask_range.u32); if (rc != 0) { printf("failed to read source address/mask: %s\n", in[CB_FLD_SRC_ADDR]); return rc; }
rc = parse_ipv4_net(in[CB_FLD_DST_ADDR], &v->field[DST_FIELD_IPV4].value.u32, &v->field[DST_FIELD_IPV4].mask_range.u32); if (rc != 0) { printf("failed to read destination address/mask: %s\n", in[CB_FLD_DST_ADDR]); return rc; }
GET_CB_FIELD(in[CB_FLD_SRC_PORT_LOW],v->field[SRCP_FIELD_IPV4].value.u16, 0, UINT16_MAX, 0); GET_CB_FIELD(in[CB_FLD_SRC_PORT_HIGH],v->field[SRCP_FIELD_IPV4].mask_range.u16, 0, UINT16_MAX, 0);
if (strncmp(in[CB_FLD_SRC_PORT_DLM], cb_port_delim, sizeof(cb_port_delim)) != 0) return -EINVAL;
GET_CB_FIELD(in[CB_FLD_DST_PORT_LOW],v->field[DSTP_FIELD_IPV4].value.u16,0, UINT16_MAX, 0); GET_CB_FIELD(in[CB_FLD_DST_PORT_HIGH], v->field[DSTP_FIELD_IPV4].mask_range.u16, 0, UINT16_MAX, 0);
if (strncmp(in[CB_FLD_DST_PORT_DLM], cb_port_delim, sizeof(cb_port_delim)) != 0) return -EINVAL;
if (v->field[SRCP_FIELD_IPV4].mask_range.u16< v->field[SRCP_FIELD_IPV4].value.u16 || v->field[DSTP_FIELD_IPV4].mask_range.u16 < v->field[DSTP_FIELD_IPV4].value.u16) return -EINVAL;
GET_CB_FIELD(in[CB_FLD_PROTO], v->field[PROTO_FIELD_IPV4].value.u8, 0, UINT8_MAX, '/'); GET_CB_FIELD(in[CB_FLD_PROTO], v->field[PROTO_FIELD_IPV4].mask_range.u8, 0, UINT8_MAX, 0); GET_CB_FIELD(in[CB_FLD_USERDATA], v->data.userdata, 0, UINT32_MAX, 0); GET_CB_FIELD(in[CB_FLD_CATEGORY_MASK], v->data.category_mask, 0, UINT32_MAX, 0); return 0; }
static int add_rules(const char **rule_list, struct rte_acl_rule **pacl_base, unsigned int *pacl_num) { uint8_t *acl_rules = NULL; struct rte_acl_rule *rule = NULL; unsigned int acl_cnt = 0; unsigned int rule_size = 0; unsigned int i = 0;
//统计 while(rule_list[rule_size]) { rule_size++; } if(0 == rule_size) { return -1; }
acl_rules = malloc(rule_size * sizeof(struct acl4_rule)); memset(acl_rules, 0, rule_size * sizeof(struct acl4_rule));
//添加 for(i = 0; rule_list[i]; i++) { const char *rule_text = rule_list[i]; rule = (struct rte_acl_rule *)(acl_rules + acl_cnt * sizeof(struct acl4_rule)); if (parse_ipv4_rule(rule_text, rule) != 0) rte_exit(EXIT_FAILURE, "parse rules error\n");
//rule->data.priority = RTE_ACL_MAX_PRIORITY - acl_cnt; rule->data.priority = 500 + acl_cnt; acl_cnt++; };
//传出参数 *pacl_base = (struct rte_acl_rule *)acl_rules; *pacl_num = acl_cnt; return 0; }
static inline void print_one_ipv4_rule(struct acl4_rule *rule) { unsigned char a, b, c, d;
uint32_t_to_char(rule->field[SRC_FIELD_IPV4].value.u32, &a, &b, &c, &d); printf("%hhu.%hhu.%hhu.%hhu/%u ", a, b, c, d, rule->field[SRC_FIELD_IPV4].mask_range.u32); uint32_t_to_char(rule->field[DST_FIELD_IPV4].value.u32, &a, &b, &c, &d); printf("%hhu.%hhu.%hhu.%hhu/%u ", a, b, c, d, rule->field[DST_FIELD_IPV4].mask_range.u32); printf("%hu : %hu %hu : %hu 0x%hhx/0x%hhx ", rule->field[SRCP_FIELD_IPV4].value.u16, rule->field[SRCP_FIELD_IPV4].mask_range.u16, rule->field[DSTP_FIELD_IPV4].value.u16, rule->field[DSTP_FIELD_IPV4].mask_range.u16, rule->field[PROTO_FIELD_IPV4].value.u8, rule->field[PROTO_FIELD_IPV4].mask_range.u8); printf("userdata:%u ", rule->data.userdata); printf("priority:%u ", rule->data.priority); printf("category_mask:%u ", rule->data.category_mask); }
static inline void dump_ipv4_rules(struct acl4_rule *rule, int num) { int i;
for (i = 0; i < num; i++, rule++) { printf("%d:", i + 1); print_one_ipv4_rule(rule); printf("\n"); } }
static struct rte_acl_ctx* setup_acl(struct rte_acl_rule *acl_base, unsigned int acl_num) { char name[PATH_MAX]; struct rte_acl_param acl_param; struct rte_acl_config acl_build_param; struct rte_acl_ctx *context; int dim = RTE_DIM(ipv4_defs); int socketid = 0;
/* Create ACL contexts */ snprintf(name, sizeof(name), "%s", "ACL_CHUNLI");
acl_param.name = name; acl_param.socket_id = socketid; acl_param.rule_size = RTE_ACL_RULE_SZ(dim); acl_param.max_rule_num = MAX_ACL_RULE_NUM;
if ((context = rte_acl_create(&acl_param)) == NULL) rte_exit(EXIT_FAILURE, "Failed to create ACL context\n");
if (rte_acl_set_ctx_classify(context, RTE_ACL_CLASSIFY_SCALAR) != 0) rte_exit(EXIT_FAILURE, "Failed to setup classify method for ACL context\n");
if (rte_acl_add_rules(context, acl_base, acl_num) < 0) rte_exit(EXIT_FAILURE, "add rules failed\n");
/* Perform builds */ memset(&acl_build_param, 0, sizeof(acl_build_param)); acl_build_param.num_categories = RTE_ACL_MAX_CATEGORIES; acl_build_param.num_fields = dim; memcpy(&acl_build_param.defs, ipv4_defs, sizeof(ipv4_defs));
if (rte_acl_build(context, &acl_build_param) != 0) rte_exit(EXIT_FAILURE, "Failed to build ACL trie\n");
return context; }
int main(int argc, char **argv) { int ret; int i; int j; int pkts_num = 0; int max_categories = RTE_ACL_MAX_CATEGORIES; unsigned int acl_ipv4_num; struct rte_acl_rule *acl_ipv4; struct rte_acl_ctx *acl_ipv4_ctx;
ret = rte_eal_init(argc, argv); if (ret < 0) rte_exit(EXIT_FAILURE, "Invalid EAL parameters\n");
argc -= ret; argv += ret;
//多条报文同时参与匹配 const uint8_t *pkts[] = { (const uint8_t*)http_req + OFF_ETHHEAD + OFF_IPV42PROTO,//指向IPv4的proto, (const uint8_t*)http_rep + OFF_ETHHEAD + OFF_IPV42PROTO,//指向IPv4的proto, NULL, };
//统计报文数 for(i = 0; pkts[i]; i++) { pkts_num++; }
//多条规则同时参与匹配 const char *rule_list[] = { "172.16.20.59/32 0.0.0.0/0 0 : 65535 0 : 65535 6/0xfe 1001 1", //cat't "172.16.20.58/32 122.226.84.47/32 0 : 65535 0 : 65535 6/0xfe 1003 32767", //OK hit http_req "172.16.20.58/32 122.226.84.47/32 0 : 65535 0 : 65535 6/0xfe 1002 1", //OK hit http_req "122.226.84.47/32 172.16.20.58/32 0 : 65535 0 : 65535 6/0xfe 1004 32768", //OK hit http_req NULL };
//规则添加 ret = add_rules(rule_list, &acl_ipv4, &acl_ipv4_num); if (ret < 0) rte_exit(EXIT_FAILURE, "ERROR add_rules\n");
//规则编译预览 dump_ipv4_rules((struct acl4_rule *)acl_ipv4, acl_ipv4_num);
//规则编译 acl_ipv4_ctx = setup_acl(acl_ipv4, acl_ipv4_num); if (NULL == acl_ipv4_ctx) rte_exit(EXIT_FAILURE, "ERROR setup_acl\n");
//构造匹配空间 uint32_t *res_ipv4 = malloc(sizeof(uint32_t)*max_categories * pkts_num); memset(res_ipv4, 0, sizeof(uint32_t)*max_categories * pkts_num);
//开始匹配 ret = rte_acl_classify(acl_ipv4_ctx, pkts, res_ipv4, pkts_num, max_categories); if (ret < 0) rte_exit(EXIT_FAILURE, "ERROR rte_acl_classify\n");
//输出行头 CATEGORIES 16行 for(i = 0; i < max_categories; i++) { printf("C%d\t", i); } printf("\n");
//输出匹配空间 for(j = 0; j < pkts_num; j++) { for(i = 0; i < max_categories; i++) { printf("%d\t", res_ipv4[j*max_categories+i]); } printf("\n"); }
//结束 free(acl_ipv4); rte_acl_free(acl_ipv4_ctx); free(res_ipv4); return 0; }
|