From 21c2fe30c7b9b3eed9ce0a49c02ed8923fd74c26 Mon Sep 17 00:00:00 2001 From: Richard Cochran Date: Thu, 2 Aug 2012 06:36:07 +0200 Subject: [PATCH] Provide a method to send a management error status message. Signed-off-by: Richard Cochran --- port.c | 32 ++++++++++++++++++++++++++++++++ port.h | 11 +++++++++++ tlv.h | 2 ++ 3 files changed, 45 insertions(+) diff --git a/port.c b/port.c index e9e2cf9..385f00c 100644 --- a/port.c +++ b/port.c @@ -1390,6 +1390,38 @@ int port_manage(struct port *p, struct port *ingress, struct ptp_message *msg) return 0; } +int port_managment_error(struct PortIdentity pid, struct port *ingress, + struct ptp_message *req, Enumeration16 error_id) +{ + struct ptp_message *msg; + struct management_tlv *mgt; + struct management_error_status *mes; + int err = 0, pdulen; + + msg = port_management_reply(pid, ingress, req); + if (!msg) { + return -1; + } + mgt = (struct management_tlv *) req->management.suffix; + mes = (struct management_error_status *) msg->management.suffix; + mes->type = TLV_MANAGEMENT_ERROR_STATUS; + mes->length = 8; + mes->error = error_id; + mes->id = mgt->id; + pdulen = msg->header.messageLength + sizeof(*mes); + msg->header.messageLength = pdulen; + msg->tlv_count = 1; + + err = msg_pre_send(msg); + if (err) { + goto out; + } + err = port_forward(ingress, msg, pdulen); +out: + msg_put(msg); + return err; +} + struct ptp_message *port_management_reply(struct PortIdentity pid, struct port *ingress, struct ptp_message *req) diff --git a/port.h b/port.h index 6e7c25e..3e2b1c7 100644 --- a/port.h +++ b/port.h @@ -97,6 +97,17 @@ int port_forward(struct port *p, struct ptp_message *msg, int msglen); */ int port_manage(struct port *p, struct port *ingress, struct ptp_message *msg); +/** + * Send a management error status message. + * @param pid The id of the responding port. + * @param ingress Port on which the 'req' was received. + * @param req The management message which triggered the error. + * @param error_id One of the management error ID values. + * @return Zero on success, non-zero otherwise. + */ +int port_managment_error(struct PortIdentity pid, struct port *ingress, + struct ptp_message *req, Enumeration16 error_id); + /** * Allocate a reply to a management message. * diff --git a/tlv.h b/tlv.h index b34679a..5256e3d 100644 --- a/tlv.h +++ b/tlv.h @@ -21,6 +21,8 @@ #define HAVE_TLV_H #include "ddt.h" +#include "msg.h" +#include "port.h" /* TLV types */ #define TLV_MANAGEMENT 0x0001