Prevent busy poll loop on pfkey message error.
authorclaudio <claudio@openbsd.org>
Wed, 15 Jun 2022 16:00:37 +0000 (16:00 +0000)
committerclaudio <claudio@openbsd.org>
Wed, 15 Jun 2022 16:00:37 +0000 (16:00 +0000)
When pfkey_reply() detects an error in a message it needs to flush that
message out of the buffer because pfkey_read() only did a peak read.
OK tb@

usr.sbin/bgpd/pfkey.c

index 6da7de6..fafef64 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: pfkey.c,v 1.63 2022/06/15 14:09:30 claudio Exp $ */
+/*     $OpenBSD: pfkey.c,v 1.64 2022/06/15 16:00:37 claudio Exp $ */
 
 /*
  * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@@ -469,6 +469,9 @@ pfkey_reply(int sd, uint32_t *spi)
                        return (0);
                else {
                        log_warn("pfkey");
+                       /* discard error message */
+                       if (read(sd, &hdr, sizeof(hdr)) == -1)
+                               log_warn("pfkey read");
                        return (-1);
                }
        }