Compare commits

...

3 Commits

Author SHA1 Message Date
Yu Watanabe 08c588d18b network: do not re-attach sd-event object
Fixes #15126.
2020-03-17 00:32:55 +09:00
Yu Watanabe 74f0fb9095 network: can: add support for listen-only mode
Closes #15129.
2020-03-17 00:32:35 +09:00
Susant Sahani 6cfef1b308 networkctl: Add support to display master device 2020-03-17 00:32:14 +09:00
8 changed files with 44 additions and 13 deletions

View File

@ -2317,6 +2317,16 @@
the value of a received bit by majority rule. When unset, the kernel's default will be used.</para>
</listitem>
</varlistentry>
<varlistentry>
<term><varname>ListenOnly=</varname></term>
<listitem>
<para>Takes a boolean. When <literal>yes</literal>, listen-only mode is enabled. When the
interface is in listen-only mode, the interface neither transmit CAN frames nor send ACK
bit. Listen-only mode is important to debug CAN networks without interfering with the
communication or acknowledge the CAN frame. When unset, the kernel's default will be used.
</para>
</listitem>
</varlistentry>
</variablelist>
</refsect1>

View File

@ -120,6 +120,7 @@ typedef struct LinkInfo {
unsigned short iftype;
struct ether_addr mac_address;
struct ether_addr permanent_mac_address;
uint32_t master;
uint32_t mtu;
uint32_t min_mtu;
uint32_t max_mtu;
@ -342,6 +343,8 @@ static int decode_link(sd_netlink_message *m, LinkInfo *info, char **patterns, b
return log_oom();
}
(void) sd_netlink_message_read_u32(m, IFLA_MASTER, &info->master);
/* fill kind info */
(void) decode_netdev(m, info);
@ -1354,6 +1357,15 @@ static int link_status_one(
return table_log_add_error(r);
}
if (info->master > 0) {
r = table_add_many(table,
TABLE_EMPTY,
TABLE_STRING, "Master:",
TABLE_IFINDEX, info->master);
if (r < 0)
return table_log_add_error(r);
}
if (streq_ptr(info->netdev_kind, "bridge")) {
r = table_add_many(table,
TABLE_EMPTY,

View File

@ -71,6 +71,7 @@ static int link_set_handler(sd_netlink *rtnl, sd_netlink_message *m, Link *link)
static int link_set_can(Link *link) {
_cleanup_(sd_netlink_message_unrefp) sd_netlink_message *m = NULL;
struct can_ctrlmode cm = {};
int r;
assert(link);
@ -142,13 +143,18 @@ static int link_set_can(Link *link) {
}
if (link->network->can_triple_sampling >= 0) {
struct can_ctrlmode cm = {
.mask = CAN_CTRLMODE_3_SAMPLES,
.flags = link->network->can_triple_sampling ? CAN_CTRLMODE_3_SAMPLES : 0,
};
cm.mask |= CAN_CTRLMODE_3_SAMPLES;
SET_FLAG(cm.flags, CAN_CTRLMODE_3_SAMPLES, link->network->can_triple_sampling);
log_link_debug(link, "%sabling triple-sampling", link->network->can_triple_sampling ? "En" : "Dis");
}
if (link->network->can_listen_only >= 0) {
cm.mask |= CAN_CTRLMODE_LISTENONLY;
SET_FLAG(cm.flags, CAN_CTRLMODE_LISTENONLY, link->network->can_listen_only);
log_link_debug(link, "%sabling listen-only mode", link->network->can_listen_only ? "En" : "Dis");
}
if (cm.mask != 0) {
r = sd_netlink_message_append_data(m, IFLA_CAN_CTRLMODE, &cm, sizeof(cm));
if (r < 0)
return log_link_error_errno(link, r, "Could not append IFLA_CAN_CTRLMODE attribute: %m");

View File

@ -1334,11 +1334,11 @@ int dhcp4_configure(Link *link) {
return log_oom();
if (r < 0)
return log_link_error_errno(link, r, "DHCP4 CLIENT: Failed to create DHCP4 client: %m");
}
r = sd_dhcp_client_attach_event(link->dhcp_client, NULL, 0);
if (r < 0)
return log_link_error_errno(link, r, "DHCP4 CLIENT: Failed to attach event: %m");
r = sd_dhcp_client_attach_event(link->dhcp_client, NULL, 0);
if (r < 0)
return log_link_error_errno(link, r, "DHCP4 CLIENT: Failed to attach event: %m");
}
r = sd_dhcp_client_set_mac(link->dhcp_client,
(const uint8_t *) &link->mac,

View File

@ -154,6 +154,10 @@ int ipv4ll_configure(Link *link) {
r = sd_ipv4ll_new(&link->ipv4ll);
if (r < 0)
return r;
r = sd_ipv4ll_attach_event(link->ipv4ll, NULL, 0);
if (r < 0)
return r;
}
if (link->sd_device &&
@ -163,10 +167,6 @@ int ipv4ll_configure(Link *link) {
return r;
}
r = sd_ipv4ll_attach_event(link->ipv4ll, NULL, 0);
if (r < 0)
return r;
r = sd_ipv4ll_set_mac(link->ipv4ll, &link->mac);
if (r < 0)
return r;

View File

@ -256,6 +256,7 @@ CAN.SamplePoint, config_parse_permille,
CAN.RestartSec, config_parse_sec, 0, offsetof(Network, can_restart_us)
CAN.TripleSampling, config_parse_tristate, 0, offsetof(Network, can_triple_sampling)
CAN.Termination, config_parse_tristate, 0, offsetof(Network, can_termination)
CAN.ListenOnly, config_parse_tristate, 0, offsetof(Network, can_listen_only)
QDisc.Parent, config_parse_qdisc_parent, _QDISC_KIND_INVALID, 0
QDisc.Handle, config_parse_qdisc_handle, _QDISC_KIND_INVALID, 0
BFIFO.Parent, config_parse_qdisc_parent, QDISC_KIND_BFIFO, 0

View File

@ -200,6 +200,7 @@ struct Network {
usec_t can_restart_us;
int can_triple_sampling;
int can_termination;
int can_listen_only;
AddressFamily ip_forward;
bool ip_masquerade;

View File

@ -201,6 +201,7 @@ BitRate=
RestartSec=
TripleSampling=
Termination=
ListenOnly=
[Address]
DuplicateAddressDetection=
AutoJoin=