diff --git a/src/libsystemd-network/dhcp6-protocol.h b/src/libsystemd-network/dhcp6-protocol.h index 2f41bcbfc8..e1f5b840d6 100644 --- a/src/libsystemd-network/dhcp6-protocol.h +++ b/src/libsystemd-network/dhcp6-protocol.h @@ -62,22 +62,46 @@ typedef enum DHCP6State { _DHCP6_STATE_INVALID = -EINVAL, } DHCP6State; -enum { - DHCP6_SOLICIT = 1, - DHCP6_ADVERTISE = 2, - DHCP6_REQUEST = 3, - DHCP6_CONFIRM = 4, - DHCP6_RENEW = 5, - DHCP6_REBIND = 6, - DHCP6_REPLY = 7, - DHCP6_RELEASE = 8, - DHCP6_DECLINE = 9, - DHCP6_RECONFIGURE = 10, - DHCP6_INFORMATION_REQUEST = 11, - DHCP6_RELAY_FORW = 12, - DHCP6_RELAY_REPL = 13, - _DHCP6_MESSAGE_MAX = 14, -}; +/* https://www.iana.org/assignments/dhcpv6-parameters/dhcpv6-parameters.xhtml#dhcpv6-parameters-1 */ +typedef enum DHCP6MessageType { + DHCP6_MESSAGE_SOLICIT = 1, /* RFC 8415 */ + DHCP6_MESSAGE_ADVERTISE = 2, /* RFC 8415 */ + DHCP6_MESSAGE_REQUEST = 3, /* RFC 8415 */ + DHCP6_MESSAGE_CONFIRM = 4, /* RFC 8415 */ + DHCP6_MESSAGE_RENEW = 5, /* RFC 8415 */ + DHCP6_MESSAGE_REBIND = 6, /* RFC 8415 */ + DHCP6_MESSAGE_REPLY = 7, /* RFC 8415 */ + DHCP6_MESSAGE_RELEASE = 8, /* RFC 8415 */ + DHCP6_MESSAGE_DECLINE = 9, /* RFC 8415 */ + DHCP6_MESSAGE_RECONFIGURE = 10, /* RFC 8415 */ + DHCP6_MESSAGE_INFORMATION_REQUEST = 11, /* RFC 8415 */ + DHCP6_MESSAGE_RELAY_FORWARD = 12, /* RFC 8415 */ + DHCP6_MESSAGE_RELAY_REPLY = 13, /* RFC 8415 */ + DHCP6_MESSAGE_LEASE_QUERY = 14, /* RFC 5007 */ + DHCP6_MESSAGE_LEASE_QUERY_REPLY = 15, /* RFC 5007 */ + DHCP6_MESSAGE_LEASE_QUERY_DONE = 16, /* RFC 5460 */ + DHCP6_MESSAGE_LEASE_QUERY_DATA = 17, /* RFC 5460 */ + DHCP6_MESSAGE_RECONFIGURE_REQUEST = 18, /* RFC 6977 */ + DHCP6_MESSAGE_RECONFIGURE_REPLY = 19, /* RFC 6977 */ + DHCP6_MESSAGE_DHCPV4_QUERY = 20, /* RFC 7341 */ + DHCP6_MESSAGE_DHCPV4_RESPONSE = 21, /* RFC 7341 */ + DHCP6_MESSAGE_ACTIVE_LEASE_QUERY = 22, /* RFC 7653 */ + DHCP6_MESSAGE_START_TLS = 23, /* RFC 7653 */ + DHCP6_MESSAGE_BINDING_UPDATE = 24, /* RFC 8156 */ + DHCP6_MESSAGE_BINDING_REPLY = 25, /* RFC 8156 */ + DHCP6_MESSAGE_POOL_REQUEST = 26, /* RFC 8156 */ + DHCP6_MESSAGE_POOL_RESPONSE = 27, /* RFC 8156 */ + DHCP6_MESSAGE_UPDATE_REQUEST = 28, /* RFC 8156 */ + DHCP6_MESSAGE_UPDATE_REQUEST_ALL = 29, /* RFC 8156 */ + DHCP6_MESSAGE_UPDATE_DONE = 30, /* RFC 8156 */ + DHCP6_MESSAGE_CONNECT = 31, /* RFC 8156 */ + DHCP6_MESSAGE_CONNECT_REPLY = 32, /* RFC 8156 */ + DHCP6_MESSAGE_DISCONNECT = 33, /* RFC 8156 */ + DHCP6_MESSAGE_STATE = 34, /* RFC 8156 */ + DHCP6_MESSAGE_CONTACT = 35, /* RFC 8156 */ + _DHCP6_MESSAGE_TYPE_MAX, + _DHCP6_MESSAGE_TYPE_INVALID = -EINVAL, +} DHCP6MessageType; typedef enum DHCP6NTPSubOption { DHCP6_NTP_SUBOPTION_SRV_ADDR = 1, diff --git a/src/libsystemd-network/sd-dhcp6-client.c b/src/libsystemd-network/sd-dhcp6-client.c index 6ed78259e0..d729b4aa13 100644 --- a/src/libsystemd-network/sd-dhcp6-client.c +++ b/src/libsystemd-network/sd-dhcp6-client.c @@ -96,20 +96,42 @@ static const uint16_t default_req_opts[] = { SD_DHCP6_OPTION_SNTP_SERVERS, }; -const char * dhcp6_message_type_table[_DHCP6_MESSAGE_MAX] = { - [DHCP6_SOLICIT] = "SOLICIT", - [DHCP6_ADVERTISE] = "ADVERTISE", - [DHCP6_REQUEST] = "REQUEST", - [DHCP6_CONFIRM] = "CONFIRM", - [DHCP6_RENEW] = "RENEW", - [DHCP6_REBIND] = "REBIND", - [DHCP6_REPLY] = "REPLY", - [DHCP6_RELEASE] = "RELEASE", - [DHCP6_DECLINE] = "DECLINE", - [DHCP6_RECONFIGURE] = "RECONFIGURE", - [DHCP6_INFORMATION_REQUEST] = "INFORMATION-REQUEST", - [DHCP6_RELAY_FORW] = "RELAY-FORW", - [DHCP6_RELAY_REPL] = "RELAY-REPL", +const char * dhcp6_message_type_table[_DHCP6_MESSAGE_TYPE_MAX] = { + [DHCP6_MESSAGE_SOLICIT] = "Solicit", + [DHCP6_MESSAGE_ADVERTISE] = "Advertise", + [DHCP6_MESSAGE_REQUEST] = "Request", + [DHCP6_MESSAGE_CONFIRM] = "Confirm", + [DHCP6_MESSAGE_RENEW] = "Renew", + [DHCP6_MESSAGE_REBIND] = "Rebind", + [DHCP6_MESSAGE_REPLY] = "Reply", + [DHCP6_MESSAGE_RELEASE] = "Release", + [DHCP6_MESSAGE_DECLINE] = "Decline", + [DHCP6_MESSAGE_RECONFIGURE] = "Reconfigure", + [DHCP6_MESSAGE_INFORMATION_REQUEST] = "Information Request", + [DHCP6_MESSAGE_RELAY_FORWARD] = "Relay Forward", + [DHCP6_MESSAGE_RELAY_REPLY] = "Relay Reply", + [DHCP6_MESSAGE_LEASE_QUERY] = "Lease Query", + [DHCP6_MESSAGE_LEASE_QUERY_REPLY] = "Lease Query Reply", + [DHCP6_MESSAGE_LEASE_QUERY_DONE] = "Lease Query Done", + [DHCP6_MESSAGE_LEASE_QUERY_DATA] = "Lease Query Data", + [DHCP6_MESSAGE_RECONFIGURE_REQUEST] = "Reconfigure Request", + [DHCP6_MESSAGE_RECONFIGURE_REPLY] = "Reconfigure Reply", + [DHCP6_MESSAGE_DHCPV4_QUERY] = "DHCPv4 Query", + [DHCP6_MESSAGE_DHCPV4_RESPONSE] = "DHCPv4 Response", + [DHCP6_MESSAGE_ACTIVE_LEASE_QUERY] = "Active Lease Query", + [DHCP6_MESSAGE_START_TLS] = "Start TLS", + [DHCP6_MESSAGE_BINDING_UPDATE] = "Binding Update", + [DHCP6_MESSAGE_BINDING_REPLY] = "Binding Reply", + [DHCP6_MESSAGE_POOL_REQUEST] = "Pool Request", + [DHCP6_MESSAGE_POOL_RESPONSE] = "Pool Response", + [DHCP6_MESSAGE_UPDATE_REQUEST] = "Update Request", + [DHCP6_MESSAGE_UPDATE_REQUEST_ALL] = "Update Request All", + [DHCP6_MESSAGE_UPDATE_DONE] = "Update Done", + [DHCP6_MESSAGE_CONNECT] = "Connect", + [DHCP6_MESSAGE_CONNECT_REPLY] = "Connect Reply", + [DHCP6_MESSAGE_DISCONNECT] = "Disconnect", + [DHCP6_MESSAGE_STATE] = "State", + [DHCP6_MESSAGE_CONTACT] = "Contact", }; DEFINE_STRING_TABLE_LOOKUP(dhcp6_message_type, int); @@ -668,7 +690,7 @@ static int client_send_message(sd_dhcp6_client *client, usec_t time_now) { switch(client->state) { case DHCP6_STATE_INFORMATION_REQUEST: - message->type = DHCP6_INFORMATION_REQUEST; + message->type = DHCP6_MESSAGE_INFORMATION_REQUEST; if (client->mudurl) { r = dhcp6_option_append(&opt, &optlen, @@ -681,7 +703,7 @@ static int client_send_message(sd_dhcp6_client *client, usec_t time_now) { break; case DHCP6_STATE_SOLICITATION: - message->type = DHCP6_SOLICIT; + message->type = DHCP6_MESSAGE_SOLICIT; r = dhcp6_option_append(&opt, &optlen, SD_DHCP6_OPTION_RAPID_COMMIT, 0, NULL); @@ -740,9 +762,9 @@ static int client_send_message(sd_dhcp6_client *client, usec_t time_now) { case DHCP6_STATE_RENEW: if (client->state == DHCP6_STATE_REQUEST) - message->type = DHCP6_REQUEST; + message->type = DHCP6_MESSAGE_REQUEST; else - message->type = DHCP6_RENEW; + message->type = DHCP6_MESSAGE_RENEW; r = dhcp6_option_append(&opt, &optlen, SD_DHCP6_OPTION_SERVERID, client->lease->serverid_len, @@ -798,7 +820,7 @@ static int client_send_message(sd_dhcp6_client *client, usec_t time_now) { break; case DHCP6_STATE_REBIND: - message->type = DHCP6_REBIND; + message->type = DHCP6_MESSAGE_REBIND; if (FLAGS_SET(client->request_ia, DHCP6_REQUEST_IA_NA)) { r = dhcp6_option_append_ia(&opt, &optlen, &client->lease->ia); @@ -1327,7 +1349,7 @@ static int client_receive_reply(sd_dhcp6_client *client, DHCP6Message *reply, si assert(client); assert(reply); - if (reply->type != DHCP6_REPLY) + if (reply->type != DHCP6_MESSAGE_REPLY) return 0; r = dhcp6_lease_new(&lease); @@ -1358,7 +1380,7 @@ static int client_receive_advertise(sd_dhcp6_client *client, DHCP6Message *adver uint8_t pref_advertise = 0, pref_lease = 0; int r; - if (advertise->type != DHCP6_ADVERTISE) + if (advertise->type != DHCP6_MESSAGE_ADVERTISE) return 0; r = dhcp6_lease_new(&lease); @@ -1430,26 +1452,12 @@ static int client_receive_message( return 0; } - switch(message->type) { - case DHCP6_SOLICIT: - case DHCP6_REQUEST: - case DHCP6_CONFIRM: - case DHCP6_RENEW: - case DHCP6_REBIND: - case DHCP6_RELEASE: - case DHCP6_DECLINE: - case DHCP6_INFORMATION_REQUEST: - case DHCP6_RELAY_FORW: - case DHCP6_RELAY_REPL: - return 0; - - case DHCP6_ADVERTISE: - case DHCP6_REPLY: - case DHCP6_RECONFIGURE: - break; - - default: - log_dhcp6_client(client, "Unknown message type %d", message->type); + if (!IN_SET(message->type, DHCP6_MESSAGE_ADVERTISE, DHCP6_MESSAGE_REPLY, DHCP6_MESSAGE_RECONFIGURE)) { + const char *type_str = dhcp6_message_type_to_string(message->type); + if (type_str) + log_dhcp6_client(client, "Received unexpected %s message, ignoring.", type_str); + else + log_dhcp6_client(client, "Received unsupported message type %u, ignoring.", message->type); return 0; } diff --git a/src/libsystemd-network/test-dhcp6-client.c b/src/libsystemd-network/test-dhcp6-client.c index b725f5c305..93d97a212b 100644 --- a/src/libsystemd-network/test-dhcp6-client.c +++ b/src/libsystemd-network/test-dhcp6-client.c @@ -450,7 +450,7 @@ static int test_advertise_option(sd_event *e) { assert_se(dhcp6_lease_new(&lease) >= 0); - assert_se(advertise->type == DHCP6_ADVERTISE); + assert_se(advertise->type == DHCP6_MESSAGE_ADVERTISE); assert_se((be32toh(advertise->transaction_id) & 0x00ffffff) == 0x0fb4e5); @@ -617,7 +617,7 @@ static int test_client_send_reply(DHCP6Message *request) { log_debug("/* %s */", __func__); reply.transaction_id = request->transaction_id; - reply.type = DHCP6_REPLY; + reply.type = DHCP6_MESSAGE_REPLY; memcpy(msg_reply, &reply.transaction_id, 4); @@ -642,7 +642,7 @@ static int test_client_verify_request(DHCP6Message *request, size_t len) { log_debug("/* %s */", __func__); - assert_se(request->type == DHCP6_REQUEST); + assert_se(request->type == DHCP6_MESSAGE_REQUEST); assert_se(dhcp6_lease_new(&lease) >= 0); len -= sizeof(DHCP6Message); @@ -725,7 +725,7 @@ static int test_client_send_advertise(DHCP6Message *solicit) { log_debug("/* %s */", __func__); advertise.transaction_id = solicit->transaction_id; - advertise.type = DHCP6_ADVERTISE; + advertise.type = DHCP6_MESSAGE_ADVERTISE; memcpy(msg_advertise, &advertise.transaction_id, 4); @@ -746,7 +746,7 @@ static int test_client_verify_solicit(DHCP6Message *solicit, size_t len) { log_debug("/* %s */", __func__); - assert_se(solicit->type == DHCP6_SOLICIT); + assert_se(solicit->type == DHCP6_MESSAGE_SOLICIT); len -= sizeof(DHCP6Message); @@ -859,7 +859,7 @@ static int test_client_verify_information_request(DHCP6Message *information_requ log_debug("/* %s */", __func__); - assert_se(information_request->type == DHCP6_INFORMATION_REQUEST); + assert_se(information_request->type == DHCP6_MESSAGE_INFORMATION_REQUEST); assert_se(dhcp6_lease_new(&lease) >= 0); len -= sizeof(DHCP6Message); diff --git a/src/network/test-network-tables.c b/src/network/test-network-tables.c index c1c26d21c5..e3e260754d 100644 --- a/src/network/test-network-tables.c +++ b/src/network/test-network-tables.c @@ -24,7 +24,7 @@ int main(int argc, char **argv) { test_table(bond_primary_reselect, NETDEV_BOND_PRIMARY_RESELECT); test_table(bond_xmit_hash_policy, NETDEV_BOND_XMIT_HASH_POLICY); test_table(dhcp6_message_status, DHCP6_STATUS); - test_table_sparse(dhcp6_message_type, DHCP6_MESSAGE); /* enum starts from 1 */ + test_table_sparse(dhcp6_message_type, DHCP6_MESSAGE_TYPE); /* enum starts from 1 */ test_table(dhcp_use_domains, DHCP_USE_DOMAINS); test_table(duplex, DUP); test_table(ip6tnl_mode, NETDEV_IP6_TNL_MODE);