]> git.sur5r.net Git - openldap/commitdiff
added tcp keepalive support to back-ldap
authorTed C. Cheng <tedcheng@symas.com>
Thu, 24 Jan 2013 01:10:41 +0000 (17:10 -0800)
committerQuanah Gibson-Mount <quanah@openldap.org>
Thu, 24 Jan 2013 18:53:56 +0000 (10:53 -0800)
doc/man/man5/slapd-ldap.5
servers/slapd/back-ldap/bind.c
servers/slapd/back-ldap/config.c
servers/slapd/config.c

index 1244d1fe088101d645b41a9074990a1a5ef62e2b..7b2ab181a2b7cce4b75849886d2754ba750b2abc 100644 (file)
@@ -422,6 +422,25 @@ for details on the syntax of this field.
 This directive causes a cached connection to be dropped an recreated
 after it has been idle for the specified time.
 
+.TP
+.B keepalive  <idle>:<probes>:<interval>
+The
+.B keepalive
+parameter sets the values of \fIidle\fP, \fIprobes\fP, and \fIinterval\fP
+used to check whether a socket is alive;
+.I idle
+is the number of seconds a connection needs to remain idle before TCP 
+starts sending keepalive probes;
+.I probes
+is the maximum number of keepalive probes TCP should send before dropping
+the connection;
+.I interval
+is interval in seconds between individual keepalive probes.
+Only some systems support the customization of these values;
+the
+.B keepalive
+parameter is ignored otherwise, and system-wide settings are used.
+
 .TP
 .B network\-timeout <time>
 Sets the network timeout value after which
index 409b93c45452a6c8cd753405e3b30acaa06f99b1..45f228a2824c2a6145b94dd583db241449d4a8da 100644 (file)
@@ -716,6 +716,9 @@ ldap_back_prepare_conn( ldapconn_t *lc, Operation *op, SlapReply *rs, ldap_back_
                ldap_set_option( ld, LDAP_OPT_NETWORK_TIMEOUT, (const void *)&tv );
        }
 
+       /* turn on network keepalive, if configured so */
+       slap_client_keepalive(ld, &li->li_tls.sb_keepalive); 
+
 #ifdef HAVE_TLS
        if ( LDAP_BACK_CONN_ISPRIV( lc ) ) {
                /* See "rationale" comment in ldap_back_getconn() */
index fdba1d3cf62be951f32690f9151dc4394ddb112c..fd48ea385e3fdbb508b6587298d8f31417d7f119 100644 (file)
@@ -74,6 +74,7 @@ enum {
        LDAP_BACK_CFG_ONERR,
 
        LDAP_BACK_CFG_REWRITE,
+       LDAP_BACK_CFG_KEEPALIVE,
 
        LDAP_BACK_CFG_LAST
 };
@@ -353,6 +354,14 @@ static ConfigTable ldapcfg[] = {
        { "rewrite", "<arglist>", 2, 4, STRLENOF( "rewrite" ),
                ARG_STRING|ARG_MAGIC|LDAP_BACK_CFG_REWRITE,
                ldap_back_cf_gen, NULL, NULL, NULL },
+       { "keepalive", "keepalive", 2, 2, 0,
+               ARG_MAGIC|LDAP_BACK_CFG_KEEPALIVE,
+               ldap_back_cf_gen, "( OLcfgDbAt:3.29 "
+                       "NAME 'olcDbKeepalive' "
+                       "DESC 'TCP keepalive' "
+                       "SYNTAX OMsDirectoryString "
+                       "SINGLE-VALUE )",
+               NULL, NULL },
        { NULL, NULL, 0, 0, 0, ARG_IGNORED,
                NULL, NULL, NULL, NULL }
 };
@@ -393,6 +402,7 @@ static ConfigOCs ldapocs[] = {
                        "$ olcDbNoRefs "
                        "$ olcDbNoUndefFilter "
                        "$ olcDbOnErr "
+                       "$ olcDbKeepalive "
                ") )",
                        Cft_Database, ldapcfg},
        { NULL, 0, NULL }
@@ -1404,6 +1414,16 @@ ldap_back_cf_gen( ConfigArgs *c )
                        }
                        break;
 
