| 1509 | } |
| 1510 | |
| 1511 | Status ConfigureGateHook(ServerContext*, |
| 1512 | const ConfigureGateHookRequest* request, |
| 1513 | ConfigureGateHookResponse* response) override { |
| 1514 | std::lock_guard<std::recursive_mutex> lock(mutex_); |
| 1515 | |
| 1516 | WorkerPauser wp; |
| 1517 | bool use_gate = true; |
| 1518 | gate_idx_t gate_idx = 0; |
| 1519 | bool is_igate = |
| 1520 | request->hook().gate_case() == bess::pb::GateHookInfo::kIgate; |
| 1521 | |
| 1522 | if (is_igate) { |
| 1523 | gate_idx = request->hook().igate(); |
| 1524 | use_gate = request->hook().igate() >= 0; |
| 1525 | } else { |
| 1526 | gate_idx = request->hook().ogate(); |
| 1527 | use_gate = request->hook().ogate() >= 0; |
| 1528 | } |
| 1529 | |
| 1530 | const auto builder = bess::GateHookBuilder::all_gate_hook_builders().find( |
| 1531 | request->hook().class_name()); |
| 1532 | if (builder == bess::GateHookBuilder::all_gate_hook_builders().end()) { |
| 1533 | return return_with_error(response, ENOENT, "No such gate hook: %s", |
| 1534 | request->hook().class_name().c_str()); |
| 1535 | } |
| 1536 | |
| 1537 | if (request->hook().module_name().length() == 0) { |
| 1538 | // Install this hook on all modules |
| 1539 | for (const auto& it : ModuleGraph::GetAllModules()) { |
| 1540 | if (request->enable()) { |
| 1541 | enable_hook_for_module(response, request->hook().hook_name(), |
| 1542 | it.second, gate_idx, is_igate, use_gate, |
| 1543 | builder->second, request->hook().arg()); |
| 1544 | } else { |
| 1545 | disable_hook_for_module(response, request->hook().class_name(), |
| 1546 | request->hook().hook_name(), it.second, |
| 1547 | gate_idx, is_igate, use_gate); |
| 1548 | } |
| 1549 | if (response->error().code() != 0) { |
| 1550 | return Status::OK; |
| 1551 | } |
| 1552 | } |
| 1553 | return Status::OK; |
| 1554 | } |
| 1555 | |
| 1556 | // Install this hook on the specified module |
| 1557 | const auto& it = |
| 1558 | ModuleGraph::GetAllModules().find(request->hook().module_name()); |
| 1559 | if (it == ModuleGraph::GetAllModules().end()) { |
| 1560 | return return_with_error(response, ENOENT, "No module '%s' found", |
| 1561 | request->hook().module_name().c_str()); |
| 1562 | } |
| 1563 | if (request->enable()) { |
| 1564 | enable_hook_for_module(response, request->hook().hook_name(), it->second, |
| 1565 | gate_idx, is_igate, use_gate, builder->second, |
| 1566 | request->hook().arg()); |
| 1567 | } else { |
| 1568 | disable_hook_for_module(response, request->hook().class_name(), |
nothing calls this directly
no test coverage detected