Patches to print/parse IPv6 interface ID's.
authoraland <aland>
Mon, 15 Sep 2003 20:16:53 +0000 (20:16 +0000)
committeraland <aland>
Mon, 15 Sep 2003 20:16:53 +0000 (20:16 +0000)
Patch from Hajimu UMEMOTO

Next, we do IPv6 addresses & prefixes...

src/include/libradius.h
src/lib/misc.c
src/lib/print.c
src/lib/valuepair.c

index e06d15b..558448e 100644 (file)
@@ -259,6 +259,8 @@ char *              ip_hostname (char *buf, size_t buflen, uint32_t ipaddr);
 uint32_t       ip_getaddr (const char *);
 char *         ip_ntoa(char *, uint32_t);
 uint32_t       ip_addr(const char *);
+char           *ifid_ntoa(char *buffer, size_t size, uint8_t *ifid);
+uint8_t                *ifid_aton(const char *ifid_str, uint8_t *ifid);
 char           *strNcpy(char *dest, const char *src, int n);
 void           rad_lowercase(char *str);
 void           rad_rmspace(char *str);
index 94f1947..79f1b73 100644 (file)
@@ -284,3 +284,62 @@ int rad_unlockfd(int fd, int lock_len)
        return fcntl(fd, F_UNLCK, (void *)&fl);
 #endif
 }
+
+/*
+ *     Return an interface-id in standard colon notation
+ */
+char *ifid_ntoa(char *buffer, size_t size, uint8_t *ifid)
+{
+       snprintf(buffer, size, "%x:%x:%x:%x",
+                (ifid[0] << 8) + ifid[1], (ifid[2] << 8) + ifid[3],
+                (ifid[4] << 8) + ifid[5], (ifid[6] << 8) + ifid[7]);
+       return buffer;
+}
+
+
+/*
+ *     Return an interface-id from
+ *     one supplied in standard colon notation.
+ */
+uint8_t *ifid_aton(const char *ifid_str, uint8_t *ifid)
+{
+       static const char xdigits[] = "0123456789abcdef";
+       char *p, *pch;
+       int num_id = 0, val = 0, idx = 0;
+
+       for (p = ifid_str; ; ++p) {
+               if (*p == ':' || *p == '\0') {
+                       if (num_id <= 0)
+                               return NULL;
+
+                       /*
+                        *      Drop 'val' into the array.
+                        */
+                       ifid[idx] = (val >> 8) & 0xff;
+                       ifid[idx + 1] = val & 0xff;
+                       if (*p == '\0') {
+                               /*
+                                *      Must have all entries before
+                                *      end of the string.
+                                */
+                               if (idx != 6)
+                                       return NULL;
+                               break;
+                       }
+                       val = 0;
+                       num_id = 0;
+                       if ((idx += 2) > 6)
+                               return NULL;
+               } else if ((pch = strchr(xdigits, tolower(*p))) != NULL) {
+                       if (++num_id > 4)
+                               return NULL;
+                       /*
+                        *      Dumb version of 'scanf'
+                        */
+                       val <<= 4;
+                       val |= (pch - xdigits);
+               } else
+                       return NULL;
+       }
+       return ifid;
+ }
index 1257531..162db03 100644 (file)
@@ -189,6 +189,10 @@ int vp_prints_value(char * out, int outlen, VALUE_PAIR *vp, int delimitst)
                  a = buf;
                  break;
 
+               case PW_TYPE_IFID:
+                       a = ifid_ntoa(buf, sizeof(buf), vp->strvalue);
+                       break;
+
                default:
                        a = 0;
                        break;
index 4749022..c82d7b3 100644 (file)
@@ -674,6 +674,16 @@ VALUE_PAIR *pairparsevalue(VALUE_PAIR *vp, const char *value)
                        }
                        break;
 
+               case PW_TYPE_IFID:
+                       if (ifid_aton(value, vp->strvalue) == NULL) {
+                               librad_log("failed to parse interface-id "
+                                          "string \"%s\"", value);
+                               return NULL;
+                       }
+                       vp->length = 8;
+                       vp->strvalue[vp->length] = '\0';
+                       break;
+
                        /*
                         *  Anything else.
                         */