| 606 | } |
| 607 | |
| 608 | CommandResponse L2Forward::CommandAdd( |
| 609 | const bess::pb::L2ForwardCommandAddArg &arg) { |
| 610 | for (int i = 0; i < arg.entries_size(); i++) { |
| 611 | const auto &entry = arg.entries(i); |
| 612 | |
| 613 | if (!entry.addr().length()) { |
| 614 | return CommandFailure(EINVAL, |
| 615 | "add list item map must contain addr as a string"); |
| 616 | } |
| 617 | |
| 618 | const char *str_addr = entry.addr().c_str(); |
| 619 | int gate = entry.gate(); |
| 620 | char addr[6]; |
| 621 | |
| 622 | if (parse_mac_addr(str_addr, addr) != 0) { |
| 623 | return CommandFailure(EINVAL, "%s is not a proper mac address", str_addr); |
| 624 | } |
| 625 | |
| 626 | int r = l2_add_entry(&l2_table_, l2_addr_to_u64(addr), gate); |
| 627 | |
| 628 | if (r == -EEXIST) { |
| 629 | return CommandFailure(EEXIST, "MAC address '%s' already exist", str_addr); |
| 630 | } else if (r == -ENOMEM) { |
| 631 | return CommandFailure(ENOMEM, "Not enough space"); |
| 632 | } else if (r != 0) { |
| 633 | return CommandFailure(-r); |
| 634 | } |
| 635 | } |
| 636 | |
| 637 | return CommandSuccess(); |
| 638 | } |
| 639 | |
| 640 | CommandResponse L2Forward::CommandDelete( |
| 641 | const bess::pb::L2ForwardCommandDeleteArg &arg) { |
nothing calls this directly
no test coverage detected