Move the rtable_exists() check into in_pcbset_rtableid().
authorclaudio <claudio@openbsd.org>
Thu, 18 Jan 2024 11:03:16 +0000 (11:03 +0000)
committerclaudio <claudio@openbsd.org>
Thu, 18 Jan 2024 11:03:16 +0000 (11:03 +0000)
OK bluhm@ mvs@

sys/netinet/in_pcb.c
sys/netinet/ip_output.c
sys/netinet6/ip6_output.c

index 5ac1e8d..41a9dfb 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: in_pcb.c,v 1.284 2024/01/09 19:57:00 bluhm Exp $      */
+/*     $OpenBSD: in_pcb.c,v 1.285 2024/01/18 11:03:16 claudio Exp $    */
 /*     $NetBSD: in_pcb.c,v 1.25 1996/02/13 23:41:53 christos Exp $     */
 
 /*
@@ -1306,6 +1306,10 @@ in_pcbset_rtableid(struct inpcb *inp, u_int rtableid)
 {
        struct inpcbtable *table = inp->inp_table;
 
+       /* table must exist */
+       if (!rtable_exists(rtableid))
+               return (EINVAL);
+
        mtx_enter(&table->inpt_mtx);
        if (inp->inp_lport) {
                mtx_leave(&table->inpt_mtx);
index 87cf83c..761d063 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: ip_output.c,v 1.392 2023/12/01 15:30:47 bluhm Exp $   */
+/*     $OpenBSD: ip_output.c,v 1.393 2024/01/18 11:03:16 claudio Exp $ */
 /*     $NetBSD: ip_output.c,v 1.28 1996/02/13 23:43:07 christos Exp $  */
 
 /*
@@ -1077,11 +1077,6 @@ ip_ctloutput(int op, struct socket *so, int level, int optname,
                        if (rtableid != rtid && rtableid != 0 &&
                            (error = suser(p)) != 0)
                                break;
-                       /* table must exist */
-                       if (!rtable_exists(rtid)) {
-                               error = EINVAL;
-                               break;
-                       }
                        error = in_pcbset_rtableid(inp, rtid);
                        break;
                case IP_PIPEX:
index 8366d83..370f15f 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: ip6_output.c,v 1.282 2023/12/01 15:30:47 bluhm Exp $  */
+/*     $OpenBSD: ip6_output.c,v 1.283 2024/01/18 11:03:16 claudio Exp $        */
 /*     $KAME: ip6_output.c,v 1.172 2001/03/25 09:55:56 itojun Exp $    */
 
 /*
@@ -1376,11 +1376,6 @@ do { \
                        if (rtableid != rtid && rtableid != 0 &&
                            (error = suser(p)) != 0)
                                break;
-                       /* table must exist */
-                       if (!rtable_exists(rtid)) {
-                               error = EINVAL;
-                               break;
-                       }
                        error = in_pcbset_rtableid(inp, rtid);
                        break;
                case IPV6_PIPEX: