Permalink
Browse files

fix if preference function

  • Loading branch information...
1 parent f2bbb52 commit 623ee89d85a807b010ba3df10807dca489a79134 mitsuya committed Oct 11, 2005
Showing with 55 additions and 28 deletions.
  1. +31 −25 kame/kame/shisad/mdd.c
  2. +5 −2 kame/kame/shisad/mdd.h
  3. +19 −1 kame/kame/shisad/mdd_rtsock.c
@@ -1,4 +1,4 @@
-/* $KAME: mdd.c,v 1.4 2005/05/17 10:31:24 keiichi Exp $ */
+/* $KAME: mdd.c,v 1.5 2005/10/11 15:24:23 mitsuya Exp $ */
/*
* Copyright (C) 2004 WIDE Project. All rights reserved.
*
@@ -60,7 +60,6 @@
static void reload(int);
static void terminate(int);
-static int in6_is_addr_coa_candidate(struct in6_addr *);
static char *cmd;
int ver_major = 0;
@@ -114,6 +113,7 @@ main(argc, argv, env)
{
int ch;
struct binding *bp = NULL;
+ int if_pref = 0;
#ifdef MIP_MCOA
u_int16_t bid = 0;
@@ -149,7 +149,8 @@ main(argc, argv, env)
break;
#endif /* MIP_MCOA */
case 'i':
- set_coaif(optarg);
+ if_pref++;
+ set_coaif(optarg, if_pref);
cflag += 1;
break;
case 'h':
@@ -390,14 +391,16 @@ get_hoalist()
}
void
-set_coaif(ifname)
+set_coaif(ifname, preference)
char *ifname;
+ int preference;
{
struct cif *cifp;
cifp = (struct cif *) malloc(sizeof(struct cif));
cifp->cif_name = ifname;
cifp->cif_linkstatus = -1;
+ cifp->preference = preference;
LIST_INSERT_HEAD(&cifl_head, cifp, cif_entries);
}
@@ -491,22 +494,34 @@ set_coa()
{
struct coac *cp;
struct binding *bp;
- int maxmatchlen, matchlen;
+ int maxmatchlen, matchlen, if_pref;
struct sockaddr_in6 sin6;
+ char buf[PA_BUFSIZE];
- LIST_FOREACH(bp, &bl_head, binding_entries) {
- if (in6_is_addr_coa_candidate(&bp->coa.sin6_addr)) {
- /* the care-of address is still valid. */
- continue;
- }
+ LIST_FOREACH(bp, &bl_head, binding_entries) {
maxmatchlen = -1;
+ if_pref = -1;
+
LIST_FOREACH(cp, &coacl_head, coac_entries) {
matchlen = in6_matchlen(&bp->hoa.sin6_addr,
&cp->coa.sin6_addr);
- if (maxmatchlen < matchlen) {
+
+ /*
+ * 1. check preference
+ * take bigger one as primary coa
+ * 2. if preference were same, check matchlen
+ * take bigger one as primary coa
+ */
+ if (if_pref < cp->preference) {
+ if_pref = cp->preference;
maxmatchlen = matchlen;
memcpy(&sin6, &cp->coa, sizeof(sin6));
+ } else if (if_pref == cp->preference) {
+ if (maxmatchlen < matchlen) {
+ maxmatchlen = matchlen;
+ memcpy(&sin6, &cp->coa, sizeof(sin6));
+ }
}
}
if (maxmatchlen < 0) {
@@ -535,24 +550,15 @@ set_coa()
bp->flags &= ~BF_HOME;
memcpy(&bp->pcoa, &bp->coa, sizeof(bp->pcoa));
memcpy(&bp->coa, &sin6, sizeof(bp->coa));
- }
- }
-}
-
-static int
-in6_is_addr_coa_candidate(addr)
- struct in6_addr *addr;
-{
- struct coac *cp;
- LIST_FOREACH(cp, &coacl_head, coac_entries) {
- if (IN6_ARE_ADDR_EQUAL(&cp->coa.sin6_addr, addr))
- return (1);
+ printf("set_coa(): coa %s\n",
+ (char *) inet_ntop(AF_INET6,
+ &bp->coa.sin6_addr,
+ buf, sizeof(buf)));
+ }
}
- return (0);
}
-
void
sync_binding()
{
@@ -1,4 +1,4 @@
-/* $KAME: mdd.h,v 1.2 2005/02/18 05:57:44 t-momose Exp $ */
+/* $KAME: mdd.h,v 1.3 2005/10/11 15:24:23 mitsuya Exp $ */
/*
* Copyright (C) 2004 WIDE Project. All rights reserved.
*
@@ -54,11 +54,13 @@ struct cif {
LIST_ENTRY(cif) cif_entries;
char * cif_name;
int cif_linkstatus;
+ int preference;
};
struct coac {
LIST_ENTRY(coac) coac_entries;
struct sockaddr_in6 coa;
+ int preference;
};
LIST_HEAD(bl, binding);
@@ -70,7 +72,7 @@ struct binding *set_hoa(struct in6_addr *, int);
struct binding *set_hoa_str(char *);
void get_hoalist(void);
int _get_hoalist(void);
-void set_coaif(char *);
+void set_coaif(char *, int);
void get_coaiflist(void);
void get_coacandidate(void);
void set_coa(void);
@@ -79,6 +81,7 @@ void print_coaiflist(FILE *);
void mainloop(void);
void sync_binding(void);
int get_addr_with_ifl(struct coacl *, struct cifl *);
+int get_preference_in_ifl(int, struct cifl *);
int in6_addrscope(struct in6_addr *);
int chbinding(struct sockaddr_in6 *, struct sockaddr_in6 *, u_int16_t);
int returntohome(struct sockaddr_in6 *, struct sockaddr_in6 *, int);
@@ -1,4 +1,4 @@
-/* $KAME: mdd_rtsock.c,v 1.2 2005/04/14 06:22:36 suz Exp $ */
+/* $KAME: mdd_rtsock.c,v 1.3 2005/10/11 15:24:23 mitsuya Exp $ */
/*
* Copyright (C) 2004 WIDE Project. All rights reserved.
*
@@ -136,6 +136,22 @@ is_in_ifl(index, ifl_headp)
}
int
+get_preference_in_ifl(index, ifl_headp)
+ int index;
+ struct cifl *ifl_headp;
+{
+ struct cif *cifp;
+
+ LIST_FOREACH(cifp, ifl_headp, cif_entries) {
+ if (if_nametoindex(cifp->cif_name) == index)
+ return (cifp->preference);
+ }
+
+ return (0);
+}
+
+
+int
get_addr_with_ifl(coacl_headp, ifl_headp)
struct coacl *coacl_headp;
struct cifl *ifl_headp;
@@ -194,6 +210,8 @@ get_addr_with_ifl(coacl_headp, ifl_headp)
cp = malloc(sizeof(struct coac));
memcpy(&cp->coa, sin6, sizeof(cp->coa));
+ cp->preference = get_preference_in_ifl(ifm->ifm_index,
+ ifl_headp);
LIST_INSERT_HEAD(coacl_headp, cp, coac_entries);
}
}

0 comments on commit 623ee89

Please sign in to comment.