add CMD support to the PMC to allow for new command to rekey the security 
associations.

Signed-off-by: Clay Kaiser <clay.kai...@ibm.com>
---
 clock.c      | 24 ++++++++++++++++++++++++
 pmc_common.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++
 pmc_common.h |  2 ++
 tlv.h        |  1 +
 4 files changed, 78 insertions(+)

diff --git a/clock.c b/clock.c
index 5a64613..51c779b 100644
--- a/clock.c
+++ b/clock.c
@@ -36,6 +36,7 @@
 #include "msg.h"
 #include "phc.h"
 #include "port.h"
+#include "sad.h"
 #include "servo.h"
 #include "stats.h"
 #include "print.h"
@@ -577,6 +578,9 @@ static int clock_management_fill_response(struct clock *c, 
struct port *p,
                mtd->val = c->local_sync_uncertain;
                datalen = sizeof(*mtd);
                break;
+       case MID_SA_REKEY_NP:
+               datalen = 0;
+               break;
        default:
                /* The caller should *not* respond to this message. */
                tlv_extra_recycle(extra);
@@ -711,6 +715,24 @@ static int clock_management_set(struct clock *c, struct 
port *p,
        return respond ? 1 : 0;
 }
 
+static int clock_management_cmd(struct clock *c, struct port *p,
+                               int id, struct ptp_message *req, int *changed)
+{
+       int respond = 0;
+
+       switch (id) {
+       case MID_SA_REKEY_NP:
+               if (!sad_create(c->config)) {
+                       *changed = 1;
+                       respond = 1;
+               }
+       }
+
+       if (respond && !clock_management_get_response(c, p, id, req))
+               pr_err("failed to send management set response");
+       return respond ? 1 : 0;
+}
+
 static void clock_stats_update(struct clock_stats *s,
                               double offset, double freq)
 {
@@ -1650,6 +1672,8 @@ int clock_manage(struct clock *c, struct port *p, struct 
ptp_message *msg)
                        clock_management_send_error(p, msg, MID_NOT_SUPPORTED);
                        return changed;
                }
+               if (clock_management_cmd(c, p, mgt->id, msg, &changed))
+                       return changed;
                break;
        default:
                return changed;
diff --git a/pmc_common.c b/pmc_common.c
index 9e251c4..59e4488 100644
--- a/pmc_common.c
+++ b/pmc_common.c
@@ -77,6 +77,7 @@
 
 static void do_get_action(struct pmc *pmc, int action, int index, char *str);
 static void do_set_action(struct pmc *pmc, int action, int index, char *str);
+static void do_cmd_action(struct pmc *pmc, int action, int index, char *str);
 static void not_supported(struct pmc *pmc, int action, int index, char *str);
 static void null_management(struct pmc *pmc, int action, int index, char *str);
 
@@ -131,6 +132,7 @@ struct management_id idtab[] = {
        { "GRANDMASTER_SETTINGS_NP", MID_GRANDMASTER_SETTINGS_NP, do_set_action 
},
        { "SUBSCRIBE_EVENTS_NP", MID_SUBSCRIBE_EVENTS_NP, do_set_action },
        { "SYNCHRONIZATION_UNCERTAIN_NP", MID_SYNCHRONIZATION_UNCERTAIN_NP, 
do_set_action },
+       { "SA_REKEY_NP", MID_SA_REKEY_NP, do_cmd_action },
 /* Port management ID values */
        { "NULL_MANAGEMENT", MID_NULL_MANAGEMENT, null_management },
        { "CLOCK_DESCRIPTION", MID_CLOCK_DESCRIPTION, do_get_action },
@@ -388,6 +390,30 @@ static void do_set_action(struct pmc *pmc, int action, int 
index, char *str)
        }
 }
 
+static void do_cmd_action(struct pmc *pmc, int action, int index, char *str)
+{
+       int code = idtab[index].code;
+
+       switch (action) {
+       case COMMAND:
+               break;
+       case GET:
+       case SET:
+       case RESPONSE:
+       case ACKNOWLEDGE:
+       default:
+               fprintf(stderr, "%s only allows COMMAND\n",
+                       idtab[index].name);
+               return;
+       }
+
+       switch (code) {
+       case MID_SA_REKEY_NP:
+               pmc_send_cmd_action(pmc, code);
+               break;
+       }
+}
+
 static void not_supported(struct pmc *pmc, int action, int index, char *str)
 {
        fprintf(stdout, "sorry, %s not supported yet\n", idtab[index].name);
@@ -795,6 +821,31 @@ int pmc_send_set_aton(struct pmc *pmc, int id, uint8_t 
key, const char *name)
        return 0;
 }
 
+int pmc_send_cmd_action(struct pmc *pmc, int id)
+{
+       struct management_tlv *mgt;
+       struct ptp_message *msg;
+       struct tlv_extra *extra;
+
+       msg = pmc_message(pmc, COMMAND);
+       if (!msg) {
+               return -1;
+       }
+       extra = msg_tlv_append(msg, sizeof(*mgt));
+       if (!extra) {
+               msg_put(msg);
+               return -ENOMEM;
+       }
+       mgt = (struct management_tlv *) extra->tlv;
+       mgt->type = TLV_MANAGEMENT;
+       mgt->length = 2;
+       mgt->id = id;
+       pmc_send(pmc, msg);
+       msg_put(msg);
+
+       return 0;
+}
+
 struct ptp_message *pmc_recv(struct pmc *pmc)
 {
        struct ptp_message *msg;
diff --git a/pmc_common.h b/pmc_common.h
index 6fb2fae..3add048 100644
--- a/pmc_common.h
+++ b/pmc_common.h
@@ -43,6 +43,8 @@ int pmc_send_set_action(struct pmc *pmc, int id, void *data, 
int datasize);
 
 int pmc_send_set_aton(struct pmc *pmc, int id, uint8_t key, const char *name);
 
+int pmc_send_cmd_action(struct pmc *pmc, int id);
+
 struct ptp_message *pmc_recv(struct pmc *pmc);
 
 int pmc_target(struct pmc *pmc, struct PortIdentity *pid);
diff --git a/tlv.h b/tlv.h
index 1beaac1..362778a 100644
--- a/tlv.h
+++ b/tlv.h
@@ -100,6 +100,7 @@ enum management_action {
 #define MID_GRANDMASTER_SETTINGS_NP                    0xC001
 #define MID_SUBSCRIBE_EVENTS_NP                                0xC003
 #define MID_SYNCHRONIZATION_UNCERTAIN_NP               0xC006
+#define MID_SA_REKEY_NP                                        0xC00B
 
 /* Port management ID values */
 #define MID_NULL_MANAGEMENT                            0x0000
-- 
2.42.1



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

Reply via email to