1
0
mirror of https://github.com/systemd/systemd.git synced 2025-01-12 13:18:14 +03:00

network: reject bridge port priorities above kernel's max value. (#5877)

Bridge port priority in the kernel can only be between 0 and 63. Therefore
reject values above maximum.

Fixes: #5729
This commit is contained in:
Dimitri John Ledkov 2017-05-02 20:32:42 +01:00 committed by Zbigniew Jędrzejewski-Szmek
parent b7674ecd5b
commit f00ff0de40
4 changed files with 47 additions and 3 deletions

View File

@ -349,6 +349,45 @@ int config_parse_iaid(const char *unit,
return 0;
}
int config_parse_bridge_port_priority(
const char *unit,
const char *filename,
unsigned line,
const char *section,
unsigned section_line,
const char *lvalue,
int ltype,
const char *rvalue,
void *data,
void *userdata) {
uint16_t i;
int r;
assert(filename);
assert(lvalue);
assert(rvalue);
assert(data);
r = safe_atou16(rvalue, &i);
if (r < 0) {
log_syntax(unit, LOG_ERR, filename, line, r,
"Failed to parse bridge port priority, ignoring: %s", rvalue);
return 0;
}
if (i > LINK_BRIDGE_PORT_PRIORITY_MAX) {
log_syntax(unit, LOG_ERR, filename, line, r,
"Bridge port priority is larger than maximum %u, ignoring: %s", LINK_BRIDGE_PORT_PRIORITY_MAX, rvalue);
return 0;
}
*((uint16_t *)data) = i;
return 0;
}
void serialize_in_addrs(FILE *f, const struct in_addr *addresses, size_t size) {
unsigned i;

View File

@ -26,6 +26,9 @@
#include "condition.h"
#include "udev.h"
#define LINK_BRIDGE_PORT_PRIORITY_INVALID 128
#define LINK_BRIDGE_PORT_PRIORITY_MAX 63
bool net_match_config(const struct ether_addr *match_mac,
char * const *match_path,
char * const *match_driver,
@ -62,6 +65,10 @@ int config_parse_iaid(const char *unit, const char *filename, unsigned line,
const char *section, unsigned section_line, const char *lvalue,
int ltype, const char *rvalue, void *data, void *userdata);
int config_parse_bridge_port_priority(const char *unit, const char *filename, unsigned line,
const char *section, unsigned section_line, const char *lvalue,
int ltype, const char *rvalue, void *data, void *userdata);
int net_get_unique_predictable_data(struct udev_device *device, uint64_t *result);
const char *net_get_name(struct udev_device *device);

View File

@ -33,8 +33,6 @@
#include "list.h"
#include "set.h"
#define LINK_BRIDGE_PORT_PRIORITY_INVALID 128
typedef enum LinkState {
LINK_STATE_PENDING,
LINK_STATE_ENSLAVING,

View File

@ -129,7 +129,7 @@ Bridge.HairPin, config_parse_bool,
Bridge.FastLeave, config_parse_bool, 0, offsetof(Network, fast_leave)
Bridge.AllowPortToBeRoot, config_parse_bool, 0, offsetof(Network, allow_port_to_be_root)
Bridge.UnicastFlood, config_parse_bool, 0, offsetof(Network, unicast_flood)
Bridge.Priority, config_parse_uint16, 0, offsetof(Network, priority)
Bridge.Priority, config_parse_bridge_port_priority, 0, offsetof(Network, priority)
BridgeFDB.MACAddress, config_parse_fdb_hwaddr, 0, 0
BridgeFDB.VLANId, config_parse_fdb_vlan_id, 0, 0
BridgeVLAN.PVID, config_parse_brvlan_pvid, 0, 0