On Mon, Mar 24, 2014 at 09:53:27AM +0100, Jiri Benc wrote:
> Used to enumerate all ports. With the future dynamic port adding/removal,
> there may be holes in the port number sequence. For now, just fill it with
> the sequence numbers.
> 
> Signed-off-by: Jiri Benc <jb...@redhat.com>
> ---
>  clock.c |   16 ++++++++++++++++
>  tlv.c   |   29 +++++++++++++++++++++++++++++
>  tlv.h   |    6 ++++++
>  3 files changed, 51 insertions(+), 0 deletions(-)
> 
> diff --git a/clock.c b/clock.c
> index 010262f522e3..2e7794cc07cd 100644
> --- a/clock.c
> +++ b/clock.c
> @@ -381,6 +381,21 @@ static int clock_management_fill_response(struct clock 
> *c,
>               datalen = sizeof(*gsn);
>               respond = 1;
>               break;
> +     case PORT_ENUMERATION_NP:
> +             {

No braces, please.

> +                     struct port_enumeration_np *pen;
> +                     int i;
> +
> +                     if (c->nports > 720)
> +                             break;
> +                     pen = (struct port_enumeration_np *)tlv->data;
> +                     pen->numberPorts = c->nports;
> +                     for (i = 0; i < c->nports; i++)
> +                             pen->portNumber[i] = i + 1;
> +                     datalen = sizeof(*pen) + pen->numberPorts * 
> sizeof(UInteger16);
> +                     respond = 1;
> +             }
> +             break;
>       }
>       if (respond) {
>               if (datalen % 2) {
> @@ -1030,6 +1045,7 @@ int clock_manage(struct clock *c, struct port *p, 
> struct ptp_message *msg)
>       case TIME_STATUS_NP:
>       case GRANDMASTER_SETTINGS_NP:
>       case SUBSCRIBE_EVENTS_NP:
> +     case PORT_ENUMERATION_NP:
>               clock_management_send_error(p, msg, NOT_SUPPORTED);
>               break;
>       default:
> diff --git a/tlv.c b/tlv.c
> index 352026ee5f7a..8d635c452905 100644
> --- a/tlv.c
> +++ b/tlv.c
> @@ -252,6 +252,24 @@ static int mgt_post_recv(struct management_tlv *m, 
> uint16_t data_len,
>                       sen->bitmask = ntohl(sen->bitmask);
>               }
>               break;
> +     case PORT_ENUMERATION_NP:
> +             {

Same.

> +                     struct port_enumeration_np *pen;
> +                     size_t expected_len;
> +                     int i;
> +
> +                     if (data_len < sizeof(struct port_enumeration_np))
> +                             goto bad_length;
> +                     pen = (struct port_enumeration_np *)m->data;
> +                     pen->numberPorts = ntohs(pen->numberPorts);
> +                     expected_len = sizeof(struct port_enumeration_np) +
> +                                    pen->numberPorts * sizeof(UInteger16);
> +                     if (data_len != expected_len)
> +                             goto bad_length;
> +                     for (i = 0; i < pen->numberPorts; i++)
> +                             pen->portNumber[i] = ntohs(pen->portNumber[i]);
> +             }
> +             break;
>       case SAVE_IN_NON_VOLATILE_STORAGE:
>       case RESET_NON_VOLATILE_STORAGE:
>       case INITIALIZE:
> @@ -355,6 +373,17 @@ static void mgt_pre_send(struct management_tlv *m, 
> struct tlv_extra *extra)
>                       sen->bitmask = htonl(sen->bitmask);
>               }
>               break;
> +     case PORT_ENUMERATION_NP:
> +             {

Same.

> +                     struct port_enumeration_np *pen;
> +                     int i;
> +
> +                     pen = (struct port_enumeration_np *)m->data;
> +                     for (i = 0; i < pen->numberPorts; i++)
> +                             pen->portNumber[i] = htons(pen->portNumber[i]);
> +                     pen->numberPorts = htons(pen->numberPorts);
> +             }
> +             break;
>       }
>  }
>  
> diff --git a/tlv.h b/tlv.h
> index 8eb840685a81..dffdabda7d09 100644
> --- a/tlv.h
> +++ b/tlv.h
> @@ -80,6 +80,7 @@ enum management_action {
>  #define TIME_STATUS_NP                                       0xC000
>  #define GRANDMASTER_SETTINGS_NP                              0xC001
>  #define SUBSCRIBE_EVENTS_NP                          0xC003
> +#define PORT_ENUMERATION_NP                          0xC004
>  
>  /* Port management ID values */
>  #define NULL_MANAGEMENT                                      0x0000
> @@ -201,6 +202,11 @@ struct subscribe_events_np {
>       UInteger32    bitmask;
>  } PACKED;
>  
> +struct port_enumeration_np {
> +     UInteger16 numberPorts;
> +     UInteger16 portNumber[0];
> +} PACKED;
> +

I don't like this variable sized message. We should stick to fixed
sized items. Why do we need this at all?

BTW, regarding your dynamic port work, have you seen 1588
Interpretation 21?

Thanks,
Richard

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

Reply via email to