[Pkg-privacy-commits] [onioncat] 81/340: ETH_ALEN exchanged by ETHER_ADDR_LEN reconnecting remotely disconnected permanent peers changing name of socks-connector threads

Ximin Luo infinity0 at moszumanska.debian.org
Sat Aug 22 13:04:27 UTC 2015


This is an automated email from the git hooks/post-receive script.

infinity0 pushed a commit to branch debian
in repository onioncat.

commit a11e230360c0aa1f19555f46569dfc5770108a99
Author: eagle <eagle at 58e1ccc2-750e-0410-8d0d-f93ca75ab447>
Date:   Mon Dec 1 12:50:23 2008 +0000

    ETH_ALEN exchanged by ETHER_ADDR_LEN
    reconnecting remotely disconnected permanent peers
    changing name of socks-connector threads
    
    
    git-svn-id: http://www.cypherpunk.at/svn/onioncat/trunk@370 58e1ccc2-750e-0410-8d0d-f93ca75ab447
---
 src/ocat.h       |  5 +++--
 src/ocateth.c    | 16 ++++++++--------
 src/ocatroute.c  | 15 +++++++++++++--
 src/ocatsocks.c  | 13 ++++++++++---
 src/ocatthread.c | 20 ++++++++++++++++++++
 5 files changed, 54 insertions(+), 15 deletions(-)

diff --git a/src/ocat.h b/src/ocat.h
index 9850408..0dcc3f3 100644
--- a/src/ocat.h
+++ b/src/ocat.h
@@ -163,7 +163,7 @@ struct OcatSetup
    int config_read;
    int use_tap;
    //! local OnionCat MAC address
-   uint8_t ocat_hwaddr[ETH_ALEN];
+   uint8_t ocat_hwaddr[ETHER_ADDR_LEN];
    char *pid_file;
    char *logfn;
    FILE *logf;
@@ -256,7 +256,7 @@ typedef struct MACTable
       struct in6_addr in6addr;
       struct in_addr inaddr;
    };
-   uint8_t hwaddr[ETH_ALEN];
+   uint8_t hwaddr[ETHER_ADDR_LEN];
    time_t age;
 } MACTable_t;
 
@@ -363,6 +363,7 @@ int run_local_listeners(short, int *, int (action_accept)(int));
 const OcatThread_t *init_ocat_thread(const char *);
 int run_ocat_thread(const char *, void *(*)(void*), void*);
 const OcatThread_t *get_thread(void);
+int set_thread_name(const char *);
 
 /* ocatcompat.c */
 #ifndef HAVE_STRLCAT
diff --git a/src/ocateth.c b/src/ocateth.c
index 78b55cc..ec62cfc 100644
--- a/src/ocateth.c
+++ b/src/ocateth.c
@@ -68,7 +68,7 @@ static pthread_mutex_t mac_mutex_ = PTHREAD_MUTEX_INITIALIZER;
 
 
 /*! Convert an ethernet hardware address to a string.
- *  @param hwaddr Pointer to hardware address. Must be of len ETH_ALEN (6).
+ *  @param hwaddr Pointer to hardware address. Must be of len ETHER_ADDR_LEN (6).
  *  @param str Pointer to string. Must have at least 18 bytes!
  */
 char *mac_hw2str(const uint8_t *hwaddr, char *str)
@@ -76,7 +76,7 @@ char *mac_hw2str(const uint8_t *hwaddr, char *str)
    char *s = str;
    int i;
 
-   for (i = 0; i < ETH_ALEN; i++, str += 3, hwaddr++)
+   for (i = 0; i < ETHER_ADDR_LEN; i++, str += 3, hwaddr++)
       sprintf(str, "%02x:", *hwaddr);
    str--;
    *str = '\0';
@@ -134,7 +134,7 @@ int mac_get_mac(const struct in6_addr *in6, uint8_t *hwaddr)
    for (i = mac_cnt_ - 1; i >= 0; i--)
       if (IN6_ARE_ADDR_EQUAL(in6, &mac_tbl_[i].in6addr))
       {
-         memcpy(hwaddr, &mac_tbl_[i].hwaddr, ETH_ALEN);
+         memcpy(hwaddr, &mac_tbl_[i].hwaddr, ETHER_ADDR_LEN);
          mac_tbl_[i].age = time(NULL);
          break;
       }
