Commit 1355fe13 authored by Jakub Kicinski's avatar Jakub Kicinski

Merge branch 'tools-ynl-handful-of-forward-looking-updates'

Jakub Kicinski says:

====================
tools: ynl: handful of forward looking updates

Small YNL improvements, mostly for work-in-progress families.
====================

Link: https://lore.kernel.org/r/20230824003056.1436637-1-kuba@kernel.orgSigned-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parents 10ea77e4 e83d4e9b
...@@ -107,16 +107,16 @@ operations: ...@@ -107,16 +107,16 @@ operations:
flags: [ admin-perm ] flags: [ admin-perm ]
do: do:
request: &select_attrs request: &select_attrs
attributes: attributes:
- af - af
- ifindex - ifindex
- port - port
- peer_port - peer_port
- local_v4 - local_v4
- peer_v4 - peer_v4
- local_v6 - local_v6
- peer_v6 - peer_v6
- -
name: get name: get
......
...@@ -1422,6 +1422,7 @@ ethtool_wol_set_req_set_sopass(struct ethtool_wol_set_req *req, ...@@ -1422,6 +1422,7 @@ ethtool_wol_set_req_set_sopass(struct ethtool_wol_set_req *req,
const void *sopass, size_t len) const void *sopass, size_t len)
{ {
free(req->sopass); free(req->sopass);
req->_present.sopass_len = len;
req->sopass = malloc(req->_present.sopass_len); req->sopass = malloc(req->_present.sopass_len);
memcpy(req->sopass, sopass, req->_present.sopass_len); memcpy(req->sopass, sopass, req->_present.sopass_len);
} }
...@@ -4071,6 +4072,7 @@ ethtool_fec_set_req_set_stats_corrected(struct ethtool_fec_set_req *req, ...@@ -4071,6 +4072,7 @@ ethtool_fec_set_req_set_stats_corrected(struct ethtool_fec_set_req *req,
const void *corrected, size_t len) const void *corrected, size_t len)
{ {
free(req->stats.corrected); free(req->stats.corrected);
req->stats._present.corrected_len = len;
req->stats.corrected = malloc(req->stats._present.corrected_len); req->stats.corrected = malloc(req->stats._present.corrected_len);
memcpy(req->stats.corrected, corrected, req->stats._present.corrected_len); memcpy(req->stats.corrected, corrected, req->stats._present.corrected_len);
} }
...@@ -4079,6 +4081,7 @@ ethtool_fec_set_req_set_stats_uncorr(struct ethtool_fec_set_req *req, ...@@ -4079,6 +4081,7 @@ ethtool_fec_set_req_set_stats_uncorr(struct ethtool_fec_set_req *req,
const void *uncorr, size_t len) const void *uncorr, size_t len)
{ {
free(req->stats.uncorr); free(req->stats.uncorr);
req->stats._present.uncorr_len = len;
req->stats.uncorr = malloc(req->stats._present.uncorr_len); req->stats.uncorr = malloc(req->stats._present.uncorr_len);
memcpy(req->stats.uncorr, uncorr, req->stats._present.uncorr_len); memcpy(req->stats.uncorr, uncorr, req->stats._present.uncorr_len);
} }
...@@ -4087,6 +4090,7 @@ ethtool_fec_set_req_set_stats_corr_bits(struct ethtool_fec_set_req *req, ...@@ -4087,6 +4090,7 @@ ethtool_fec_set_req_set_stats_corr_bits(struct ethtool_fec_set_req *req,
const void *corr_bits, size_t len) const void *corr_bits, size_t len)
{ {
free(req->stats.corr_bits); free(req->stats.corr_bits);
req->stats._present.corr_bits_len = len;
req->stats.corr_bits = malloc(req->stats._present.corr_bits_len); req->stats.corr_bits = malloc(req->stats._present.corr_bits_len);
memcpy(req->stats.corr_bits, corr_bits, req->stats._present.corr_bits_len); memcpy(req->stats.corr_bits, corr_bits, req->stats._present.corr_bits_len);
} }
......
...@@ -91,6 +91,7 @@ fou_add_req_set_local_v6(struct fou_add_req *req, const void *local_v6, ...@@ -91,6 +91,7 @@ fou_add_req_set_local_v6(struct fou_add_req *req, const void *local_v6,
size_t len) size_t len)
{ {
free(req->local_v6); free(req->local_v6);
req->_present.local_v6_len = len;
req->local_v6 = malloc(req->_present.local_v6_len); req->local_v6 = malloc(req->_present.local_v6_len);
memcpy(req->local_v6, local_v6, req->_present.local_v6_len); memcpy(req->local_v6, local_v6, req->_present.local_v6_len);
} }
...@@ -99,6 +100,7 @@ fou_add_req_set_peer_v6(struct fou_add_req *req, const void *peer_v6, ...@@ -99,6 +100,7 @@ fou_add_req_set_peer_v6(struct fou_add_req *req, const void *peer_v6,
size_t len) size_t len)
{ {
free(req->peer_v6); free(req->peer_v6);
req->_present.peer_v6_len = len;
req->peer_v6 = malloc(req->_present.peer_v6_len); req->peer_v6 = malloc(req->_present.peer_v6_len);
memcpy(req->peer_v6, peer_v6, req->_present.peer_v6_len); memcpy(req->peer_v6, peer_v6, req->_present.peer_v6_len);
} }
...@@ -192,6 +194,7 @@ fou_del_req_set_local_v6(struct fou_del_req *req, const void *local_v6, ...@@ -192,6 +194,7 @@ fou_del_req_set_local_v6(struct fou_del_req *req, const void *local_v6,
size_t len) size_t len)
{ {
free(req->local_v6); free(req->local_v6);
req->_present.local_v6_len = len;
req->local_v6 = malloc(req->_present.local_v6_len); req->local_v6 = malloc(req->_present.local_v6_len);
memcpy(req->local_v6, local_v6, req->_present.local_v6_len); memcpy(req->local_v6, local_v6, req->_present.local_v6_len);
} }
...@@ -200,6 +203,7 @@ fou_del_req_set_peer_v6(struct fou_del_req *req, const void *peer_v6, ...@@ -200,6 +203,7 @@ fou_del_req_set_peer_v6(struct fou_del_req *req, const void *peer_v6,
size_t len) size_t len)
{ {
free(req->peer_v6); free(req->peer_v6);
req->_present.peer_v6_len = len;
req->peer_v6 = malloc(req->_present.peer_v6_len); req->peer_v6 = malloc(req->_present.peer_v6_len);
memcpy(req->peer_v6, peer_v6, req->_present.peer_v6_len); memcpy(req->peer_v6, peer_v6, req->_present.peer_v6_len);
} }
...@@ -280,6 +284,7 @@ fou_get_req_set_local_v6(struct fou_get_req *req, const void *local_v6, ...@@ -280,6 +284,7 @@ fou_get_req_set_local_v6(struct fou_get_req *req, const void *local_v6,
size_t len) size_t len)
{ {
free(req->local_v6); free(req->local_v6);
req->_present.local_v6_len = len;
req->local_v6 = malloc(req->_present.local_v6_len); req->local_v6 = malloc(req->_present.local_v6_len);
memcpy(req->local_v6, local_v6, req->_present.local_v6_len); memcpy(req->local_v6, local_v6, req->_present.local_v6_len);
} }
...@@ -288,6 +293,7 @@ fou_get_req_set_peer_v6(struct fou_get_req *req, const void *peer_v6, ...@@ -288,6 +293,7 @@ fou_get_req_set_peer_v6(struct fou_get_req *req, const void *peer_v6,
size_t len) size_t len)
{ {
free(req->peer_v6); free(req->peer_v6);
req->_present.peer_v6_len = len;
req->peer_v6 = malloc(req->_present.peer_v6_len); req->peer_v6 = malloc(req->_present.peer_v6_len);
memcpy(req->peer_v6, peer_v6, req->_present.peer_v6_len); memcpy(req->peer_v6, peer_v6, req->_present.peer_v6_len);
} }
......
...@@ -410,7 +410,12 @@ class YnlFamily(SpecFamily): ...@@ -410,7 +410,12 @@ class YnlFamily(SpecFamily):
elif attr["type"] == 'string': elif attr["type"] == 'string':
attr_payload = str(value).encode('ascii') + b'\x00' attr_payload = str(value).encode('ascii') + b'\x00'
elif attr["type"] == 'binary': elif attr["type"] == 'binary':
attr_payload = bytes.fromhex(value) if isinstance(value, bytes):
attr_payload = value
elif isinstance(value, str):
attr_payload = bytes.fromhex(value)
else:
raise Exception(f'Unknown type for binary attribute, value: {value}')
elif attr['type'] in NlAttr.type_formats: elif attr['type'] in NlAttr.type_formats:
format = NlAttr.get_format(attr['type'], attr.byte_order) format = NlAttr.get_format(attr['type'], attr.byte_order)
attr_payload = format.pack(int(value)) attr_payload = format.pack(int(value))
......
...@@ -428,6 +428,7 @@ class TypeBinary(Type): ...@@ -428,6 +428,7 @@ class TypeBinary(Type):
def _setter_lines(self, ri, member, presence): def _setter_lines(self, ri, member, presence):
return [f"free({member});", return [f"free({member});",
f"{presence}_len = len;",
f"{member} = malloc({presence}_len);", f"{member} = malloc({presence}_len);",
f'memcpy({member}, {self.c_name}, {presence}_len);'] f'memcpy({member}, {self.c_name}, {presence}_len);']
...@@ -614,7 +615,7 @@ class Struct: ...@@ -614,7 +615,7 @@ class Struct:
self.attr_list = [] self.attr_list = []
self.attrs = dict() self.attrs = dict()
if type_list: if type_list is not None:
for t in type_list: for t in type_list:
self.attr_list.append((t, self.attr_set[t]),) self.attr_list.append((t, self.attr_set[t]),)
else: else:
...@@ -977,7 +978,9 @@ class Family(SpecFamily): ...@@ -977,7 +978,9 @@ class Family(SpecFamily):
for op_mode in ['do', 'dump']: for op_mode in ['do', 'dump']:
if op_mode in op: if op_mode in op:
global_set.update(op[op_mode].get('request', [])) req = op[op_mode].get('request')
if req:
global_set.update(req.get('attributes', []))
self.global_policy = [] self.global_policy = []
self.global_policy_set = attr_set_name self.global_policy_set = attr_set_name
...@@ -1540,7 +1543,14 @@ def parse_rsp_msg(ri, deref=False): ...@@ -1540,7 +1543,14 @@ def parse_rsp_msg(ri, deref=False):
ri.cw.write_func_prot('int', f'{op_prefix(ri, "reply", deref=deref)}_parse', func_args) ri.cw.write_func_prot('int', f'{op_prefix(ri, "reply", deref=deref)}_parse', func_args)
_multi_parse(ri, ri.struct["reply"], init_lines, local_vars) if ri.struct["reply"].member_list():
_multi_parse(ri, ri.struct["reply"], init_lines, local_vars)
else:
# Empty reply
ri.cw.block_start()
ri.cw.p('return MNL_CB_OK;')
ri.cw.block_end()
ri.cw.nl()
def print_req(ri): def print_req(ri):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment