Bug 88336 - [ipsec] [patch] setkey(8) -D fails to report all SAs
Summary: [ipsec] [patch] setkey(8) -D fails to report all SAs
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: kern (show other bugs)
Version: Unspecified
Hardware: Any Any
: Normal Affects Only Me
Assignee: Andrey V. Elsukov
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-11-01 15:40 UTC by Mats Palmgren
Modified: 2019-01-20 09:27 UTC (History)
2 users (show)

See Also:


Attachments
file.diff (421 bytes, patch)
2005-11-01 15:40 UTC, Mats Palmgren
no flags Details | Diff
file.diff (353 bytes, patch)
2005-11-01 15:40 UTC, Mats Palmgren
no flags Details | Diff
file.diff (641 bytes, patch)
2005-11-01 15:40 UTC, Mats Palmgren
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Mats Palmgren 2005-11-01 15:40:17 UTC
The socket buffer size for pfkey only allows for 342
SAs to be dumped by "setkey -D".
(In our application we have the need for in the order of 10k)

Fix: This is our workaround for now, probably not the best solution.
Could you at least add the u_quad_t cast since it triggers this
warning when increasing SB_MAX:
uipc_socket2.c:69: warning: integer overflow in expression

The added cast corresponds to uipc_socket2.c:490:
    sb_max_adj = (u_quad_t)sb_max * MCLBYTES / (MSIZE + MCLBYTES);



+#ifdef FIX
+       const int r_bufsiz = 8 * 1024 * 1024;
+#endif
        if ((so = socket(PF_KEY, SOCK_RAW, PF_KEY_V2)) < 0) {
                __ipsec_set_strerror(strerror(errno));
                return -1;
@@ -1592,7 +1601,11 @@
         * Don't really care even if it fails.
         */
        (void)setsockopt(so, SOL_SOCKET, SO_SNDBUF, &bufsiz, sizeof(bufsiz));
+#ifdef FIX
+       (void)setsockopt(so, SOL_SOCKET, SO_RCVBUF, &r_bufsiz, sizeof(r_bufsiz));
+#else
        (void)setsockopt(so, SOL_SOCKET, SO_RCVBUF, &bufsiz, sizeof(bufsiz));
+#endif

        __ipsec_errcode = EIPSEC_NO_ERROR;
        return so;
u_long sb_max = SB_MAX;
 static u_long sb_max_adj =
-    SB_MAX * MCLBYTES / (MSIZE + MCLBYTES); /* adjusted sb_max */
+    (u_quad_t)SB_MAX * MCLBYTES / (MSIZE + MCLBYTES); /* adjusted sb_max */

 static u_long sb_efficiency = 8;       /* parameter for sbreserve() */
How-To-Repeat: Use 'setkey' command to push 10000 SAs into the kernel.
Run 'setkey -D'.

ACTUAL RESULT
Only 342 of the SAs is reported to userland, then an error message:
# setkey -D | grep esp | wc -l
recv: Resource temporarily unavailable
     342

EXPECTED RESULT
# setkey -D | grep esp | wc -l
     10000
Comment 1 Robert Watson freebsd_committer freebsd_triage 2009-02-09 23:26:47 UTC
Responsible Changed
From-To: freebsd-bugs->freebsd-net

Tag as ipsec; assign to freebsd-net.
Comment 2 VANHULLEBUS Yvan freebsd_committer freebsd_triage 2009-02-10 08:39:39 UTC
Responsible Changed
From-To: freebsd-net->vanhu

Alraedy working on the problem for ipsec-tools, on which a similar patch 
has been added as a first workaround.
Comment 3 Eitan Adler freebsd_committer freebsd_triage 2017-12-31 08:01:27 UTC
For bugs matching the following criteria:

Status: In Progress Changed: (is less than) 2014-06-01

Reset to default assignee and clear in-progress tags.

Mail being skipped
Comment 4 commit-hook freebsd_committer freebsd_triage 2018-03-11 19:26:42 UTC
A commit references this bug:

Author: ae
Date: Sun Mar 11 19:26:35 UTC 2018
New revision: 330781
URL: https://svnweb.freebsd.org/changeset/base/330781

Log:
  Update pfkey_open() function to set socket's write buffer size to
  128k and receive buffer size to 2MB. In case if system has bigger
  default values, do not lower them.

  This should partially solve the problem, when setkey(8) returns
  EAGAIN error on systems with many SAs or SPs.

  PR:		88336
  Obtained from:	NetBSD/ipsec-tools
  MFC after:	2 weeks

Changes:
  head/lib/libipsec/pfkey.c
Comment 5 commit-hook freebsd_committer freebsd_triage 2018-03-25 03:50:46 UTC
A commit references this bug:

Author: ae
Date: Sun Mar 25 03:50:38 UTC 2018
New revision: 331527
URL: https://svnweb.freebsd.org/changeset/base/331527

Log:
  MFC r330781:
    Update pfkey_open() function to set socket's write buffer size to
    128k and receive buffer size to 2MB. In case if system has bigger
    default values, do not lower them.

    This should partially solve the problem, when setkey(8) returns
    EAGAIN error on systems with many SAs or SPs.

    PR:		88336
    Obtained from:	NetBSD/ipsec-tools

Changes:
_U  stable/11/
  stable/11/lib/libipsec/pfkey.c
Comment 6 Oleksandr Tymoshenko freebsd_committer freebsd_triage 2019-01-19 19:17:24 UTC
Hello,

There is a commit referencing this PR but it's not yet closed. Is there any pending work or can it be closed?

Thanks
Comment 7 Andrey V. Elsukov freebsd_committer freebsd_triage 2019-01-20 09:27:13 UTC
The committed fix is a partial solution, but since there is no pending work, I'm closing it.