The xfrm commands open their own NETLINK_XFRM handle in a local named rth, shadowing the global rth declared in ip_common.h. Rename the locals to xrth. xfrm_state_keep() and xfrm_policy_keep() aliased xb->rth into a local rth used once; drop the alias and dereference xb->rth directly. Signed-off-by: Stephen Hemminger <step…@networkplumber.org> --- ip/xfrm_policy.c | 81 ++++++++++++++++++++++++------------------------ ip/xfrm_state.c | 69 ++++++++++++++++++++--------------------- 2 files changed, 74 insertions(+), 76 deletions(-) diff --git a/ip/xfrm_policy.c b/ip/xfrm_policy.c index 5261a292..ea7e8c0c 100644 --- a/ip/xfrm_policy.c +++ b/ip/xfrm_policy.c @@ -227,7 +227,7 @@ int xfrm_sctx_parse(char *ctxstr, char *s, static int xfrm_policy_modify(int cmd, unsigned int flags, int argc, char **argv) { - struct rtnl_handle rth; + struct rtnl_handle xrth; struct { struct nlmsghdr n; struct xfrm_userpolicy_info xpinfo; @@ -399,16 +399,16 @@ static int xfrm_policy_modify(int cmd, unsigned int flags, int argc, char **argv sizeof(xuo)); } - if (rtnl_open_byproto(&rth, 0, NETLINK_XFRM) < 0) + if (rtnl_open_byproto(&xrth, 0, NETLINK_XFRM) < 0) exit(1); if (req.xpinfo.sel.family == AF_UNSPEC) req.xpinfo.sel.family = AF_INET; - if (rtnl_talk(&rth, &req.n, NULL) < 0) + if (rtnl_talk(&xrth, &req.n, NULL) < 0) exit(2); - rtnl_close(&rth); + rtnl_close(&xrth); return 0; } @@ -574,7 +574,7 @@ int xfrm_policy_print(struct nlmsghdr *n, void *arg) static int xfrm_policy_get_or_delete(int argc, char **argv, int delete, struct nlmsghdr **answer) { - struct rtnl_handle rth; + struct rtnl_handle xrth; struct { struct nlmsghdr n; struct xfrm_userpolicy_id xpid; @@ -669,7 +669,7 @@ static int xfrm_policy_get_or_delete(int argc, char **argv, int delete, if (selp && indexp) duparg2("SELECTOR", "INDEX"); - if (rtnl_open_byproto(&rth, 0, NETLINK_XFRM) < 0) + if (rtnl_open_byproto(&xrth, 0, NETLINK_XFRM) < 0) exit(1); if (req.xpid.sel.family == AF_UNSPEC) @@ -692,10 +692,10 @@ static int xfrm_policy_get_or_delete(int argc, char **argv, int delete, if (is_if_id_set) addattr32(&req.n, sizeof(req.buf), XFRMA_IF_ID, if_id); - if (rtnl_talk(&rth, &req.n, answer) < 0) + if (rtnl_talk(&xrth, &req.n, answer) < 0) exit(2); - rtnl_close(&rth); + rtnl_close(&xrth); return 0; } @@ -727,7 +727,6 @@ static int xfrm_policy_get(int argc, char **argv) static int xfrm_policy_keep(struct nlmsghdr *n, void *arg) { struct xfrm_buffer *xb = (struct xfrm_buffer *)arg; - struct rtnl_handle *rth = xb->rth; struct xfrm_userpolicy_info *xpinfo = NLMSG_DATA(n); int len = n->nlmsg_len; struct rtattr *tb[XFRMA_MAX+1]; @@ -774,7 +773,7 @@ static int xfrm_policy_keep(struct nlmsghdr *n, void *arg) new_n->nlmsg_len = NLMSG_LENGTH(sizeof(*xpid)); new_n->nlmsg_flags = NLM_F_REQUEST; new_n->nlmsg_type = XFRM_MSG_DELPOLICY; - new_n->nlmsg_seq = ++rth->seq; + new_n->nlmsg_seq = ++xb->rth->seq; xpid = NLMSG_DATA(new_n); memcpy(&xpid->sel, &xpinfo->sel, sizeof(xpid->sel)); @@ -804,7 +803,7 @@ static int xfrm_policy_keep(struct nlmsghdr *n, void *arg) static int xfrm_policy_list_or_deleteall(int argc, char **argv, int deleteall) { char *selp = NULL; - struct rtnl_handle rth; + struct rtnl_handle xrth; if (argc > 0 || preferred_family != AF_UNSPEC) filter.use = 1; @@ -872,7 +871,7 @@ static int xfrm_policy_list_or_deleteall(int argc, char **argv, int deleteall) argc--; argv++; } - if (rtnl_open_byproto(&rth, 0, NETLINK_XFRM) < 0) + if (rtnl_open_byproto(&xrth, 0, NETLINK_XFRM) < 0) exit(1); if (deleteall) { @@ -882,7 +881,7 @@ static int xfrm_policy_list_or_deleteall(int argc, char **argv, int deleteall) xb.buf = buf; xb.size = sizeof(buf); - xb.rth = &rth; + xb.rth = &xrth; for (i = 0; ; i++) { struct { @@ -892,7 +891,7 @@ static int xfrm_policy_list_or_deleteall(int argc, char **argv, int deleteall) .n.nlmsg_len = NLMSG_HDRLEN, .n.nlmsg_flags = NLM_F_DUMP | NLM_F_REQUEST, .n.nlmsg_type = XFRM_MSG_GETPOLICY, - .n.nlmsg_seq = rth.dump = ++rth.seq, + .n.nlmsg_seq = xrth.dump = ++xrth.seq, }; xb.offset = 0; @@ -901,12 +900,12 @@ static int xfrm_policy_list_or_deleteall(int argc, char **argv, int deleteall) if (show_stats > 1) fprintf(stderr, "Delete-all round = %d\n", i); - if (rtnl_send(&rth, (void *)&req, req.n.nlmsg_len) < 0) { + if (rtnl_send(&xrth, (void *)&req, req.n.nlmsg_len) < 0) { perror("Cannot send dump request"); exit(1); } - if (rtnl_dump_filter(&rth, xfrm_policy_keep, &xb) < 0) { + if (rtnl_dump_filter(&xrth, xfrm_policy_keep, &xb) < 0) { fprintf(stderr, "Delete-all terminated\n"); exit(1); } @@ -916,7 +915,7 @@ static int xfrm_policy_list_or_deleteall(int argc, char **argv, int deleteall) break; } - if (rtnl_send_check(&rth, xb.buf, xb.offset) < 0) { + if (rtnl_send_check(&xrth, xb.buf, xb.offset) < 0) { perror("Failed to send delete-all request"); exit(1); } @@ -934,21 +933,21 @@ static int xfrm_policy_list_or_deleteall(int argc, char **argv, int deleteall) .n.nlmsg_len = NLMSG_HDRLEN, .n.nlmsg_flags = NLM_F_DUMP | NLM_F_REQUEST, .n.nlmsg_type = XFRM_MSG_GETPOLICY, - .n.nlmsg_seq = rth.dump = ++rth.seq, + .n.nlmsg_seq = xrth.dump = ++xrth.seq, }; - if (rtnl_send(&rth, (void *)&req, req.n.nlmsg_len) < 0) { + if (rtnl_send(&xrth, (void *)&req, req.n.nlmsg_len) < 0) { perror("Cannot send dump request"); exit(1); } - if (rtnl_dump_filter(&rth, xfrm_policy_print, stdout) < 0) { + if (rtnl_dump_filter(&xrth, xfrm_policy_print, stdout) < 0) { fprintf(stderr, "Dump terminated\n"); exit(1); } } - rtnl_close(&rth); + rtnl_close(&xrth); exit(0); } @@ -1045,7 +1044,7 @@ static int print_spdinfo(struct nlmsghdr *n, void *arg) static int xfrm_spd_setinfo(int argc, char **argv) { - struct rtnl_handle rth; + struct rtnl_handle xrth; struct { struct nlmsghdr n; __u32 flags; @@ -1098,20 +1097,20 @@ static int xfrm_spd_setinfo(int argc, char **argv) argc--; argv++; } - if (rtnl_open_byproto(&rth, 0, NETLINK_XFRM) < 0) + if (rtnl_open_byproto(&xrth, 0, NETLINK_XFRM) < 0) exit(1); - if (rtnl_talk(&rth, &req.n, NULL) < 0) + if (rtnl_talk(&xrth, &req.n, NULL) < 0) exit(2); - rtnl_close(&rth); + rtnl_close(&xrth); return 0; } static int xfrm_spd_getinfo(int argc, char **argv) { - struct rtnl_handle rth; + struct rtnl_handle xrth; struct { struct nlmsghdr n; __u32 flags; @@ -1123,16 +1122,16 @@ static int xfrm_spd_getinfo(int argc, char **argv) }; struct nlmsghdr *answer; - if (rtnl_open_byproto(&rth, 0, NETLINK_XFRM) < 0) + if (rtnl_open_byproto(&xrth, 0, NETLINK_XFRM) < 0) exit(1); - if (rtnl_talk(&rth, &req.n, &answer) < 0) + if (rtnl_talk(&xrth, &req.n, &answer) < 0) exit(2); print_spdinfo(answer, (void *)stdout); free(answer); - rtnl_close(&rth); + rtnl_close(&xrth); return 0; } @@ -1167,7 +1166,7 @@ static char *xfrm_policy_to_str(uint8_t policy) static int xfrm_spd_setdefault(int argc, char **argv) { - struct rtnl_handle rth; + struct rtnl_handle xrth; struct { struct nlmsghdr n; struct xfrm_userpolicy_default up; @@ -1206,13 +1205,13 @@ static int xfrm_spd_setdefault(int argc, char **argv) argc--; argv++; } - if (rtnl_open_byproto(&rth, 0, NETLINK_XFRM) < 0) + if (rtnl_open_byproto(&xrth, 0, NETLINK_XFRM) < 0) exit(1); - if (rtnl_talk(&rth, &req.n, NULL) < 0) + if (rtnl_talk(&xrth, &req.n, NULL) < 0) exit(2); - rtnl_close(&rth); + rtnl_close(&xrth); return 0; } @@ -1239,7 +1238,7 @@ int xfrm_policy_default_print(struct nlmsghdr *n, FILE *fp) static int xfrm_spd_getdefault(int argc, char **argv) { - struct rtnl_handle rth; + struct rtnl_handle xrth; struct { struct nlmsghdr n; struct xfrm_userpolicy_default up; @@ -1250,23 +1249,23 @@ static int xfrm_spd_getdefault(int argc, char **argv) }; struct nlmsghdr *answer; - if (rtnl_open_byproto(&rth, 0, NETLINK_XFRM) < 0) + if (rtnl_open_byproto(&xrth, 0, NETLINK_XFRM) < 0) exit(1); - if (rtnl_talk(&rth, &req.n, &answer) < 0) + if (rtnl_talk(&xrth, &req.n, &answer) < 0) exit(2); xfrm_policy_default_print(answer, (FILE *)stdout); free(answer); - rtnl_close(&rth); + rtnl_close(&xrth); return 0; } static int xfrm_policy_flush(int argc, char **argv) { - struct rtnl_handle rth; + struct rtnl_handle xrth; struct { struct nlmsghdr n; char buf[RTA_BUF_SIZE]; @@ -1297,16 +1296,16 @@ static int xfrm_policy_flush(int argc, char **argv) (void *)&upt, sizeof(upt)); } - if (rtnl_open_byproto(&rth, 0, NETLINK_XFRM) < 0) + if (rtnl_open_byproto(&xrth, 0, NETLINK_XFRM) < 0) exit(1); if (show_stats > 1) fprintf(stderr, "Flush policy\n"); - if (rtnl_talk(&rth, &req.n, NULL) < 0) + if (rtnl_talk(&xrth, &req.n, NULL) < 0) exit(2); - rtnl_close(&rth); + rtnl_close(&xrth); return 0; } diff --git a/ip/xfrm_state.c b/ip/xfrm_state.c index dcd08d59..db80a0e0 100644 --- a/ip/xfrm_state.c +++ b/ip/xfrm_state.c @@ -269,7 +269,7 @@ static void xfrm_dir_parse(__u8 *dir, int *argcp, char ***argvp) static int xfrm_state_modify(int cmd, unsigned int flags, int argc, char **argv) { - struct rtnl_handle rth; + struct rtnl_handle xrth; struct { struct nlmsghdr n; struct xfrm_usersa_info xsinfo; @@ -761,7 +761,7 @@ static int xfrm_state_modify(int cmd, unsigned int flags, int argc, char **argv) if (output_mark.m) addattr32(&req.n, sizeof(req.buf), XFRMA_SET_MARK_MASK, output_mark.m); - if (rtnl_open_byproto(&rth, 0, NETLINK_XFRM) < 0) + if (rtnl_open_byproto(&xrth, 0, NETLINK_XFRM) < 0) exit(1); if (dir) { @@ -778,17 +778,17 @@ static int xfrm_state_modify(int cmd, unsigned int flags, int argc, char **argv) if (req.xsinfo.family == AF_UNSPEC) req.xsinfo.family = AF_INET; - if (rtnl_talk(&rth, &req.n, NULL) < 0) + if (rtnl_talk(&xrth, &req.n, NULL) < 0) exit(2); - rtnl_close(&rth); + rtnl_close(&xrth); return 0; } static int xfrm_state_allocspi(int argc, char **argv) { - struct rtnl_handle rth; + struct rtnl_handle xrth; struct { struct nlmsghdr n; struct xfrm_userspi_info xspi; @@ -917,14 +917,14 @@ static int xfrm_state_allocspi(int argc, char **argv) if (pcpu_num != -1) addattr32(&req.n, sizeof(req.buf), XFRMA_SA_PCPU, pcpu_num); - if (rtnl_open_byproto(&rth, 0, NETLINK_XFRM) < 0) + if (rtnl_open_byproto(&xrth, 0, NETLINK_XFRM) < 0) exit(1); if (req.xspi.info.family == AF_UNSPEC) req.xspi.info.family = AF_INET; - if (rtnl_talk(&rth, &req.n, &answer) < 0) + if (rtnl_talk(&xrth, &req.n, &answer) < 0) exit(2); if (xfrm_state_print(answer, (void *)stdout) < 0) { @@ -933,7 +933,7 @@ static int xfrm_state_allocspi(int argc, char **argv) } free(answer); - rtnl_close(&rth); + rtnl_close(&xrth); return 0; } @@ -1067,7 +1067,7 @@ static int xfrm_state_print_nokeys(struct nlmsghdr *n, void *arg) static int xfrm_state_get_or_delete(int argc, char **argv, int delete) { - struct rtnl_handle rth; + struct rtnl_handle xrth; struct { struct nlmsghdr n; struct xfrm_usersa_id xsid; @@ -1118,19 +1118,19 @@ static int xfrm_state_get_or_delete(int argc, char **argv, int delete) } } - if (rtnl_open_byproto(&rth, 0, NETLINK_XFRM) < 0) + if (rtnl_open_byproto(&xrth, 0, NETLINK_XFRM) < 0) exit(1); if (req.xsid.family == AF_UNSPEC) req.xsid.family = AF_INET; if (delete) { - if (rtnl_talk(&rth, &req.n, NULL) < 0) + if (rtnl_talk(&xrth, &req.n, NULL) < 0) exit(2); } else { struct nlmsghdr *answer; - if (rtnl_talk(&rth, &req.n, &answer) < 0) + if (rtnl_talk(&xrth, &req.n, &answer) < 0) exit(2); if (xfrm_state_print(answer, (void *)stdout) < 0) { @@ -1141,7 +1141,7 @@ static int xfrm_state_get_or_delete(int argc, char **argv, int delete) free(answer); } - rtnl_close(&rth); + rtnl_close(&xrth); return 0; } @@ -1153,7 +1153,6 @@ static int xfrm_state_get_or_delete(int argc, char **argv, int delete) static int xfrm_state_keep(struct nlmsghdr *n, void *arg) { struct xfrm_buffer *xb = (struct xfrm_buffer *)arg; - struct rtnl_handle *rth = xb->rth; struct xfrm_usersa_info *xsinfo = NLMSG_DATA(n); int len = n->nlmsg_len; struct nlmsghdr *new_n; @@ -1188,7 +1187,7 @@ static int xfrm_state_keep(struct nlmsghdr *n, void *arg) new_n->nlmsg_len = NLMSG_LENGTH(sizeof(*xsid)); new_n->nlmsg_flags = NLM_F_REQUEST; new_n->nlmsg_type = XFRM_MSG_DELSA; - new_n->nlmsg_seq = ++rth->seq; + new_n->nlmsg_seq = ++xb->rth->seq; xsid = NLMSG_DATA(new_n); xsid->family = xsinfo->family; @@ -1219,7 +1218,7 @@ static int xfrm_state_keep(struct nlmsghdr *n, void *arg) static int xfrm_state_list_or_deleteall(int argc, char **argv, int deleteall) { char *idp = NULL; - struct rtnl_handle rth; + struct rtnl_handle xrth; bool nokeys = false; if (argc > 0 || preferred_family != AF_UNSPEC) @@ -1261,7 +1260,7 @@ static int xfrm_state_list_or_deleteall(int argc, char **argv, int deleteall) argc--; argv++; } - if (rtnl_open_byproto(&rth, 0, NETLINK_XFRM) < 0) + if (rtnl_open_byproto(&xrth, 0, NETLINK_XFRM) < 0) exit(1); if (deleteall) { @@ -1271,7 +1270,7 @@ static int xfrm_state_list_or_deleteall(int argc, char **argv, int deleteall) xb.buf = buf; xb.size = sizeof(buf); - xb.rth = &rth; + xb.rth = &xrth; for (i = 0; ; i++) { struct { @@ -1281,7 +1280,7 @@ static int xfrm_state_list_or_deleteall(int argc, char **argv, int deleteall) .n.nlmsg_len = NLMSG_HDRLEN, .n.nlmsg_flags = NLM_F_DUMP | NLM_F_REQUEST, .n.nlmsg_type = XFRM_MSG_GETSA, - .n.nlmsg_seq = rth.dump = ++rth.seq, + .n.nlmsg_seq = xrth.dump = ++xrth.seq, }; xb.offset = 0; @@ -1290,12 +1289,12 @@ static int xfrm_state_list_or_deleteall(int argc, char **argv, int deleteall) if (show_stats > 1) fprintf(stderr, "Delete-all round = %d\n", i); - if (rtnl_send(&rth, (void *)&req, req.n.nlmsg_len) < 0) { + if (rtnl_send(&xrth, (void *)&req, req.n.nlmsg_len) < 0) { perror("Cannot send dump request"); exit(1); } - if (rtnl_dump_filter(&rth, xfrm_state_keep, &xb) < 0) { + if (rtnl_dump_filter(&xrth, xfrm_state_keep, &xb) < 0) { fprintf(stderr, "Delete-all terminated\n"); exit(1); } @@ -1305,7 +1304,7 @@ static int xfrm_state_list_or_deleteall(int argc, char **argv, int deleteall) break; } - if (rtnl_send_check(&rth, xb.buf, xb.offset) < 0) { + if (rtnl_send_check(&xrth, xb.buf, xb.offset) < 0) { perror("Failed to send delete-all request\n"); exit(1); } @@ -1331,7 +1330,7 @@ static int xfrm_state_list_or_deleteall(int argc, char **argv, int deleteall) .n.nlmsg_len = NLMSG_HDRLEN, .n.nlmsg_flags = NLM_F_DUMP | NLM_F_REQUEST, .n.nlmsg_type = XFRM_MSG_GETSA, - .n.nlmsg_seq = rth.dump = ++rth.seq, + .n.nlmsg_seq = xrth.dump = ++xrth.seq, }; if (filter.xsinfo.id.proto) @@ -1340,20 +1339,20 @@ static int xfrm_state_list_or_deleteall(int argc, char **argv, int deleteall) addattr_l(&req.n, sizeof(req), XFRMA_ADDRESS_FILTER, &addrfilter, sizeof(addrfilter)); - if (rtnl_send(&rth, (void *)&req, req.n.nlmsg_len) < 0) { + if (rtnl_send(&xrth, (void *)&req, req.n.nlmsg_len) < 0) { perror("Cannot send dump request"); exit(1); } - rtnl_filter_t filter = nokeys ? + rtnl_filter_t dump_filter = nokeys ? xfrm_state_print_nokeys : xfrm_state_print; - if (rtnl_dump_filter(&rth, filter, stdout) < 0) { + if (rtnl_dump_filter(&xrth, dump_filter, stdout) < 0) { fprintf(stderr, "Dump terminated\n"); exit(1); } } - rtnl_close(&rth); + rtnl_close(&xrth); exit(0); } @@ -1409,7 +1408,7 @@ static int print_sadinfo(struct nlmsghdr *n, void *arg) static int xfrm_sad_getinfo(int argc, char **argv) { - struct rtnl_handle rth; + struct rtnl_handle xrth; struct { struct nlmsghdr n; __u32 flags; @@ -1421,23 +1420,23 @@ static int xfrm_sad_getinfo(int argc, char **argv) }; struct nlmsghdr *answer; - if (rtnl_open_byproto(&rth, 0, NETLINK_XFRM) < 0) + if (rtnl_open_byproto(&xrth, 0, NETLINK_XFRM) < 0) exit(1); - if (rtnl_talk(&rth, &req.n, &answer) < 0) + if (rtnl_talk(&xrth, &req.n, &answer) < 0) exit(2); print_sadinfo(answer, (void *)stdout); free(answer); - rtnl_close(&rth); + rtnl_close(&xrth); return 0; } static int xfrm_state_flush(int argc, char **argv) { - struct rtnl_handle rth; + struct rtnl_handle xrth; struct { struct nlmsghdr n; struct xfrm_usersa_flush xsf; @@ -1469,17 +1468,17 @@ static int xfrm_state_flush(int argc, char **argv) argc--; argv++; } - if (rtnl_open_byproto(&rth, 0, NETLINK_XFRM) < 0) + if (rtnl_open_byproto(&xrth, 0, NETLINK_XFRM) < 0) exit(1); if (show_stats > 1) fprintf(stderr, "Flush state with XFRM-PROTO value \"%s\"\n", strxf_xfrmproto(req.xsf.proto)); - if (rtnl_talk(&rth, &req.n, NULL) < 0) + if (rtnl_talk(&xrth, &req.n, NULL) < 0) exit(2); - rtnl_close(&rth); + rtnl_close(&xrth); return 0; }
-- 2.53.0