X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Fnspawn%2Fnspawn.c;h=d01da45930ce1900777c6248ecaa8a6e650a086a;hb=4d8ddba9d71e51356cc9488f906b8fef89c60c23;hp=b118c739e8c6b0f562b2daf14520d15443d420e4;hpb=4212a3375e03fd12cb407b34cab59dbe4ed9f4eb;p=elogind.git diff --git a/src/nspawn/nspawn.c b/src/nspawn/nspawn.c index b118c739e..d01da4593 100644 --- a/src/nspawn/nspawn.c +++ b/src/nspawn/nspawn.c @@ -166,8 +166,7 @@ static unsigned long arg_personality = 0xffffffffLU; static const char *arg_image = NULL; static Volatile arg_volatile = VOLATILE_NO; -static int help(void) { - +static void help(void) { printf("%s [OPTIONS...] [PATH] [ARGUMENTS...]\n\n" "Spawn a minimal namespace container for debugging, testing and building.\n\n" " -h --help Show this help\n" @@ -216,8 +215,6 @@ static int help(void) { " the service unit nspawn is running in\n" " --volatile[=MODE] Run the system in volatile mode\n", program_invocation_short_name); - - return 0; } static int parse_argv(int argc, char *argv[]) { @@ -285,12 +282,13 @@ static int parse_argv(int argc, char *argv[]) { assert(argc >= 0); assert(argv); - while ((c = getopt_long(argc, argv, "+hD:u:bL:M:jS:Z:qi:", options, NULL)) >= 0) { + while ((c = getopt_long(argc, argv, "+hD:u:bL:M:jS:Z:qi:", options, NULL)) >= 0) switch (c) { case 'h': - return help(); + help(); + return 0; case ARG_VERSION: puts(PACKAGE_STRING); @@ -593,7 +591,6 @@ static int parse_argv(int argc, char *argv[]) { default: assert_not_reached("Unhandled option"); } - } if (arg_share_system) arg_register = false; @@ -1389,7 +1386,7 @@ static int drop_capabilities(void) { static int register_machine(pid_t pid, int local_ifindex) { _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL; - _cleanup_bus_unref_ sd_bus *bus = NULL; + _cleanup_bus_close_unref_ sd_bus *bus = NULL; int r; if (!arg_register) @@ -1524,7 +1521,7 @@ static int register_machine(pid_t pid, int local_ifindex) { static int terminate_machine(pid_t pid) { _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL; _cleanup_bus_message_unref_ sd_bus_message *reply = NULL; - _cleanup_bus_unref_ sd_bus *bus = NULL; + _cleanup_bus_close_unref_ sd_bus *bus = NULL; const char *path; int r; @@ -1609,9 +1606,10 @@ static int reset_audit_loginuid(void) { return 0; } -#define HASH_KEY SD_ID128_MAKE(c3,c4,f9,19,b5,57,b2,1c,e6,cf,14,27,03,9c,ee,a2) +#define HOST_HASH_KEY SD_ID128_MAKE(1a,37,6f,c7,46,ec,45,0b,ad,a3,d5,31,06,60,5d,b1) +#define CONTAINER_HASH_KEY SD_ID128_MAKE(c3,c4,f9,19,b5,57,b2,1c,e6,cf,14,27,03,9c,ee,a2) -static int get_mac(struct ether_addr *mac) { +static int generate_mac(struct ether_addr *mac, sd_id128_t hash_key) { int r; uint8_t result[8]; @@ -1633,7 +1631,7 @@ static int get_mac(struct ether_addr *mac) { /* Let's hash the host machine ID plus the container name. We * use a fixed, but originally randomly created hash key here. */ - siphash24(result, v, sz, HASH_KEY.bytes); + siphash24(result, v, sz, hash_key.bytes); assert_cc(ETH_ALEN <= sizeof(result)); memcpy(mac->ether_addr_octet, result, ETH_ALEN); @@ -1648,7 +1646,7 @@ static int get_mac(struct ether_addr *mac) { static int setup_veth(pid_t pid, char iface_name[IFNAMSIZ], int *ifi) { _cleanup_rtnl_message_unref_ sd_rtnl_message *m = NULL; _cleanup_rtnl_unref_ sd_rtnl *rtnl = NULL; - struct ether_addr mac; + struct ether_addr mac_host, mac_container; int r, i; if (!arg_private_network) @@ -1662,9 +1660,15 @@ static int setup_veth(pid_t pid, char iface_name[IFNAMSIZ], int *ifi) { snprintf(iface_name, IFNAMSIZ, "%s-%s", arg_network_bridge ? "vb" : "ve", arg_machine); - r = get_mac(&mac); + r = generate_mac(&mac_container, CONTAINER_HASH_KEY); + if (r < 0) { + log_error("Failed to generate predictable MAC address for container side"); + return r; + } + + r = generate_mac(&mac_host, HOST_HASH_KEY); if (r < 0) { - log_error("Failed to generate predictable MAC address for host0"); + log_error("Failed to generate predictable MAC address for host side"); return r; } @@ -1686,6 +1690,12 @@ static int setup_veth(pid_t pid, char iface_name[IFNAMSIZ], int *ifi) { return r; } + r = sd_rtnl_message_append_ether_addr(m, IFLA_ADDRESS, &mac_host); + if (r < 0) { + log_error("Failed to add netlink MAC address: %s", strerror(-r)); + return r; + } + r = sd_rtnl_message_open_container(m, IFLA_LINKINFO); if (r < 0) { log_error("Failed to open netlink container: %s", strerror(-r)); @@ -1710,7 +1720,7 @@ static int setup_veth(pid_t pid, char iface_name[IFNAMSIZ], int *ifi) { return r; } - r = sd_rtnl_message_append_ether_addr(m, IFLA_ADDRESS, &mac); + r = sd_rtnl_message_append_ether_addr(m, IFLA_ADDRESS, &mac_container); if (r < 0) { log_error("Failed to add netlink MAC address: %s", strerror(-r)); return r;