| 33 | namespace veth { |
| 34 | |
| 35 | Try<bool> create( |
| 36 | const string& veth, |
| 37 | const string& peer, |
| 38 | const Option<pid_t>& pid) |
| 39 | { |
| 40 | Try<Netlink<struct nl_sock>> socket = routing::socket(); |
| 41 | if (socket.isError()) { |
| 42 | return Error(socket.error()); |
| 43 | } |
| 44 | |
| 45 | int error = rtnl_link_veth_add( |
| 46 | socket->get(), |
| 47 | veth.c_str(), |
| 48 | peer.c_str(), |
| 49 | (pid.isNone() ? getpid() : pid.get())); |
| 50 | |
| 51 | if (error != 0) { |
| 52 | if (error == -NLE_EXIST) { |
| 53 | return false; |
| 54 | } |
| 55 | return Error(nl_geterror(error)); |
| 56 | } |
| 57 | |
| 58 | return true; |
| 59 | } |
| 60 | |
| 61 | } // namespace veth { |
| 62 | } // namespace link { |