Permalink
Browse files

Added CryptoAuth session state and ipv6 address to sessionStats

  • Loading branch information...
1 parent eeb619f commit 428d3f65a2bd0cdc0644b5d7902bfb22ec8e10b3 Caleb James DeLisle committed Dec 25, 2013
Showing with 51 additions and 15 deletions.
  1. +3 −2 contrib/python/sessionStats
  2. +12 −1 crypto/CryptoAuth.h
  3. +9 −0 interface/SessionManager.c
  4. +9 −0 interface/SessionManager.h
  5. +18 −12 interface/SessionManager_admin.c
@@ -28,8 +28,9 @@ while True:
for h in handles:
r = cjdns.SessionManager_sessionStats(h);
- print(PublicToIp6_convert(r['publicKey']) + ' ' + r['publicKey'] +
+ print(r['ip6'] + ' ' + r['publicKey'] +
' v' + str(r['version']) +
' dup ' + str(r['duplicates']) +
' los ' + str(r['lostPackets']) +
- ' oor ' + str(r['receivedOutOfRange']));
+ ' oor ' + str(r['receivedOutOfRange']) +
+ ' ' + r['state'].replace('CryptoAuth_', '') + ' ' + str(h));
View
@@ -159,7 +159,6 @@ uint8_t* CryptoAuth_getHerPublicKey(struct Interface* iface);
/** Reset the session's state to CryptoAuth_NEW, a new connection will be negotiated. */
void CryptoAuth_reset(struct Interface* iface);
-
/** New CryptoAuth session, has not sent or received anything. */
#define CryptoAuth_NEW 0
@@ -175,6 +174,18 @@ void CryptoAuth_reset(struct Interface* iface);
/** The CryptoAuth session has successfully done a handshake and received at least one message. */
#define CryptoAuth_ESTABLISHED 4
+static inline char* CryptoAuth_stateString(int state)
+{
+ switch (state) {
+ case CryptoAuth_NEW: return "CryptoAuth_NEW";
+ case CryptoAuth_HANDSHAKE1: return "CryptoAuth_HANDSHAKE1";
+ case CryptoAuth_HANDSHAKE2: return "CryptoAuth_HANDSHAKE2";
+ case CryptoAuth_HANDSHAKE3: return "CryptoAuth_HANDSHAKE3";
+ case CryptoAuth_ESTABLISHED: return "CryptoAuth_ESTABLISHED";
+ default: return "INVALID";
+ }
+}
+
/**
* Get the state of the CryptoAuth session.
*
@@ -91,6 +91,7 @@ static void cleanup(void* vsm)
static void check(struct SessionManager* sm, int mapIndex)
{
+ Assert_always(sm->ifaceMap.keys[mapIndex].bytes[0] == 0xfc);
uint8_t* herPubKey = CryptoAuth_getHerPublicKey(&sm->ifaceMap.values[mapIndex].iface);
if (!Bits_isZero(herPubKey, 32)) {
uint8_t ip6[16];
@@ -166,6 +167,14 @@ struct SessionManager_Session* SessionManager_sessionForHandle(uint32_t handle,
return &sm->ifaceMap.values[index];
}
+uint8_t* SessionManager_getIp6(uint32_t handle, struct SessionManager* sm)
+{
+ int index = Map_OfSessionsByIp6_indexForHandle(handle - sm->first, &sm->ifaceMap);
+ if (index < 0) { return NULL; }
+ check(sm, index);
+ return sm->ifaceMap.keys[index].bytes;
+}
+
struct SessionManager_HandleList* SessionManager_getHandleList(struct SessionManager* sm,
struct Allocator* alloc)
{
@@ -100,6 +100,15 @@ struct SessionManager_Session* SessionManager_sessionForHandle(uint32_t handle,
struct SessionManager* sm);
/**
+ * Get the IPv6 address for a session.
+ *
+ * @param handle the handle for the session
+ * @param sm the session manager
+ * @return a binary ipv6 address or NULL.
+ */
+uint8_t* SessionManager_getIp6(uint32_t handle, struct SessionManager* sm);
+
+/**
* Get the list of all handles.
*/
struct SessionManager_HandleList* SessionManager_getHandleList(struct SessionManager* sm,
@@ -59,22 +59,36 @@ static void getHandles(Dict* args, void* vcontext, String* txid, struct Allocato
Allocator_free(alloc);
}
-static void sessionStats2(Dict* args,
- struct Context* context,
- struct Allocator* alloc,
- String* txid)
+static void sessionStats(Dict* args,
+ void* vcontext,
+ String* txid,
+ struct Allocator* alloc)
{
+ struct Context* context = vcontext;
int64_t* handleP = Dict_getInt(args, String_CONST("handle"));
uint32_t handle = *handleP;
struct SessionManager_Session* session = SessionManager_sessionForHandle(handle, context->sm);
+ uint8_t* ip6 = SessionManager_getIp6(handle, context->sm);
Dict* r = Dict_new(alloc);
if (!session) {
Dict_putString(r, String_CONST("error"), String_CONST("no such session"), alloc);
Admin_sendMessage(r, txid, context->admin);
return;
}
+ // both or neither
+ Assert_always(ip6);
+
+ uint8_t printedAddr[40];
+ AddrTools_printIp(printedAddr, ip6);
+ Dict_putString(r, String_CONST("ip6"), String_new(printedAddr, alloc), alloc);
+
+ int state = CryptoAuth_getState(&session->iface);
+ Dict_putString(r,
+ String_CONST("state"),
+ String_new(CryptoAuth_stateString(state), alloc),
+ alloc);
struct ReplayProtector* rp = CryptoAuth_getReplayProtector(&session->iface);
Dict_putInt(r, String_CONST("duplicates"), rp->duplicates, alloc);
@@ -93,14 +107,6 @@ static void sessionStats2(Dict* args,
return;
}
-static void sessionStats(Dict* args, void* vcontext, String* txid, struct Allocator* requestAlloc)
-{
- struct Context* context = vcontext;
- struct Allocator* alloc = Allocator_child(context->alloc);
- sessionStats2(args, context, alloc, txid);
- Allocator_free(alloc);
-}
-
void SessionManager_admin_register(struct SessionManager* sm,
struct Admin* admin,
struct Allocator* alloc)

0 comments on commit 428d3f6

Please sign in to comment.