ovs-ofctl: Add "packet-out" command.
[sliver-openvswitch.git] / lib / learn.c
1 /*
2  * Copyright (c) 2011, 2012 Nicira Networks.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at:
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #include <config.h>
18
19 #include "learn.h"
20
21 #include "byte-order.h"
22 #include "dynamic-string.h"
23 #include "meta-flow.h"
24 #include "nx-match.h"
25 #include "ofp-errors.h"
26 #include "ofp-util.h"
27 #include "ofpbuf.h"
28 #include "openflow/openflow.h"
29 #include "unaligned.h"
30
31 static ovs_be16
32 get_be16(const void **pp)
33 {
34     const ovs_be16 *p = *pp;
35     ovs_be16 value = *p;
36     *pp = p + 1;
37     return value;
38 }
39
40 static ovs_be32
41 get_be32(const void **pp)
42 {
43     const ovs_be32 *p = *pp;
44     ovs_be32 value = get_unaligned_be32(p);
45     *pp = p + 1;
46     return value;
47 }
48
49 static uint64_t
50 get_bits(int n_bits, const void **p)
51 {
52     int n_segs = DIV_ROUND_UP(n_bits, 16);
53     uint64_t value;
54
55     value = 0;
56     while (n_segs-- > 0) {
57         value = (value << 16) | ntohs(get_be16(p));
58     }
59     return value;
60 }
61
62 static void
63 get_subfield(int n_bits, const void **p, struct mf_subfield *sf)
64 {
65     sf->field = mf_from_nxm_header(ntohl(get_be32(p)));
66     sf->ofs = ntohs(get_be16(p));
67     sf->n_bits = n_bits;
68 }
69
70 static unsigned int
71 learn_min_len(uint16_t header)
72 {
73     int n_bits = header & NX_LEARN_N_BITS_MASK;
74     int src_type = header & NX_LEARN_SRC_MASK;
75     int dst_type = header & NX_LEARN_DST_MASK;
76     unsigned int min_len;
77
78     min_len = 0;
79     if (src_type == NX_LEARN_SRC_FIELD) {
80         min_len += sizeof(ovs_be32); /* src_field */
81         min_len += sizeof(ovs_be16); /* src_ofs */
82     } else {
83         min_len += DIV_ROUND_UP(n_bits, 16);
84     }
85     if (dst_type == NX_LEARN_DST_MATCH ||
86         dst_type == NX_LEARN_DST_LOAD) {
87         min_len += sizeof(ovs_be32); /* dst_field */
88         min_len += sizeof(ovs_be16); /* dst_ofs */
89     }
90     return min_len;
91 }
92
93 static enum ofperr
94 learn_check_header(uint16_t header, size_t len)
95 {
96     int src_type = header & NX_LEARN_SRC_MASK;
97     int dst_type = header & NX_LEARN_DST_MASK;
98
99     /* Check for valid src and dst type combination. */
100     if (dst_type == NX_LEARN_DST_MATCH ||
101         dst_type == NX_LEARN_DST_LOAD ||
102         (dst_type == NX_LEARN_DST_OUTPUT &&
103          src_type == NX_LEARN_SRC_FIELD)) {
104         /* OK. */
105     } else {
106         return OFPERR_OFPBAC_BAD_ARGUMENT;
107     }
108
109     /* Check that the arguments don't overrun the end of the action. */
110     if (len < learn_min_len(header)) {
111         return OFPERR_OFPBAC_BAD_LEN;
112     }
113
114     return 0;
115 }
116
117 /* Checks that 'learn' (which must be at least 'sizeof *learn' bytes long) is a
118  * valid action on 'flow'. */
119 enum ofperr
120 learn_check(const struct nx_action_learn *learn, const struct flow *flow)
121 {
122     struct cls_rule rule;
123     const void *p, *end;
124
125     cls_rule_init_catchall(&rule, 0);
126
127     if (learn->flags & ~htons(OFPFF_SEND_FLOW_REM)
128         || !is_all_zeros(learn->pad, sizeof learn->pad)
129         || learn->table_id == 0xff) {
130         return OFPERR_OFPBAC_BAD_ARGUMENT;
131     }
132
133     end = (char *) learn + ntohs(learn->len);
134     for (p = learn + 1; p != end; ) {
135         uint16_t header = ntohs(get_be16(&p));
136         int n_bits = header & NX_LEARN_N_BITS_MASK;
137         int src_type = header & NX_LEARN_SRC_MASK;
138         int dst_type = header & NX_LEARN_DST_MASK;
139
140         enum ofperr error;
141         uint64_t value;
142
143         if (!header) {
144             break;
145         }
146
147         error = learn_check_header(header, (char *) end - (char *) p);
148         if (error) {
149             return error;
150         }
151
152         /* Check the source. */
153         if (src_type == NX_LEARN_SRC_FIELD) {
154             struct mf_subfield src;
155
156             get_subfield(n_bits, &p, &src);
157             error = mf_check_src(&src, flow);
158             if (error) {
159                 return error;
160             }
161             value = 0;
162         } else {
163             value = get_bits(n_bits, &p);
164         }
165
166         /* Check the destination. */
167         if (dst_type == NX_LEARN_DST_MATCH || dst_type == NX_LEARN_DST_LOAD) {
168             struct mf_subfield dst;
169
170             get_subfield(n_bits, &p, &dst);
171             error = (dst_type == NX_LEARN_DST_LOAD
172                      ? mf_check_dst(&dst, &rule.flow)
173                      : mf_check_src(&dst, &rule.flow));
174             if (error) {
175                 return error;
176             }
177
178             if (dst_type == NX_LEARN_DST_MATCH
179                 && src_type == NX_LEARN_SRC_IMMEDIATE) {
180                 mf_set_subfield(&dst, value, &rule);
181             }
182         }
183     }
184     if (!is_all_zeros(p, (char *) end - (char *) p)) {
185         return OFPERR_OFPBAC_BAD_ARGUMENT;
186     }
187
188     return 0;
189 }
190
191 void
192 learn_execute(const struct nx_action_learn *learn, const struct flow *flow,
193               struct ofputil_flow_mod *fm)
194 {
195     const void *p, *end;
196     struct ofpbuf actions;
197
198     cls_rule_init_catchall(&fm->cr, ntohs(learn->priority));
199     fm->cookie = learn->cookie;
200     fm->table_id = learn->table_id;
201     fm->command = OFPFC_MODIFY_STRICT;
202     fm->idle_timeout = ntohs(learn->idle_timeout);
203     fm->hard_timeout = ntohs(learn->hard_timeout);
204     fm->buffer_id = UINT32_MAX;
205     fm->out_port = OFPP_NONE;
206     fm->flags = ntohs(learn->flags) & OFPFF_SEND_FLOW_REM;
207     fm->actions = NULL;
208     fm->n_actions = 0;
209
210     ofpbuf_init(&actions, 64);
211
212     for (p = learn + 1, end = (char *) learn + ntohs(learn->len); p != end; ) {
213         uint16_t header = ntohs(get_be16(&p));
214         int n_bits = header & NX_LEARN_N_BITS_MASK;
215         int src_type = header & NX_LEARN_SRC_MASK;
216         int dst_type = header & NX_LEARN_DST_MASK;
217         uint64_t value;
218
219         struct nx_action_reg_load *load;
220         struct mf_subfield dst;
221
222         if (!header) {
223             break;
224         }
225
226         if (src_type == NX_LEARN_SRC_FIELD) {
227             struct mf_subfield src;
228
229             get_subfield(n_bits, &p, &src);
230             value = mf_get_subfield(&src, flow);
231         } else {
232             value = get_bits(n_bits, &p);
233         }
234
235         switch (dst_type) {
236         case NX_LEARN_DST_MATCH:
237             get_subfield(n_bits, &p, &dst);
238             mf_set_subfield(&dst, value, &fm->cr);
239             break;
240
241         case NX_LEARN_DST_LOAD:
242             get_subfield(n_bits, &p, &dst);
243             load = ofputil_put_NXAST_REG_LOAD(&actions);
244             load->ofs_nbits = nxm_encode_ofs_nbits(dst.ofs, dst.n_bits);
245             load->dst = htonl(dst.field->nxm_header);
246             load->value = htonll(value);
247             break;
248
249         case NX_LEARN_DST_OUTPUT:
250             ofputil_put_OFPAT_OUTPUT(&actions)->port = htons(value);
251             break;
252         }
253     }
254
255     fm->actions = ofpbuf_steal_data(&actions);
256     fm->n_actions = actions.size / sizeof(struct ofp_action_header);
257 }
258
259 static void
260 put_be16(struct ofpbuf *b, ovs_be16 x)
261 {
262     ofpbuf_put(b, &x, sizeof x);
263 }
264
265 static void
266 put_be32(struct ofpbuf *b, ovs_be32 x)
267 {
268     ofpbuf_put(b, &x, sizeof x);
269 }
270
271 static void
272 put_u16(struct ofpbuf *b, uint16_t x)
273 {
274     put_be16(b, htons(x));
275 }
276
277 static void
278 put_u32(struct ofpbuf *b, uint32_t x)
279 {
280     put_be32(b, htonl(x));
281 }
282
283 struct learn_spec {
284     int n_bits;
285
286     int src_type;
287     struct mf_subfield src;
288     uint8_t src_imm[sizeof(union mf_value)];
289
290     int dst_type;
291     struct mf_subfield dst;
292 };
293
294 static void
295 learn_parse_spec(const char *orig, char *name, char *value,
296                  struct learn_spec *spec)
297 {
298     memset(spec, 0, sizeof *spec);
299     if (mf_from_name(name)) {
300         const struct mf_field *dst = mf_from_name(name);
301         union mf_value imm;
302         char *error;
303
304         error = mf_parse_value(dst, value, &imm);
305         if (error) {
306             ovs_fatal(0, "%s", error);
307         }
308
309         spec->n_bits = dst->n_bits;
310         spec->src_type = NX_LEARN_SRC_IMMEDIATE;
311         memcpy(spec->src_imm, &imm, dst->n_bytes);
312         spec->dst_type = NX_LEARN_DST_MATCH;
313         spec->dst.field = dst;
314         spec->dst.ofs = 0;
315         spec->dst.n_bits = dst->n_bits;
316     } else if (strchr(name, '[')) {
317         /* Parse destination and check prerequisites. */
318         if (mf_parse_subfield(&spec->dst, name)[0] != '\0') {
319             ovs_fatal(0, "%s: syntax error after NXM field name `%s'",
320                       orig, name);
321         }
322
323         /* Parse source and check prerequisites. */
324         if (value[0] != '\0') {
325             if (mf_parse_subfield(&spec->src, value)[0] != '\0') {
326                 ovs_fatal(0, "%s: syntax error after NXM field name `%s'",
327                           orig, value);
328             }
329             if (spec->src.n_bits != spec->dst.n_bits) {
330                 ovs_fatal(0, "%s: bit widths of %s (%u) and %s (%u) differ",
331                           orig, name, spec->src.n_bits, value,
332                           spec->dst.n_bits);
333             }
334         } else {
335             spec->src = spec->dst;
336         }
337
338         spec->n_bits = spec->src.n_bits;
339         spec->src_type = NX_LEARN_SRC_FIELD;
340         spec->dst_type = NX_LEARN_DST_MATCH;
341     } else if (!strcmp(name, "load")) {
342         if (value[strcspn(value, "[-")] == '-') {
343             struct nx_action_reg_load load;
344             int nbits, imm_bytes;
345             uint64_t imm;
346             int i;
347
348             nxm_parse_reg_load(&load, value);
349             nbits = nxm_decode_n_bits(load.ofs_nbits);
350             imm_bytes = DIV_ROUND_UP(nbits, 8);
351             imm = ntohll(load.value);
352
353             spec->n_bits = nbits;
354             spec->src_type = NX_LEARN_SRC_IMMEDIATE;
355             for (i = 0; i < imm_bytes; i++) {
356                 spec->src_imm[i] = imm >> ((imm_bytes - i - 1) * 8);
357             }
358             spec->dst_type = NX_LEARN_DST_LOAD;
359             nxm_decode(&spec->dst, load.dst, load.ofs_nbits);
360         } else {
361             struct nx_action_reg_move move;
362
363             nxm_parse_reg_move(&move, value);
364
365             spec->n_bits = ntohs(move.n_bits);
366             spec->src_type = NX_LEARN_SRC_FIELD;
367             nxm_decode_discrete(&spec->src,
368                                 move.src, move.src_ofs, move.n_bits);
369             spec->dst_type = NX_LEARN_DST_LOAD;
370             nxm_decode_discrete(&spec->dst,
371                                 move.dst, move.dst_ofs, move.n_bits);
372         }
373     } else if (!strcmp(name, "output")) {
374         if (mf_parse_subfield(&spec->src, value)[0] != '\0') {
375             ovs_fatal(0, "%s: syntax error after NXM field name `%s'",
376                       orig, name);
377         }
378
379         spec->n_bits = spec->src.n_bits;
380         spec->src_type = NX_LEARN_SRC_FIELD;
381         spec->dst_type = NX_LEARN_DST_OUTPUT;
382     } else {
383         ovs_fatal(0, "%s: unknown keyword %s", orig, name);
384     }
385 }
386
387 /* Parses 'arg' as a set of arguments to the "learn" action and appends a
388  * matching NXAST_LEARN action to 'b'.  The format parsed is described in
389  * ovs-ofctl(8).
390  *
391  * Prints an error on stderr and aborts the program if 'arg' syntax is invalid.
392  *
393  * If 'flow' is nonnull, then it should be the flow from a cls_rule that is
394  * the matching rule for the learning action.  This helps to better validate
395  * the action's arguments.
396  *
397  * Modifies 'arg'. */
398 void
399 learn_parse(struct ofpbuf *b, char *arg, const struct flow *flow)
400 {
401     char *orig = xstrdup(arg);
402     char *name, *value;
403     enum ofperr error;
404     size_t learn_ofs;
405     size_t len;
406
407     struct nx_action_learn *learn;
408     struct cls_rule rule;
409
410     learn_ofs = b->size;
411     learn = ofputil_put_NXAST_LEARN(b);
412     learn->idle_timeout = htons(OFP_FLOW_PERMANENT);
413     learn->hard_timeout = htons(OFP_FLOW_PERMANENT);
414     learn->priority = htons(OFP_DEFAULT_PRIORITY);
415     learn->cookie = htonll(0);
416     learn->flags = htons(0);
417     learn->table_id = 1;
418
419     cls_rule_init_catchall(&rule, 0);
420     while (ofputil_parse_key_value(&arg, &name, &value)) {
421         learn = ofpbuf_at_assert(b, learn_ofs, sizeof *learn);
422         if (!strcmp(name, "table")) {
423             learn->table_id = atoi(value);
424             if (learn->table_id == 255) {
425                 ovs_fatal(0, "%s: table id 255 not valid for `learn' action",
426                           orig);
427             }
428         } else if (!strcmp(name, "priority")) {
429             learn->priority = htons(atoi(value));
430         } else if (!strcmp(name, "idle_timeout")) {
431             learn->idle_timeout = htons(atoi(value));
432         } else if (!strcmp(name, "hard_timeout")) {
433             learn->hard_timeout = htons(atoi(value));
434         } else if (!strcmp(name, "cookie")) {
435             learn->cookie = htonll(strtoull(value, NULL, 0));
436         } else {
437             struct learn_spec spec;
438
439             learn_parse_spec(orig, name, value, &spec);
440
441             /* Check prerequisites. */
442             if (spec.src_type == NX_LEARN_SRC_FIELD
443                 && flow && !mf_are_prereqs_ok(spec.src.field, flow)) {
444                 ovs_fatal(0, "%s: cannot specify source field %s because "
445                           "prerequisites are not satisfied",
446                           orig, spec.src.field->name);
447             }
448             if ((spec.dst_type == NX_LEARN_DST_MATCH
449                  || spec.dst_type == NX_LEARN_DST_LOAD)
450                 && !mf_are_prereqs_ok(spec.dst.field, &rule.flow)) {
451                 ovs_fatal(0, "%s: cannot specify destination field %s because "
452                           "prerequisites are not satisfied",
453                           orig, spec.dst.field->name);
454             }
455
456             /* Update 'rule' to allow for satisfying destination
457              * prerequisites. */
458             if (spec.src_type == NX_LEARN_SRC_IMMEDIATE
459                 && spec.dst_type == NX_LEARN_DST_MATCH
460                 && spec.dst.ofs == 0
461                 && spec.n_bits == spec.dst.field->n_bytes * 8) {
462                 union mf_value imm;
463
464                 memcpy(&imm, spec.src_imm, spec.dst.field->n_bytes);
465                 mf_set_value(spec.dst.field, &imm, &rule);
466             }
467
468             /* Output the flow_mod_spec. */
469             put_u16(b, spec.n_bits | spec.src_type | spec.dst_type);
470             if (spec.src_type == NX_LEARN_SRC_IMMEDIATE) {
471                 int n_bytes = DIV_ROUND_UP(spec.n_bits, 8);
472                 if (n_bytes % 2) {
473                     ofpbuf_put_zeros(b, 1);
474                 }
475                 ofpbuf_put(b, spec.src_imm, n_bytes);
476             } else {
477                 put_u32(b, spec.src.field->nxm_header);
478                 put_u16(b, spec.src.ofs);
479             }
480             if (spec.dst_type == NX_LEARN_DST_MATCH ||
481                 spec.dst_type == NX_LEARN_DST_LOAD) {
482                 put_u32(b, spec.dst.field->nxm_header);
483                 put_u16(b, spec.dst.ofs);
484             } else {
485                 assert(spec.dst_type == NX_LEARN_DST_OUTPUT);
486             }
487         }
488     }
489
490     put_u16(b, 0);
491
492     len = b->size - learn_ofs;
493     if (len % 8) {
494         ofpbuf_put_zeros(b, 8 - len % 8);
495     }
496
497     learn = ofpbuf_at_assert(b, learn_ofs, sizeof *learn);
498     learn->len = htons(b->size - learn_ofs);
499
500     /* In theory the above should have caught any errors, but... */
501     if (flow) {
502         error = learn_check(learn, flow);
503         if (error) {
504             ovs_fatal(0, "%s: %s", orig, ofperr_to_string(error));
505         }
506     }
507     free(orig);
508 }
509
510 void
511 learn_format(const struct nx_action_learn *learn, struct ds *s)
512 {
513     struct cls_rule rule;
514     const void *p, *end;
515
516     cls_rule_init_catchall(&rule, 0);
517
518     ds_put_format(s, "learn(table=%"PRIu8, learn->table_id);
519     if (learn->idle_timeout != htons(OFP_FLOW_PERMANENT)) {
520         ds_put_format(s, ",idle_timeout=%"PRIu16, ntohs(learn->idle_timeout));
521     }
522     if (learn->hard_timeout != htons(OFP_FLOW_PERMANENT)) {
523         ds_put_format(s, ",hard_timeout=%"PRIu16, ntohs(learn->hard_timeout));
524     }
525     if (learn->priority != htons(OFP_DEFAULT_PRIORITY)) {
526         ds_put_format(s, ",priority=%"PRIu16, ntohs(learn->priority));
527     }
528     if (learn->flags & htons(OFPFF_SEND_FLOW_REM)) {
529         ds_put_cstr(s, ",OFPFF_SEND_FLOW_REM");
530     }
531     if (learn->flags & htons(~OFPFF_SEND_FLOW_REM)) {
532         ds_put_format(s, ",***flags=%"PRIu16"***",
533                       ntohs(learn->flags) & ~OFPFF_SEND_FLOW_REM);
534     }
535     if (learn->cookie != htonll(0)) {
536         ds_put_format(s, ",cookie=0x%"PRIx64, ntohll(learn->cookie));
537     }
538     if (!is_all_zeros(learn->pad, sizeof learn->pad)) {
539         ds_put_cstr(s, ",***nonzero pad***");
540     }
541
542     end = (char *) learn + ntohs(learn->len);
543     for (p = learn + 1; p != end; ) {
544         uint16_t header = ntohs(get_be16(&p));
545         int n_bits = header & NX_LEARN_N_BITS_MASK;
546
547         int src_type = header & NX_LEARN_SRC_MASK;
548         struct mf_subfield src;
549         const uint8_t *src_value;
550         int src_value_bytes;
551
552         int dst_type = header & NX_LEARN_DST_MASK;
553         struct mf_subfield dst;
554
555         enum ofperr error;
556         int i;
557
558         if (!header) {
559             break;
560         }
561
562         error = learn_check_header(header, (char *) end - (char *) p);
563         if (error == OFPERR_OFPBAC_BAD_ARGUMENT) {
564             ds_put_format(s, ",***bad flow_mod_spec header %"PRIx16"***)",
565                           header);
566             return;
567         } else if (error == OFPERR_OFPBAC_BAD_LEN) {
568             ds_put_format(s, ",***flow_mod_spec at offset %td is %u bytes "
569                           "long but only %td bytes are left***)",
570                           (char *) p - (char *) (learn + 1) - 2,
571                           learn_min_len(header) + 2,
572                           (char *) end - (char *) p + 2);
573             return;
574         }
575         assert(!error);
576
577         /* Get the source. */
578         if (src_type == NX_LEARN_SRC_FIELD) {
579             get_subfield(n_bits, &p, &src);
580             src_value_bytes = 0;
581             src_value = NULL;
582         } else {
583             src.field = NULL;
584             src.ofs = 0;
585             src.n_bits = 0;
586             src_value_bytes = 2 * DIV_ROUND_UP(n_bits, 16);
587             src_value = p;
588             p = (const void *) ((const uint8_t *) p + src_value_bytes);
589         }
590
591         /* Get the destination. */
592         if (dst_type == NX_LEARN_DST_MATCH || dst_type == NX_LEARN_DST_LOAD) {
593             get_subfield(n_bits, &p, &dst);
594         } else {
595             dst.field = NULL;
596             dst.ofs = 0;
597             dst.n_bits = 0;
598         }
599
600         ds_put_char(s, ',');
601
602         switch (src_type | dst_type) {
603         case NX_LEARN_SRC_IMMEDIATE | NX_LEARN_DST_MATCH:
604             if (dst.field && dst.ofs == 0 && n_bits == dst.field->n_bits) {
605                 union mf_value value;
606                 uint8_t *bytes = (uint8_t *) &value;
607
608                 if (src_value_bytes > dst.field->n_bytes) {
609                     /* The destination field is an odd number of bytes, which
610                      * got rounded up to a multiple of 2 to be put into the
611                      * learning action.  Skip over the leading byte, which
612                      * should be zero anyway.  Otherwise the memcpy() below
613                      * will overrun the start of 'value'. */
614                     int diff = src_value_bytes - dst.field->n_bytes;
615                     src_value += diff;
616                     src_value_bytes -= diff;
617                 }
618
619                 memset(&value, 0, sizeof value);
620                 memcpy(&bytes[dst.field->n_bytes - src_value_bytes],
621                        src_value, src_value_bytes);
622                 ds_put_format(s, "%s=", dst.field->name);
623                 mf_format(dst.field, &value, NULL, s);
624             } else {
625                 mf_format_subfield(&dst, s);
626                 ds_put_cstr(s, "=0x");
627                 for (i = 0; i < src_value_bytes; i++) {
628                     ds_put_format(s, "%02"PRIx8, src_value[i]);
629                 }
630             }
631             break;
632
633         case NX_LEARN_SRC_FIELD | NX_LEARN_DST_MATCH:
634             mf_format_subfield(&dst, s);
635             if (src.field != dst.field || src.ofs != dst.ofs) {
636                 ds_put_char(s, '=');
637                 mf_format_subfield(&src, s);
638             }
639             break;
640
641         case NX_LEARN_SRC_IMMEDIATE | NX_LEARN_DST_LOAD:
642             ds_put_cstr(s, "load:0x");
643             for (i = 0; i < src_value_bytes; i++) {
644                 ds_put_format(s, "%02"PRIx8, src_value[i]);
645             }
646             ds_put_cstr(s, "->");
647             mf_format_subfield(&dst, s);
648             break;
649
650         case NX_LEARN_SRC_FIELD | NX_LEARN_DST_LOAD:
651             ds_put_cstr(s, "load:");
652             mf_format_subfield(&src, s);
653             ds_put_cstr(s, "->");
654             mf_format_subfield(&dst, s);
655             break;
656
657         case NX_LEARN_SRC_FIELD | NX_LEARN_DST_OUTPUT:
658             ds_put_cstr(s, "output:");
659             mf_format_subfield(&src, s);
660             break;
661         }
662     }
663     if (!is_all_zeros(p, (char *) end - (char *) p)) {
664         ds_put_cstr(s, ",***nonzero trailer***");
665     }
666     ds_put_char(s, ')');
667 }