@@ -58,6 +58,8 @@ typedef struct {
58
58
59
59
static TDB * client_db ;
60
60
61
+ unsigned long tfw_hash_str_len (const TfwStr * str , unsigned long str_len );
62
+
61
63
/**
62
64
* Called when a client socket is closed.
63
65
*/
@@ -147,16 +149,16 @@ tfw_client_ent_init(TdbRec *rec, void (*init)(void *), void *data)
147
149
}
148
150
149
151
/**
150
- * Find a client corresponding to @addr and @cli_addr (e.g. from X-Forwarded-For).
151
- * More advanced identification is possible based on User-Agent,
152
- * Cookie and other HTTP headers.
152
+ * Find a client corresponding to @addr, @cli_addr (e.g. from X-Forwarded-For)
153
+ * and @user_agent.
153
154
*
154
155
* The returned TfwClient reference must be released via tfw_client_put()
155
156
* when the @sk is closed.
156
157
* TODO #515 employ eviction strategy for the table.
157
158
*/
158
159
TfwClient *
159
- tfw_client_obtain (TfwAddr addr , TfwAddr * cli_addr , void (* init )(void * ))
160
+ tfw_client_obtain (TfwAddr addr , TfwAddr * cli_addr , TfwStr * user_agent ,
161
+ void (* init )(void * ))
160
162
{
161
163
TfwClientEntry * ent ;
162
164
TfwClient * cli ;
@@ -171,6 +173,8 @@ tfw_client_obtain(TfwAddr addr, TfwAddr *cli_addr, void (*init)(void *))
171
173
if (cli_addr )
172
174
key ^= hash_calc ((const char * )& cli_addr -> sin6_addr ,
173
175
sizeof (cli_addr -> sin6_addr ));
176
+ if (user_agent )
177
+ key ^= tfw_hash_str_len (user_agent , 256 );
174
178
175
179
len = sizeof (* ent );
176
180
rec = tdb_rec_get_alloc (client_db , key , & len , & tfw_client_addr_eq ,
0 commit comments