~ubuntu-branches/ubuntu/precise/tcpdump/precise-updates

« back to all changes in this revision

Viewing changes to print-ip6.c

  • Committer: Package Import Robot
  • Author(s): Stéphane Graber
  • Date: 2012-01-04 10:33:48 UTC
  • mfrom: (7.1.9 sid)
  • Revision ID: package-import@ubuntu.com-20120104103348-6i4d0riwu9laykex
Tags: 4.2.1-1ubuntu1
* Resynchronise with Debian.  Remaining changes (LP: #892285):
  - Add enforcing AppArmor profile.
* Refreshed manpage patch to apply to new upstream.

Show diffs side-by-side

added added

removed removed

Lines of Context:
48
48
 * Compute a V6-style checksum by building a pseudoheader.
49
49
 */
50
50
int
51
 
nextproto6_cksum(const struct ip6_hdr *ip6, const u_short *data,
 
51
nextproto6_cksum(const struct ip6_hdr *ip6, const u_int8_t *data,
52
52
                 u_int len, u_int next_proto)
53
53
{
54
 
        size_t i;
55
 
        u_int32_t sum = 0;
56
 
        union ip6_pseudo_hdr phu;
 
54
        struct {
 
55
                struct in6_addr ph_src;
 
56
                struct in6_addr ph_dst;
 
57
                u_int32_t       ph_len;
 
58
                u_int8_t        ph_zero[3];
 
59
                u_int8_t        ph_nxt;
 
60
        } ph;
 
61
        struct cksum_vec vec[2];
57
62
 
58
63
        /* pseudo-header */
59
 
        memset(&phu, 0, sizeof(phu));
60
 
        phu.ph.ph_src = ip6->ip6_src;
61
 
        phu.ph.ph_dst = ip6->ip6_dst;
62
 
        phu.ph.ph_len = htonl(len);
63
 
        phu.ph.ph_nxt = next_proto;
64
 
 
65
 
        for (i = 0; i < sizeof(phu.pa) / sizeof(phu.pa[0]); i++) {
66
 
                sum += phu.pa[i];
67
 
        }
68
 
 
69
 
        return in_cksum(data, len, sum);
 
64
        memset(&ph, 0, sizeof(ph));
 
65
        ph.ph_src = ip6->ip6_src;
 
66
        ph.ph_dst = ip6->ip6_dst;
 
67
        ph.ph_len = htonl(len);
 
68
        ph.ph_nxt = next_proto;
 
69
 
 
70
        vec[0].ptr = (const u_int8_t *)(void *)&ph;
 
71
        vec[0].len = sizeof(ph);
 
72
        vec[1].ptr = data;
 
73
        vec[1].len = len;
 
74
 
 
75
        return in_cksum(vec, 2);
70
76
}
71
77
 
72
78
/*
73
79
 * print an IP6 datagram.
74
80
 */
75
81
void
76
 
ip6_print(register const u_char *bp, register u_int length)
 
82
ip6_print(netdissect_options *ndo, const u_char *bp, u_int length)
77
83
{
78
84
        register const struct ip6_hdr *ip6;
79
85
        register int advance;
89
95
 
90
96
        TCHECK(*ip6);
91
97
        if (length < sizeof (struct ip6_hdr)) {
92
 
                (void)printf("truncated-ip6 %u", length);
 
98
                (void)ND_PRINT((ndo, "truncated-ip6 %u", length));
93
99
                return;
94
100
        }
95
101
 
96
 
        if (!eflag)
97
 
            printf("IP6 ");
 
102
        if (!ndo->ndo_eflag)
 
103
            ND_PRINT((ndo, "IP6 "));
98
104
 
99
105
        payload_len = EXTRACT_16BITS(&ip6->ip6_plen);
100
106
        len = payload_len + sizeof(struct ip6_hdr);
101
107
        if (length < len)
102
 
                (void)printf("truncated-ip6 - %u bytes missing!",
103
 
                        len - length);
 
108
                (void)ND_PRINT((ndo, "truncated-ip6 - %u bytes missing!",
 
109
                        len - length));
104
110
 
105
 
        if (vflag) {
 
111
        if (ndo->ndo_vflag) {
106
112
            flow = EXTRACT_32BITS(&ip6->ip6_flow);
107
 
            printf("(");
 
113
            ND_PRINT((ndo, "("));
108
114
#if 0
109
115
            /* rfc1883 */
110
116
            if (flow & 0x0f000000)
111
 
                (void)printf("pri 0x%02x, ", (flow & 0x0f000000) >> 24);
 
117
                (void)ND_PRINT((ndo, "pri 0x%02x, ", (flow & 0x0f000000) >> 24));
112
118
            if (flow & 0x00ffffff)
113
 
                (void)printf("flowlabel 0x%06x, ", flow & 0x00ffffff);
 
119
                (void)ND_PRINT((ndo, "flowlabel 0x%06x, ", flow & 0x00ffffff));
114
120
#else
115
121
            /* RFC 2460 */
116
122
            if (flow & 0x0ff00000)
117
 
                (void)printf("class 0x%02x, ", (flow & 0x0ff00000) >> 20);
 
123
                (void)ND_PRINT((ndo, "class 0x%02x, ", (flow & 0x0ff00000) >> 20));
118
124
            if (flow & 0x000fffff)
119
 
                (void)printf("flowlabel 0x%05x, ", flow & 0x000fffff);
 
125
                (void)ND_PRINT((ndo, "flowlabel 0x%05x, ", flow & 0x000fffff));
120
126
#endif
121
127
 
122
 
            (void)printf("hlim %u, next-header %s (%u) payload length: %u) ",
 
128
            (void)ND_PRINT((ndo, "hlim %u, next-header %s (%u) payload length: %u) ",
123
129
                         ip6->ip6_hlim,
124
130
                         tok2str(ipproto_values,"unknown",ip6->ip6_nxt),
125
131
                         ip6->ip6_nxt,
126
 
                         payload_len);
 
132
                         payload_len));
127
133
        }
128
134
 
129
135
        /*
130
136
         * Cut off the snapshot length to the end of the IP payload.
131
137
         */
132
138
        ipend = bp + len;
133
 
        if (ipend < snapend)
134
 
                snapend = ipend;
 
139
        if (ipend < ndo->ndo_snapend)
 
140
                ndo->ndo_snapend = ipend;
135
141
 
136
142
        cp = (const u_char *)ip6;
137
143
        advance = sizeof(struct ip6_hdr);
138
144
        nh = ip6->ip6_nxt;
139
 
        while (cp < snapend && advance > 0) {
 
145
        while (cp < ndo->ndo_snapend && advance > 0) {
140
146
                cp += advance;
141
147
                len -= advance;
142
148
 
143
149
                if (cp == (const u_char *)(ip6 + 1) &&
144
150
                    nh != IPPROTO_TCP && nh != IPPROTO_UDP &&
145
151
                    nh != IPPROTO_DCCP && nh != IPPROTO_SCTP) {
146
 
                        (void)printf("%s > %s: ", ip6addr_string(&ip6->ip6_src),
147
 
                                     ip6addr_string(&ip6->ip6_dst));
 
152
                        (void)ND_PRINT((ndo, "%s > %s: ", ip6addr_string(&ip6->ip6_src),
 
153
                                     ip6addr_string(&ip6->ip6_dst)));
148
154
                }
149
155
 
150
156
                switch (nh) {
158
164
                        break;
159
165
                case IPPROTO_FRAGMENT:
160
166
                        advance = frag6_print(cp, (const u_char *)ip6);
161
 
                        if (snapend <= cp + advance)
 
167
                        if (ndo->ndo_snapend <= cp + advance)
162
168
                                return;
163
169
                        nh = *cp;
164
170
                        fragmented = 1;
196
202
                        udp_print(cp, len, (const u_char *)ip6, fragmented);
197
203
                        return;
198
204
                case IPPROTO_ICMPV6:
199
 
                        icmp6_print(gndo, cp, len, (const u_char *)ip6, fragmented);
 
205
                        icmp6_print(ndo, cp, len, (const u_char *)ip6, fragmented);
200
206
                        return;
201
207
                case IPPROTO_AH:
202
208
                        advance = ah_print(cp);
205
211
                case IPPROTO_ESP:
206
212
                    {
207
213
                        int enh, padlen;
208
 
                        advance = esp_print(gndo, cp, len, (const u_char *)ip6, &enh, &padlen);
 
214
                        advance = esp_print(ndo, cp, len, (const u_char *)ip6, &enh, &padlen);
209
215
                        nh = enh & 0xff;
210
216
                        len -= padlen;
211
217
                        break;
219
225
                    }
220
226
 
221
227
                case IPPROTO_PIM:
222
 
                        pim_print(cp, len, nextproto6_cksum(ip6, (u_short *)cp, len,
 
228
                        pim_print(cp, len, nextproto6_cksum(ip6, cp, len,
223
229
                                                            IPPROTO_PIM));
224
230
                        return;
225
231
 
228
234
                        return;
229
235
 
230
236
                case IPPROTO_IPV6:
231
 
                        ip6_print(cp, len);
 
237
                        ip6_print(ndo, cp, len);
232
238
                        return;
233
239
 
234
240
                case IPPROTO_IPV4:
235
 
                        ip_print(gndo, cp, len);
 
241
                        ip_print(ndo, cp, len);
236
242
                        return;
237
243
 
238
244
                case IPPROTO_PGM:
248
254
                        return;
249
255
 
250
256
                case IPPROTO_NONE:
251
 
                        (void)printf("no next header");
 
257
                        (void)ND_PRINT((ndo, "no next header"));
252
258
                        return;
253
259
 
254
260
                default:
255
 
                        (void)printf("ip-proto-%d %d", nh, len);
 
261
                        (void)ND_PRINT((ndo, "ip-proto-%d %d", nh, len));
256
262
                        return;
257
263
                }
258
264
        }
259
265
 
260
266
        return;
261
267
trunc:
262
 
        (void)printf("[|ip6]");
 
268
        (void)ND_PRINT((ndo, "[|ip6]"));
263
269
}
264
270
 
265
271
#endif /* INET6 */