Module Name: src
Committed By: joe
Date: Tue Jan 14 13:49:17 UTC 2025
Modified Files:
src/sys/altq: altq_afmap.c altq_afmap.h
Log Message:
handle duplication: extract address family interface lookup
To generate a diff of this commit:
cvs rdiff -u -r1.23 -r1.24 src/sys/altq/altq_afmap.c
cvs rdiff -u -r1.3 -r1.4 src/sys/altq/altq_afmap.h
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/sys/altq/altq_afmap.c
diff -u src/sys/altq/altq_afmap.c:1.23 src/sys/altq/altq_afmap.c:1.24
--- src/sys/altq/altq_afmap.c:1.23 Fri Dec 31 14:25:47 2021
+++ src/sys/altq/altq_afmap.c Tue Jan 14 13:49:17 2025
@@ -1,4 +1,4 @@
-/* $NetBSD: altq_afmap.c,v 1.23 2021/12/31 14:25:47 riastradh Exp $ */
+/* $NetBSD: altq_afmap.c,v 1.24 2025/01/14 13:49:17 joe Exp $ */
/* $KAME: altq_afmap.c,v 1.12 2005/04/13 03:44:24 suz Exp $ */
/*
@@ -36,7 +36,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: altq_afmap.c,v 1.23 2021/12/31 14:25:47 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: altq_afmap.c,v 1.24 2025/01/14 13:49:17 joe Exp $");
#ifdef _KERNEL_OPT
#include "opt_altq.h"
@@ -104,12 +104,8 @@ afm_dealloc(struct ifnet *ifp)
{
struct afm_head *head;
- for (head = afhead_chain.lh_first; head != NULL;
- head = head->afh_chain.le_next)
- if (head->afh_ifp == ifp)
- break;
- if (head == NULL)
- return (-1);
+ if ((head = afmhead_if(ifp)) == NULL)
+ return -1 ;
afm_removeall(ifp);
@@ -124,11 +120,7 @@ afm_top(struct ifnet *ifp)
{
struct afm_head *head;
- for (head = afhead_chain.lh_first; head != NULL;
- head = head->afh_chain.le_next)
- if (head->afh_ifp == ifp)
- break;
- if (head == NULL)
+ if ((head = afmhead_if(ifp)) == NULL)
return NULL;
return (head->afh_head.lh_first);
@@ -140,12 +132,8 @@ afm_add(struct ifnet *ifp, struct atm_fl
struct afm_head *head;
struct afm *afm;
- for (head = afhead_chain.lh_first; head != NULL;
- head = head->afh_chain.le_next)
- if (head->afh_ifp == ifp)
- break;
- if (head == NULL)
- return (-1);
+ if ((head = afmhead_if(ifp)) == NULL)
+ return -1;
if (flowmap->af_flowinfo.fi_family == AF_INET) {
if (flowmap->af_flowinfo.fi_len != sizeof(struct flowinfo_in))
@@ -184,13 +172,9 @@ afm_removeall(struct ifnet *ifp)
{
struct afm_head *head;
struct afm *afm;
-
- for (head = afhead_chain.lh_first; head != NULL;
- head = head->afh_chain.le_next)
- if (head->afh_ifp == ifp)
- break;
- if (head == NULL)
- return (-1);
+
+ if ((head = afmhead_if(ifp)) == NULL)
+ return -1;
while ((afm = head->afh_head.lh_first) != NULL)
afm_remove(afm);
@@ -203,11 +187,7 @@ afm_lookup(struct ifnet *ifp, int vpi, i
struct afm_head *head;
struct afm *afm;
- for (head = afhead_chain.lh_first; head != NULL;
- head = head->afh_chain.le_next)
- if (head->afh_ifp == ifp)
- break;
- if (head == NULL)
+ if ((head = afmhead_if(ifp)) == NULL)
return NULL;
for (afm = head->afh_head.lh_first; afm != NULL;
@@ -290,11 +270,7 @@ afm_match(struct ifnet *ifp, struct flow
{
struct afm_head *head;
- for (head = afhead_chain.lh_first; head != NULL;
- head = head->afh_chain.le_next)
- if (head->afh_ifp == ifp)
- break;
- if (head == NULL)
+ if ((head = afmhead_if(ifp)) == NULL)
return NULL;
switch (flow->fi_family) {
@@ -311,6 +287,18 @@ afm_match(struct ifnet *ifp, struct flow
}
}
+/* find the address family node on the current interface */
+struct afm_head *
+afmhead_if(struct ifnet *ifp)
+{
+ struct afm_head *head;
+ for (head = afhead_chain.lh_first; head != NULL;
+ head = head->afh_chain.le_next)
+ if (head->afh_ifp == ifp)
+ return head;
+ return NULL;
+}
+
/*
* afm device interface
*/
Index: src/sys/altq/altq_afmap.h
diff -u src/sys/altq/altq_afmap.h:1.3 src/sys/altq/altq_afmap.h:1.4
--- src/sys/altq/altq_afmap.h:1.3 Thu Oct 12 19:59:08 2006
+++ src/sys/altq/altq_afmap.h Tue Jan 14 13:49:17 2025
@@ -1,4 +1,4 @@
-/* $NetBSD: altq_afmap.h,v 1.3 2006/10/12 19:59:08 peter Exp $ */
+/* $NetBSD: altq_afmap.h,v 1.4 2025/01/14 13:49:17 joe Exp $ */
/* $KAME: altq_afmap.h,v 1.6 2002/04/03 05:38:50 kjc Exp $ */
/*
@@ -98,6 +98,7 @@ int afm_remove(struct afm *);
int afm_removeall(struct ifnet *);
struct afm *afm_lookup(struct ifnet *, int, int);
struct afm *afm_match(struct ifnet *, struct flowinfo *);
+struct afm_head *afmhead_if(struct ifnet *);
#endif /* _KERNEL */