@@ -154,7 +154,7 @@ int mac_add_entry(const uint8_t *hwaddr, const struct in6_addr *in6)
    if (mac_cnt_ < MAX_MAC_ENTRY)
    {
       log_debug("adding entry to MAC table %d", mac_cnt_);
-      memcpy(&mac_tbl_[mac_cnt_].hwaddr, hwaddr, ETH_ALEN);
+      memcpy(&mac_tbl_[mac_cnt_].hwaddr, hwaddr, ETHER_ADDR_LEN);
       memcpy(&mac_tbl_[mac_cnt_].in6addr, in6, sizeof(struct in6_addr));
       mac_tbl_[mac_cnt_].age = time(NULL);
       mac_tbl_[mac_cnt_].family = AF_INET6;
@@ -174,7 +174,7 @@ int mac_get_ip(const uint8_t *hwaddr, struct in6_addr *in6)
    pthread_mutex_lock(&mac_mutex_);
 
    for (i = mac_cnt_ - 1; i >= 0; i--)
-      if (!memcmp(hwaddr, &mac_tbl_[i].hwaddr, ETH_ALEN))
+      if (!memcmp(hwaddr, &mac_tbl_[i].hwaddr, ETHER_ADDR_LEN))
       {
          memcpy(in6, &mac_tbl_[i].in6addr, sizeof(struct in6_addr));
          mac_tbl_[i].age = time(NULL);
@@ -346,8 +346,8 @@ int ndp_solicit(char *buf, int rlen)
          log_msg(LOG_ERR, "MAC table full");
          return -1;
       }
-   memcpy(eh->ether_dhost, eh->ether_shost, ETH_ALEN);
-   memcpy(eh->ether_shost, CNF(ocat_hwaddr), ETH_ALEN);
+   memcpy(eh->ether_dhost, eh->ether_shost, ETHER_ADDR_LEN);
+   memcpy(eh->ether_shost, CNF(ocat_hwaddr), ETHER_ADDR_LEN);
 
    // init ip6 header
    memcpy(&ip6->ip6_dst, &ip6->ip6_src, sizeof(struct in6_addr));
@@ -359,7 +359,7 @@ int ndp_solicit(char *buf, int rlen)
    nda->nd_na_hdr.icmp6_cksum = 0;
    nda->nd_na_flags_reserved = ND_NA_FLAG_SOLICITED;
    ohd->nd_opt_type = ND_OPT_TARGET_LINKADDR;
-   memcpy(ohd + 1, CNF(ocat_hwaddr), ETH_ALEN);
+   memcpy(ohd + 1, CNF(ocat_hwaddr), ETHER_ADDR_LEN);
 
    ckb = malloc_ckbuf(&ip6->ip6_src, &ip6->ip6_dst, ntohs(ip6->ip6_plen), IPPROTO_ICMPV6, icmp6);
    nda->nd_na_hdr.icmp6_cksum = checksum(ckb, ntohs(ip6->ip6_plen) + sizeof(struct ip6_psh));
diff --git a/src/ocatroute.c b/src/ocatroute.c
index 5c8dfaa..9218d94 100644
--- a/src/ocatroute.c
+++ b/src/ocatroute.c
@@ -360,16 +360,27 @@ void *socket_receiver(void *p)
             unlock_peer(peer);
             continue;
          }
+
          log_debug("received %d bytes on %d", len, peer->tcpfd);
          // if len == 0 EOF reached => close session
          if (!len)
          {
             log_msg(LOG_INFO | LOG_FCONN, "fd %d reached EOF, closing.", peer->tcpfd);
             oe_close(peer->tcpfd);
+            // restart connection of permanent peers
+            if (peer->perm)
+            {
+               log_debug("reconnection permanent peer");
+               socks_queue(&peer->addr, 1);
+            }
             unlock_peer(peer);
+
+            // deleting peer
+            // FIXME: there might be a race-condition with restarted permanent peers
             lock_peers();
             delete_peer(peer);
             unlock_peers();
+
             continue;
          }
 
