| 673 | } |
| 674 | |
| 675 | CommandResponse L2Forward::CommandLookup( |
| 676 | const bess::pb::L2ForwardCommandLookupArg &arg) { |
| 677 | bess::pb::L2ForwardCommandLookupResponse ret; |
| 678 | for (int i = 0; i < arg.addrs_size(); i++) { |
| 679 | const auto &_addr = arg.addrs(i); |
| 680 | |
| 681 | if (!_addr.length()) { |
| 682 | return CommandFailure(EINVAL, "lookup must be list of string"); |
| 683 | } |
| 684 | |
| 685 | const char *str_addr = _addr.c_str(); |
| 686 | char addr[6]; |
| 687 | |
| 688 | if (parse_mac_addr(str_addr, addr) != 0) { |
| 689 | return CommandFailure(EINVAL, "%s is not a proper mac address", str_addr); |
| 690 | } |
| 691 | |
| 692 | gate_idx_t gate; |
| 693 | int r = l2_find(&l2_table_, l2_addr_to_u64(addr), &gate); |
| 694 | |
| 695 | if (r == -ENOENT) { |
| 696 | return CommandFailure(ENOENT, "MAC address '%s' does not exist", |
| 697 | str_addr); |
| 698 | } else if (r != 0) { |
| 699 | return CommandFailure(EINVAL, "Unknown Error: %d\n", r); |
| 700 | } |
| 701 | ret.add_gates(gate); |
| 702 | } |
| 703 | |
| 704 | return CommandSuccess(ret); |
| 705 | } |
| 706 | |
| 707 | CommandResponse L2Forward::CommandPopulate( |
| 708 | const bess::pb::L2ForwardCommandPopulateArg &arg) { |
nothing calls this directly
no test coverage detected