| 555 | |
| 556 | |
| 557 | int PortMappingUpdate::execute() |
| 558 | { |
| 559 | if (flags.help) { |
| 560 | cerr << "Usage: " << name() << " [OPTIONS]" << endl << endl |
| 561 | << "Supported options:" << endl |
| 562 | << flags.usage(); |
| 563 | return 0; |
| 564 | } |
| 565 | |
| 566 | if (flags.eth0_name.isNone()) { |
| 567 | cerr << "The public interface name (e.g., eth0) is not specified" << endl; |
| 568 | return 1; |
| 569 | } |
| 570 | |
| 571 | if (flags.lo_name.isNone()) { |
| 572 | cerr << "The loopback interface name (e.g., lo) is not specified" << endl; |
| 573 | return 1; |
| 574 | } |
| 575 | |
| 576 | if (flags.pid.isNone()) { |
| 577 | cerr << "The pid is not specified" << endl; |
| 578 | return 1; |
| 579 | } |
| 580 | |
| 581 | if (flags.ports_to_add.isNone() && flags.ports_to_remove.isNone()) { |
| 582 | cerr << "Nothing to update" << endl; |
| 583 | return 1; |
| 584 | } |
| 585 | |
| 586 | Option<vector<PortRange>> portsToAdd; |
| 587 | Option<vector<PortRange>> portsToRemove; |
| 588 | |
| 589 | if (flags.ports_to_add.isSome()) { |
| 590 | Try<vector<PortRange>> parsing = parse(flags.ports_to_add.get()); |
| 591 | if (parsing.isError()) { |
| 592 | cerr << "Parsing 'ports_to_add' failed: " << parsing.error() << endl; |
| 593 | return 1; |
| 594 | } |
| 595 | portsToAdd = parsing.get(); |
| 596 | } |
| 597 | |
| 598 | if (flags.ports_to_remove.isSome()) { |
| 599 | Try<vector<PortRange>> parsing = parse(flags.ports_to_remove.get()); |
| 600 | if (parsing.isError()) { |
| 601 | cerr << "Parsing 'ports_to_remove' failed: " << parsing.error() << endl; |
| 602 | return 1; |
| 603 | } |
| 604 | portsToRemove = parsing.get(); |
| 605 | } |
| 606 | |
| 607 | // Enter the network namespace. |
| 608 | Try<Nothing> setns = ns::setns(flags.pid.get(), "net"); |
| 609 | if (setns.isError()) { |
| 610 | cerr << "Failed to enter the network namespace of pid " << flags.pid.get() |
| 611 | << ": " << setns.error() << endl; |
| 612 | return 1; |
| 613 | } |
| 614 |
nothing calls this directly
no test coverage detected