]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Add 'Cache-Status-Only' control attribute, to check the status of
authorArran Cudbard-Bell <a.cudbardb@freeradius.org>
Thu, 23 Aug 2012 15:58:50 +0000 (16:58 +0100)
committerArran Cudbard-Bell <a.cudbardb@freeradius.org>
Thu, 23 Aug 2012 16:02:41 +0000 (17:02 +0100)
an entry, but not add or merge it.

Update documentation.

Only control:Cache-TTL may extend the TTL of an entry, or expire an entry.

raddb/modules/cache
share/dictionary.freeradius.internal
src/include/radius.h
src/modules/rlm_cache/rlm_cache.c

index 5e42a62604678ef0196c3eb4da72f219bfd51867..902ae358d4107fa519d0c114b95645db5ed2c078 100644 (file)
@@ -15,8 +15,8 @@
 #      If you want different things cached for authorize and post-auth,
 #      you will need to define two instances of the "cache" module.
 #
-#      The module returns "updated" if it found a cache entry.
-#      The module returns "ok" if it added a new cache entry.
+#      The module returns "ok" if it found a cache entry.
+#      The module returns "updated" if it added a new cache entry.
 #      The module returns "noop" if it did nothing.
 #
 cache {
@@ -43,6 +43,16 @@ cache {
        #
        #  You should ALWAYS leave it as "epoch = 0" here.
        epoch = 0
+       
+       #  The module can also operate in status-only mode where it will
+       #  not add new cache entries, or merge existing ones.
+       #
+       #  To enable set the control variable "Cache-Status-Only" to "yes"
+       #  The module will return "ok" if it found a cache entry.
+       #  The module will return "notfound" if it failed to find a cache entry,
+       #  or the entry had expired.
+       #
+       #  Note: expired entries will still be removed.
 
        #  The list of attributes to cache for a particular key.
        #  Each key gets the same set of cached attributes.
@@ -51,9 +61,11 @@ cache {
        #  You can specify which list the attribute goes into by
        #  prefixing the attribute name with the list.  This allows
        #  you to update multiple lists with one configuration.
-       update cache {
+       #
+       #  If no list is specified the request list will be updated.
+       attributes {
                # list:Attr-Name
-               reply:Filter-Id += "%l"
+               reply:Reply-Message += "I'm the cached reply from %t"
 
                control:Class := 0x010203
        }
index 04859b1349013c25918ddaef3df9ad641d74768d..177191055a7ac67fdd77110dbf293ea26cf7ebb8 100644 (file)
@@ -219,7 +219,10 @@ ATTRIBUTE  MS-CHAP-Password                        1133    string
 ATTRIBUTE      Packet-Transmit-Counter                 1134    integer
 ATTRIBUTE      Cached-Session-Policy                   1135    string
 ATTRIBUTE      Cache-TTL                               1136    integer
+ATTRIBUTE      Cache-Status-Only                       1137    integer
 
+VALUE  Cache-Status-Only               no                      0
+VALUE  Cache-Status-Only               yes                     1
 #
 #      Range:  1200-1279
 #              EAP-SIM (and other EAP type) weirdness.
index 0b577232290944ee8b9d9607cbf5c4ff524aed1d..775ec5c90af30229d0d6207cc63bb8d4bd7656ce 100644 (file)
 #define PW_PACKET_TRANSMIT_COUNTER             1134
 #define PW_CACHED_SESSION_POLICY       1135
 #define PW_CACHE_TTL                   1136
+#define PW_CACHE_STATUS_ONLY           1137
 
 /*
  *     Integer Translations
index 6a651bec33b593f6e68ad20b360d4b0884cd656e..d711356a7a5869ea3272ea794500221dee31434a 100644 (file)
@@ -17,8 +17,7 @@
  *   along with this program; if not, write to the Free Software
  *   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
  *
- * Copyright 2000,2006  The FreeRADIUS server project
- * Copyright 2000  your name <your address>
+ * Copyright 2012  The FreeRADIUS server project
  */
 
 #include <freeradius-devel/ident.h>
@@ -166,11 +165,16 @@ static rlm_cache_entry_t *cache_find(rlm_cache_t *inst, REQUEST *request,
        if ((c->expires < request->timestamp) ||
            (c->created < inst->epoch)) {
        delete:
+               DEBUG("rlm_cache: Entry has expired, removing");
+
                fr_heap_extract(inst->heap, c);
                rbtree_deletebydata(inst->cache, c);
+               
                return NULL;
        }
 
+       DEBUG("rlm_cache: Found entry for \"%s\"", key);
+
        /*
         *      Update the expiry time based on the TTL.
         *      A TTL of 0 means "delete from the cache".
@@ -178,16 +182,12 @@ static rlm_cache_entry_t *cache_find(rlm_cache_t *inst, REQUEST *request,
        vp = pairfind(request->config_items, PW_CACHE_TTL);
        if (vp) {
                if (vp->vp_integer == 0) goto delete;
-
+               
                ttl = vp->vp_integer;
-       } else {
-               ttl = inst->ttl;
+               c->expires = request->timestamp + ttl;
+               DEBUG("rlm_cache: Adding %d to the TTL", ttl);
        }
 
-       DEBUG("rlm_cache: Found entry for \"%s\".  Adding %d to the TTL",
-             key, ttl);
-       c->expires = request->timestamp + ttl;
-
        return c;
 }
 
@@ -354,7 +354,7 @@ static const CONF_PARSER module_config[] = {
        { "ttl", PW_TYPE_INTEGER,
          offsetof(rlm_cache_t, ttl), NULL,   "500" },
        { "epoch", PW_TYPE_INTEGER,
-         offsetof(rlm_cache_t, epoch), NULL,   NULL },
+         offsetof(rlm_cache_t, epoch), NULL,   "0" },
 
        { NULL, -1, 0, NULL, NULL }             /* end the list */
 };
@@ -410,6 +410,12 @@ static int cache_instantiate(CONF_SECTION *conf, void **instance)
                cache_detach(inst);
                return -1;
        }
+       
+       if (inst->epoch != 0){
+               radlog(L_ERR, "rlm_cache: Epoch should only be set dynamically");
+               cache_detach(inst);
+               return -1;
+       }
 
        /*
         *      The cache.
@@ -431,6 +437,7 @@ static int cache_instantiate(CONF_SECTION *conf, void **instance)
                cache_detach(inst);
                return -1;
        }
+       
 
        inst->cs = cf_section_sub_find(conf, "update");
        if (!inst->cs) {
@@ -463,14 +470,26 @@ static int cache_it(void *instance, REQUEST *request)
 {
        rlm_cache_entry_t *c;
        rlm_cache_t *inst = instance;
+       VALUE_PAIR *vp;
        char buffer[1024];
 
        radius_xlat(buffer, sizeof(buffer), inst->key, request, NULL);
 
        c = cache_find(inst, request, buffer);
+       
+       /*
+        *      If yes, only return whether we found a valid cache entry
+        */
+       vp = pairfind(request->config_items, PW_CACHE_STATUS_ONLY);
+       if (vp && vp->vp_integer) {
+               return c ?
+                       RLM_MODULE_OK:
+                       RLM_MODULE_NOTFOUND;
+       }
+       
        if (c) {
                cache_merge(request, c);
-               return RLM_MODULE_UPDATED;
+               return RLM_MODULE_OK;
        }
 
        c = cache_add(inst, request, buffer);
@@ -478,7 +497,7 @@ static int cache_it(void *instance, REQUEST *request)
 
        cache_merge(request, c);
 
-       return RLM_MODULE_OK;
+       return RLM_MODULE_UPDATED;
 }