]> git.proxmox.com Git - mirror_iproute2.git/blobdiff - ip/xfrm_state.c
lib/libnetlink: update rtnl_talk to support malloc buff at run time
[mirror_iproute2.git] / ip / xfrm_state.c
index 99fdec2325ec026856b458484865bbf4c939450a..3e20d6ed08d1c1e9c2ee9a15ce10ec9df86036a1 100644 (file)
@@ -726,7 +726,7 @@ 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) < 0)
+       if (rtnl_talk(&rth, &req.n, NULL) < 0)
                exit(2);
 
        rtnl_close(&rth);
@@ -757,8 +757,7 @@ static int xfrm_state_allocspi(int argc, char **argv)
        char *minp = NULL;
        char *maxp = NULL;
        struct xfrm_mark mark = {0, 0};
-       char res_buf[NLMSG_BUF_SIZE] = {};
-       struct nlmsghdr *res_n = (struct nlmsghdr *)res_buf;
+       struct nlmsghdr *answer;
 
        while (argc > 0) {
                if (strcmp(*argv, "mode") == 0) {
@@ -858,14 +857,15 @@ static int xfrm_state_allocspi(int argc, char **argv)
                req.xspi.info.family = AF_INET;
 
 
-       if (rtnl_talk(&rth, &req.n, res_n, sizeof(res_buf)) < 0)
+       if (rtnl_talk(&rth, &req.n, &answer) < 0)
                exit(2);
 
-       if (xfrm_state_print(NULL, res_n, (void *)stdout) < 0) {
+       if (xfrm_state_print(NULL, answer, (void *)stdout) < 0) {
                fprintf(stderr, "An error :-)\n");
                exit(1);
        }
 
+       free(answer);
        rtnl_close(&rth);
 
        return 0;
@@ -1046,19 +1046,20 @@ static int xfrm_state_get_or_delete(int argc, char **argv, int delete)
                req.xsid.family = AF_INET;
 
        if (delete) {
-               if (rtnl_talk(&rth, &req.n, NULL, 0) < 0)
+               if (rtnl_talk(&rth, &req.n, NULL) < 0)
                        exit(2);
        } else {
-               char buf[NLMSG_BUF_SIZE] = {};
-               struct nlmsghdr *res_n = (struct nlmsghdr *)buf;
+               struct nlmsghdr *answer;
 
-               if (rtnl_talk(&rth, &req.n, res_n, sizeof(req)) < 0)
+               if (rtnl_talk(&rth, &req.n, &answer) < 0)
                        exit(2);
 
-               if (xfrm_state_print(NULL, res_n, (void *)stdout) < 0) {
+               if (xfrm_state_print(NULL, answer, (void *)stdout) < 0) {
                        fprintf(stderr, "An error :-)\n");
                        exit(1);
                }
+
+               free(answer);
        }
 
        rtnl_close(&rth);
@@ -1314,22 +1315,23 @@ static int xfrm_sad_getinfo(int argc, char **argv)
        struct {
                struct nlmsghdr                 n;
                __u32                           flags;
-               char                            ans[64];
        } req = {
                .n.nlmsg_len = NLMSG_LENGTH(sizeof(req.flags)),
                .n.nlmsg_flags = NLM_F_REQUEST,
                .n.nlmsg_type = XFRM_MSG_GETSADINFO,
                .flags = 0XFFFFFFFF,
        };
+       struct nlmsghdr *answer;
 
        if (rtnl_open_byproto(&rth, 0, NETLINK_XFRM) < 0)
                exit(1);
 
-       if (rtnl_talk(&rth, &req.n, &req.n, sizeof(req)) < 0)
+       if (rtnl_talk(&rth, &req.n, &answer) < 0)
                exit(2);
 
-       print_sadinfo(&req.n, (void *)stdout);
+       print_sadinfo(answer, (void *)stdout);
 
+       free(answer);
        rtnl_close(&rth);
 
        return 0;
@@ -1376,7 +1378,7 @@ static int xfrm_state_flush(int argc, char **argv)
                fprintf(stderr, "Flush state with XFRM-PROTO value \"%s\"\n",
                        strxf_xfrmproto(req.xsf.proto));
 
-       if (rtnl_talk(&rth, &req.n, NULL, 0) < 0)
+       if (rtnl_talk(&rth, &req.n, NULL) < 0)
                exit(2);
 
        rtnl_close(&rth);