Respond with an error to management messages to non-existing ports

Signed-off-by: Jiri Benc <jbenc@redhat.com>
master
Jiri Benc 2014-05-02 12:37:45 +02:00 committed by Richard Cochran
parent 14742ef566
commit ba577d7123
3 changed files with 17 additions and 7 deletions

15
clock.c
View File

@ -798,7 +798,7 @@ static void clock_forward_mgmt_msg(struct clock *c, struct port *p, struct ptp_m
int clock_manage(struct clock *c, struct port *p, struct ptp_message *msg) int clock_manage(struct clock *c, struct port *p, struct ptp_message *msg)
{ {
int changed = 0, i; int changed = 0, i, res, answers;
struct management_tlv *mgt; struct management_tlv *mgt;
struct ClockIdentity *tcid, wildcard = { struct ClockIdentity *tcid, wildcard = {
{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff} {0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}
@ -883,9 +883,18 @@ int clock_manage(struct clock *c, struct port *p, struct ptp_message *msg)
clock_management_send_error(p, msg, NOT_SUPPORTED); clock_management_send_error(p, msg, NOT_SUPPORTED);
break; break;
default: default:
answers = 0;
for (i = 0; i < c->nports; i++) { for (i = 0; i < c->nports; i++) {
if (port_manage(c->port[i], p, msg)) res = port_manage(c->port[i], p, msg);
break; if (res < 0)
return changed;
if (res > 0)
answers++;
}
if (!answers) {
/* IEEE 1588 Interpretation #21 suggests to use
* WRONG_VALUE for ports that do not exist */
clock_management_send_error(p, msg, WRONG_VALUE);
} }
break; break;
} }

6
port.c
View File

@ -2198,11 +2198,11 @@ int port_manage(struct port *p, struct port *ingress, struct ptp_message *msg)
switch (management_action(msg)) { switch (management_action(msg)) {
case GET: case GET:
if (port_management_get_response(p, ingress, mgt->id, msg)) if (port_management_get_response(p, ingress, mgt->id, msg))
return 0; return 1;
break; break;
case SET: case SET:
if (port_management_set(p, ingress, mgt->id, msg)) if (port_management_set(p, ingress, mgt->id, msg))
return 0; return 1;
break; break;
case COMMAND: case COMMAND:
break; break;
@ -2234,7 +2234,7 @@ int port_manage(struct port *p, struct port *ingress, struct ptp_message *msg)
port_management_send_error(p, ingress, msg, NO_SUCH_ID); port_management_send_error(p, ingress, msg, NO_SUCH_ID);
return -1; return -1;
} }
return 0; return 1;
} }
int port_management_error(struct PortIdentity pid, struct port *ingress, int port_management_error(struct PortIdentity pid, struct port *ingress,

3
port.h
View File

@ -116,7 +116,8 @@ struct PortIdentity port_identity(struct port *p);
* @param p A pointer previously obtained via port_open(). * @param p A pointer previously obtained via port_open().
* @param ingress The port on which 'msg' was received. * @param ingress The port on which 'msg' was received.
* @param msg A management message. * @param msg A management message.
* @return Zero if the message is valid, non-zero otherwise. * @return 1 if the message was responded to, 0 if it did not apply
* to the port, -1 if it was invalid.
*/ */
int port_manage(struct port *p, struct port *ingress, struct ptp_message *msg); int port_manage(struct port *p, struct port *ingress, struct ptp_message *msg);