+               case LDAP_BACK_CFG_KEEPALIVE: {
+                       struct berval bv;
+                       char buf[AC_LINE_MAX];
+                       bv.bv_len = AC_LINE_MAX;
+                       bv.bv_val = &buf[0];
+                       slap_keepalive_parse(&bv, &li->li_tls.sb_keepalive, 0, 0, 1);
+                       value_add_one( &c->rvalue_vals, &bv );
+                       break;
+                       }
+
                default:
                        /* FIXME: we need to handle all... */
                        assert( 0 );
@@ -1571,6 +1591,12 @@ ldap_back_cf_gen( ConfigArgs *c )
                        li->li_flags &= ~LDAP_BACK_F_ONERR_STOP;
                        break;
 
+               case LDAP_BACK_CFG_KEEPALIVE:
+                       li->li_tls.sb_keepalive.sk_idle = 0;
+                       li->li_tls.sb_keepalive.sk_probes = 0;
+                       li->li_tls.sb_keepalive.sk_interval = 0;
+                       break;
+
                default:
                        /* FIXME: we need to handle all... */
                        assert( 0 );
@@ -2259,6 +2285,11 @@ done_url:;
                        "and prefix all directives with \"rwm-\")" );
                Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->cr_msg, 0 );
                return 1;
+
+       case LDAP_BACK_CFG_KEEPALIVE:
+               slap_keepalive_parse( ber_bvstrdup(c->argv[1]),
+                                &li->li_tls.sb_keepalive, 0, 0, 0);
+               break;
                
        default:
                /* FIXME: try to catch inconsistencies */
index d292ab91787d86afd8817d1089a15a2ff073291e..9c7f00db0c5c5a3ec3965d0bb782f6821afaa558 100644 (file)
@@ -1283,7 +1283,7 @@ static slap_verbmasks versionkey[] = {
        { BER_BVNULL, 0 }
 };
 
-static int 
+int 
 slap_keepalive_parse(
        struct berval *val,
        void *bc,
@@ -1925,6 +1925,29 @@ int bindconf_tls_set( slap_bindconf *bc, LDAP *ld )
 }
 #endif
 
+/*
+ * set connection keepalive options
+ */
+void
+slap_client_keepalive(LDAP *ld, slap_keepalive *sk)
+{
+       if (!sk) return;
+
+       if ( sk->sk_idle ) {
+               ldap_set_option( ld, LDAP_OPT_X_KEEPALIVE_IDLE, &sk->sk_idle );
+       }
+
+       if ( sk->sk_probes ) {
+               ldap_set_option( ld, LDAP_OPT_X_KEEPALIVE_PROBES, &sk->sk_probes );
+       }
+
+       if ( sk->sk_interval ) {
+               ldap_set_option( ld, LDAP_OPT_X_KEEPALIVE_INTERVAL, &sk->sk_interval );
+       }
+
+       return;
+}
+
 /*
  * connect to a client using the bindconf data
  * note: should move "version" into bindconf...
@@ -1963,6 +1986,10 @@ slap_client_connect( LDAP **ldp, slap_bindconf *sb )
                ldap_set_option( ld, LDAP_OPT_NETWORK_TIMEOUT, &tv );
        }
 
+       /* setting network keepalive options */
+       slap_client_keepalive(ld, &sb->sb_keepalive);
+
+#if 0
        if ( sb->sb_keepalive.sk_idle ) {
                ldap_set_option( ld, LDAP_OPT_X_KEEPALIVE_IDLE, &sb->sb_keepalive.sk_idle );
        }
@@ -1974,6 +2001,7 @@ slap_client_connect( LDAP **ldp, slap_bindconf *sb )
        if ( sb->sb_keepalive.sk_interval ) {
                ldap_set_option( ld, LDAP_OPT_X_KEEPALIVE_INTERVAL, &sb->sb_keepalive.sk_interval );
        }
+#endif /* 0 */
 
 #ifdef HAVE_TLS
        if ( sb->sb_tls_do_init ) {