On Mon, Mar 24, 2014 at 09:53:43AM +0100, Jiri Benc wrote:
> Require subscriptions to be renewed regularly. This way, the subscription
> automatically times out when phc2sys is killed.
> 
> Signed-off-by: Jiri Benc <jb...@redhat.com>
> ---
>  clock.c   |   24 ++++++++++++++++++++++++
>  phc2sys.c |   10 ++++++----
>  2 files changed, 30 insertions(+), 4 deletions(-)
> 
> diff --git a/clock.c b/clock.c
> index c893a58391ce..d9ee6c4c77e2 100644
> --- a/clock.c
> +++ b/clock.c
> @@ -68,6 +68,7 @@ struct clock_subscriber {
>       uint8_t addr[TRANSPORT_RECV_ADDR_LEN];
>       int addrlen;
>       UInteger16 sequenceId;
> +     time_t subscribed;

Make this "expiration" instead, and then we can implement 1588 unicast
in the same way...

>  };
>  
>  struct clock {
> @@ -142,6 +143,7 @@ static void clock_update_subscription(struct clock *c, 
> struct ptp_message *req,
>       uint8_t addr[TRANSPORT_RECV_ADDR_LEN];
>       int addrlen;
>       struct clock_subscriber *s;
> +     struct timespec now;
>  
>       addrlen = port_recv_addr(uds, addr);
>       if (!addrlen) {
> @@ -157,6 +159,8 @@ static void clock_update_subscription(struct clock *c, 
> struct ptp_message *req,
>                               memcpy(s->addr, addr, addrlen);
>                               s->addrlen = addrlen;
>                               s->events = events;
> +                             clock_gettime(CLOCK_MONOTONIC, &now);
> +                             s->subscribed = now.tv_sec;
>                       } else {
>                               remove_subscriber(s);
>                       }
> @@ -175,6 +179,8 @@ static void clock_update_subscription(struct clock *c, 
> struct ptp_message *req,
>       memcpy(s->addr, addr, addrlen);
>       s->addrlen = addrlen;
>       s->events = events;
> +     clock_gettime(CLOCK_MONOTONIC, &now);
> +     s->subscribed = now.tv_sec;
>       s->sequenceId = 0;
>       LIST_INSERT_HEAD(&c->subscribers, s, list);
>  }
> @@ -188,6 +194,23 @@ static void clock_flush_subscriptions(struct clock *c)
>       }
>  }
>  
> +static void clock_prune_subscriptions(struct clock *c)
> +{
> +     struct clock_subscriber *s, *tmp;
> +     struct timespec now;
> +
> +     clock_gettime(CLOCK_MONOTONIC, &now);
> +     LIST_FOREACH_SAFE(s, &c->subscribers, list, tmp) {
> +             /* prune subscribers older than 3 minutes */
> +             if (s->subscribed + 180 < now.tv_sec) {

and you won't need a hard coded magic number here.

> +                     pr_info("subscriber %s timed out (not renewed in %ld 
> seconds)",
> +                             pid2str(&s->targetPortIdentity),
> +                             now.tv_sec - s->subscribed);
> +                     remove_subscriber(s);
> +             }
> +     }
> +}
> +

Thanks,
Richard

------------------------------------------------------------------------------
_______________________________________________
Linuxptp-devel mailing list
Linuxptp-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linuxptp-devel

Reply via email to