@@ -481,7 +492,7 @@ void *socket_receiver(void *p)
                   {
                      *((uint32_t*) buf) = *peer->tunhdr;
                      memcpy(buf + 4 + sizeof(struct ether_header), peer->fragbuf, len);
-                     memcpy(eh->ether_shost, CNF(ocat_hwaddr), ETH_ALEN);
+                     memcpy(eh->ether_shost, CNF(ocat_hwaddr), ETHER_ADDR_LEN);
 
                      if (*peer->tunhdr == CNF(fhd_key[IPV6_KEY]))
                         eh->ether_type = htons(ETHERTYPE_IPV6);
@@ -763,7 +774,7 @@ void packet_forwarder(void)
       // in case of TAP device handle ethernet header
       if (CNF(use_tap))
       {
-         if (!memcmp(eh->ether_dhost, CNF(ocat_hwaddr), ETH_ALEN))
+         if (!memcmp(eh->ether_dhost, CNF(ocat_hwaddr), ETHER_ADDR_LEN))
             // remove ethernet header from buffer
             // FIXME: it would be better to adjust pointers instead of moving data
             memmove(eh, eh + 1, rlen - 4 - sizeof(struct ether_header));
diff --git a/src/ocatsocks.c b/src/ocatsocks.c
index 1a18a28..b4630d7 100644
--- a/src/ocatsocks.c
+++ b/src/ocatsocks.c
@@ -138,7 +138,6 @@ void socks_queue(const struct in6_addr *addr, int perm)
 
    pthread_mutex_lock(&socks_queue_mutex_);
    for (squeue = socks_queue_; squeue; squeue = squeue->next)
-      //if (!memcmp(&squeue->addr, addr, sizeof(struct in6_addr)))
       if (IN6_ARE_ADDR_EQUAL(&squeue->addr, addr))
          break;
    if (!squeue)
@@ -164,6 +163,7 @@ void *socks_connector(void *p)
    OcatPeer_t *peer;
    SocksQueue_t **squeue, *sq;
    int i, rc, ps, run = 1;
+   char thn[THREAD_NAME_LEN] = "cn:", on[17];
 
    if ((rc = pthread_detach(pthread_self())))
       log_msg(LOG_ERR, "couldn't detach: \"%s\"", rc);
@@ -191,6 +191,11 @@ void *socks_connector(void *p)
          run_ocat_thread("connector", socks_connector, NULL);
       pthread_mutex_unlock(&socks_queue_mutex_);
 
+      // changing thread name
+      ipv6tonion(&(*squeue)->addr, on);
+      strlcat(thn, on, THREAD_NAME_LEN);
+      set_thread_name(thn);
+
       // search for existing peer
       lock_peers();
       peer = search_peer(&(*squeue)->addr);
@@ -198,9 +203,11 @@ void *socks_connector(void *p)
 
       // connect via SOCKS if no peer exists
       if (!peer)
-         for (i = 0, ps = -1; i < SOCKS_MAX_RETRY && ps < 0; i++)
+         for (i = 0, ps = -1; ((i < SOCKS_MAX_RETRY) || (*squeue)->perm) && ps < 0; i++)
+         {
+            log_debug("%d. SOCKS connection attempt", i + 1);
             ps = socks_connect(*squeue);
-            //ps = socks_connect(&(*squeue)->addr);
+         }
       else
          log_msg(LOG_INFO, "peer already exists, ignoring");
 
diff --git a/src/ocatthread.c b/src/ocatthread.c
index eb78be0..ab95a6f 100644
--- a/src/ocatthread.c
+++ b/src/ocatthread.c
@@ -141,3 +141,23 @@ const OcatThread_t *get_thread(void)
    return th;
 }
 
+
+int set_thread_name(const char *n)
+{
+   int e = -1;
+   OcatThread_t *th;
+   pthread_t thread = pthread_self();
+
+   pthread_mutex_lock(&thread_mutex_);
+   for (th = octh_; th; th = th->next)
+      if (th->handle == thread)
+      {
+         strlcpy(th->name, n, THREAD_NAME_LEN);
+         e = 0;
+         break;
+      }
+   pthread_mutex_unlock(&thread_mutex_);
+
+   return e;
+}
+

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-privacy/packages/onioncat.git



More information about the Pkg-privacy-commits mailing list