@@ -62,6 +62,15 @@ show_link_header_json(struct bpf_link_info *info, json_writer_t *wtr)
62
62
jsonw_uint_field (json_wtr , "prog_id" , info -> prog_id );
63
63
}
64
64
65
+ static void show_link_attach_type_json (__u32 attach_type , json_writer_t * wtr )
66
+ {
67
+ if (attach_type < ARRAY_SIZE (attach_type_name ))
68
+ jsonw_string_field (wtr , "attach_type" ,
69
+ attach_type_name [attach_type ]);
70
+ else
71
+ jsonw_uint_field (wtr , "attach_type" , attach_type );
72
+ }
73
+
65
74
static int get_prog_info (int prog_id , struct bpf_prog_info * info )
66
75
{
67
76
__u32 len = sizeof (* info );
@@ -105,22 +114,13 @@ static int show_link_close_json(int fd, struct bpf_link_info *info)
105
114
jsonw_uint_field (json_wtr , "prog_type" ,
106
115
prog_info .type );
107
116
108
- if (info -> tracing .attach_type < ARRAY_SIZE (attach_type_name ))
109
- jsonw_string_field (json_wtr , "attach_type" ,
110
- attach_type_name [info -> tracing .attach_type ]);
111
- else
112
- jsonw_uint_field (json_wtr , "attach_type" ,
113
- info -> tracing .attach_type );
117
+ show_link_attach_type_json (info -> tracing .attach_type ,
118
+ json_wtr );
114
119
break ;
115
120
case BPF_LINK_TYPE_CGROUP :
116
121
jsonw_lluint_field (json_wtr , "cgroup_id" ,
117
122
info -> cgroup .cgroup_id );
118
- if (info -> cgroup .attach_type < ARRAY_SIZE (attach_type_name ))
119
- jsonw_string_field (json_wtr , "attach_type" ,
120
- attach_type_name [info -> cgroup .attach_type ]);
121
- else
122
- jsonw_uint_field (json_wtr , "attach_type" ,
123
- info -> cgroup .attach_type );
123
+ show_link_attach_type_json (info -> cgroup .attach_type , json_wtr );
124
124
break ;
125
125
default :
126
126
break ;
@@ -153,6 +153,14 @@ static void show_link_header_plain(struct bpf_link_info *info)
153
153
printf ("prog %u " , info -> prog_id );
154
154
}
155
155
156
+ static void show_link_attach_type_plain (__u32 attach_type )
157
+ {
158
+ if (attach_type < ARRAY_SIZE (attach_type_name ))
159
+ printf ("attach_type %s " , attach_type_name [attach_type ]);
160
+ else
161
+ printf ("attach_type %u " , attach_type );
162
+ }
163
+
156
164
static int show_link_close_plain (int fd , struct bpf_link_info * info )
157
165
{
158
166
struct bpf_prog_info prog_info ;
@@ -176,19 +184,11 @@ static int show_link_close_plain(int fd, struct bpf_link_info *info)
176
184
else
177
185
printf ("\n\tprog_type %u " , prog_info .type );
178
186
179
- if (info -> tracing .attach_type < ARRAY_SIZE (attach_type_name ))
180
- printf ("attach_type %s " ,
181
- attach_type_name [info -> tracing .attach_type ]);
182
- else
183
- printf ("attach_type %u " , info -> tracing .attach_type );
187
+ show_link_attach_type_plain (info -> tracing .attach_type );
184
188
break ;
185
189
case BPF_LINK_TYPE_CGROUP :
186
190
printf ("\n\tcgroup_id %zu " , (size_t )info -> cgroup .cgroup_id );
187
- if (info -> cgroup .attach_type < ARRAY_SIZE (attach_type_name ))
188
- printf ("attach_type %s " ,
189
- attach_type_name [info -> cgroup .attach_type ]);
190
- else
191
- printf ("attach_type %u " , info -> cgroup .attach_type );
191
+ show_link_attach_type_plain (info -> cgroup .attach_type );
192
192
break ;
193
193
default :
194
194
break ;
0 commit comments