Skip to content

Commit

Permalink
Merge pull request #20802 from yuwata/network-receive-nl80211-multica…
Browse files Browse the repository at this point in the history
…st-messages

network: receive nl80211 multicast messages
  • Loading branch information
yuwata committed Sep 29, 2021
2 parents c103604 + 96f5f9e commit 92fc611
Show file tree
Hide file tree
Showing 22 changed files with 793 additions and 237 deletions.
43 changes: 43 additions & 0 deletions src/basic/linux/nl80211.h
Original file line number Diff line number Diff line change
Expand Up @@ -1185,6 +1185,21 @@
* passed using %NL80211_ATTR_SAR_SPEC. %NL80211_ATTR_WIPHY is used to
* specify the wiphy index to be applied to.
*
* @NL80211_CMD_OBSS_COLOR_COLLISION: This notification is sent out whenever
* mac80211/drv detects a bss color collision.
*
* @NL80211_CMD_COLOR_CHANGE_REQUEST: This command is used to indicate that
* userspace wants to change the BSS color.
*
* @NL80211_CMD_COLOR_CHANGE_STARTED: Notify userland, that a color change has
* started
*
* @NL80211_CMD_COLOR_CHANGE_ABORTED: Notify userland, that the color change has
* been aborted
*
* @NL80211_CMD_COLOR_CHANGE_COMPLETED: Notify userland that the color change
* has completed
*
* @NL80211_CMD_MAX: highest used command number
* @__NL80211_CMD_AFTER_LAST: internal use
*/
Expand Down Expand Up @@ -1417,6 +1432,14 @@ enum nl80211_commands {

NL80211_CMD_SET_SAR_SPECS,

NL80211_CMD_OBSS_COLOR_COLLISION,

NL80211_CMD_COLOR_CHANGE_REQUEST,

NL80211_CMD_COLOR_CHANGE_STARTED,
NL80211_CMD_COLOR_CHANGE_ABORTED,
NL80211_CMD_COLOR_CHANGE_COMPLETED,

/* add new commands above here */

/* used to define NL80211_CMD_MAX below */
Expand Down Expand Up @@ -2560,6 +2583,16 @@ enum nl80211_commands {
* disassoc events to indicate that an immediate reconnect to the AP
* is desired.
*
* @NL80211_ATTR_OBSS_COLOR_BITMAP: bitmap of the u64 BSS colors for the
* %NL80211_CMD_OBSS_COLOR_COLLISION event.
*
* @NL80211_ATTR_COLOR_CHANGE_COUNT: u8 attribute specifying the number of TBTT's
* until the color switch event.
* @NL80211_ATTR_COLOR_CHANGE_COLOR: u8 attribute specifying the color that we are
* switching to
* @NL80211_ATTR_COLOR_CHANGE_ELEMS: Nested set of attributes containing the IE
* information for the time while performing a color switch.
*
* @NUM_NL80211_ATTR: total number of nl80211_attrs available
* @NL80211_ATTR_MAX: highest attribute number currently defined
* @__NL80211_ATTR_AFTER_LAST: internal use
Expand Down Expand Up @@ -3057,6 +3090,12 @@ enum nl80211_attrs {

NL80211_ATTR_DISABLE_HE,

NL80211_ATTR_OBSS_COLOR_BITMAP,

NL80211_ATTR_COLOR_CHANGE_COUNT,
NL80211_ATTR_COLOR_CHANGE_COLOR,
NL80211_ATTR_COLOR_CHANGE_ELEMS,

/* add attributes here, update the policy in nl80211.c */

__NL80211_ATTR_AFTER_LAST,
Expand Down Expand Up @@ -5953,6 +5992,9 @@ enum nl80211_feature_flags {
* frame protection for all management frames exchanged during the
* negotiation and range measurement procedure.
*
* @NL80211_EXT_FEATURE_BSS_COLOR: The driver supports BSS color collision
* detection and change announcemnts.
*
* @NUM_NL80211_EXT_FEATURES: number of extended features.
* @MAX_NL80211_EXT_FEATURES: highest extended feature index.
*/
Expand Down Expand Up @@ -6017,6 +6059,7 @@ enum nl80211_ext_feature_index {
NL80211_EXT_FEATURE_SECURE_LTF,
NL80211_EXT_FEATURE_SECURE_RTT,
NL80211_EXT_FEATURE_PROT_RANGE_NEGO_AND_MEASURE,
NL80211_EXT_FEATURE_BSS_COLOR,

/* add new features before the definition below */
NUM_NL80211_EXT_FEATURES,
Expand Down
5 changes: 5 additions & 0 deletions src/basic/missing_network.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,8 @@
#ifndef BOND_MAX_ARP_TARGETS
#define BOND_MAX_ARP_TARGETS 16
#endif

/* Not exposed but defined in include/linux/ieee80211.h */
#ifndef IEEE80211_MAX_SSID_LEN
#define IEEE80211_MAX_SSID_LEN 32
#endif
65 changes: 40 additions & 25 deletions src/libsystemd/sd-netlink/netlink-genl.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,42 @@ void genl_clear_family(sd_netlink *nl) {
nl->genl_family_by_id = hashmap_free_with_destructor(nl->genl_family_by_id, genl_family_free);
}

static int genl_family_new_unsupported(
sd_netlink *nl,
const char *family_name,
const NLTypeSystem *type_system) {

_cleanup_(genl_family_freep) GenericNetlinkFamily *f = NULL;
int r;

assert(nl);
assert(family_name);
assert(type_system);

/* Kernel does not support the genl family? To prevent from resolving the family name again,
* let's store the family with zero id to indicate that. */

f = new(GenericNetlinkFamily, 1);
if (!f)
return -ENOMEM;

*f = (GenericNetlinkFamily) {
.type_system = type_system,
};

f->name = strdup(family_name);
if (!f->name)
return -ENOMEM;

r = hashmap_ensure_put(&nl->genl_family_by_name, &string_hash_ops, f->name, f);
if (r < 0)
return r;

f->genl = nl;
TAKE_PTR(f);
return 0;
}

static int genl_family_new(
sd_netlink *nl,
const char *expected_family_name,
Expand All @@ -79,28 +115,6 @@ static int genl_family_new(
.type_system = type_system,
};

if (sd_netlink_message_is_error(message)) {
int e;

/* Kernel does not support the genl family? To prevent from resolving the family name
* again, let's store the family with zero id to indicate that. */

e = sd_netlink_message_get_errno(message);
if (e >= 0) /* Huh? */
e = -EOPNOTSUPP;

f->name = strdup(expected_family_name);
if (!f->name)
return e;

if (hashmap_ensure_put(&nl->genl_family_by_name, &string_hash_ops, f->name, f) < 0)
return e;

f->genl = nl;
TAKE_PTR(f);
return e;
}

r = sd_genl_message_get_family_name(nl, message, &family_name);
if (r < 0)
return r;
Expand Down Expand Up @@ -261,9 +275,10 @@ static int genl_family_get_by_name_internal(
if (r < 0)
return r;

r = sd_netlink_call(nl, req, 0, &reply);
if (r < 0)
return r;
if (sd_netlink_call(nl, req, 0, &reply) < 0) {
(void) genl_family_new_unsupported(nl, name, type_system);
return -EOPNOTSUPP;
}

return genl_family_new(nl, name, type_system, reply, ret);
}
Expand Down
2 changes: 1 addition & 1 deletion src/libsystemd/sd-netlink/netlink-internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,8 @@ struct sd_netlink_message {
struct nlmsghdr *hdr;
struct netlink_container containers[NETLINK_CONTAINER_DEPTH];
unsigned n_containers; /* number of containers */
uint32_t multicast_group;
bool sealed:1;
bool broadcast:1;

sd_netlink_message *next; /* next in a chain of multi-part messages */
};
Expand Down

0 comments on commit 92fc611

Please sign in to comment.